R做回归中的调节效应interaction effect

标签:
股票调节效应回归交互项 |
分类: 02研究方法 |
1.
2.
3.
方法一:
1.
2.
, Y4 \8 K6 N, X) O
方法二:
1.
2.
Statistics and Probability Dictionary
Select a term from the dropdown text box. The online statistics glossary will display a definition, plus links to other related web pages.
z Score
A
z = (X - μ) / σ
where z is the z-score, X is the value of the element, μ is the population mean, and σ is the standard deviation.
Here is how to interpret z-scores.
- A z-score less than 0 represents an element less than the mean.
- A z-score greater than 0 represents an element greater than the mean.
- A z-score equal to 0 represents an element equal to the mean.
- A z-score equal to 1 represents an element that is 1 standard deviation greater than the mean; a z-score equal to 2, 2 standard deviations greater than the mean; etc.
- A z-score equal to -1 represents an element that is 1 standard deviation less than the mean; a z-score equal to -2, 2 standard deviations less than the mean; etc.
- If the number of elements in the set is large, about 68% of the elements have a z-score between -1 and 1; about 95% have a z-score between -2 and 2; and about 99% have a z-score between -3 and 3.
Here is another way to think about z-scores. A z-score is
the
How can one plot continuous by continuous interactions in
ggplot2? link
Let's say I have data:
x1 <- rnorm(100,2,10)
x2 <- rnorm(100,2,10)
y <- x1+x2+x1*x2+rnorm(100,1,2)
dat <- data.frame(y=y,x1=x1,x2=x2)
res <- lm(y~x1*x2,data=dat)
summary(res)
I want to plot the continuous by continuous interaction such that x1 is on the X axis and x2 is represented by 3 lines, one which represents x2 at a Z-score of 0, one at Z-score of +1, and another at a Z-score of -1, with each line a separate color and labelled. How can I do this using ggplot2?
For example, it might look something like this (though of course
with different colored lines rather than different line
types):
http://s1/mw690/001Rt2X3zy6OC3KlyTe40&690effect" TITLE="R做回归中的调节效应interaction
Here's my version with your simulated data set:
x1 <- rnorm(1000,20,10)
x2 <- rnorm(1000,1,10)
y <- x1+x2+x1*x2+rnorm(100,1,2)
dat <- data.frame(y=y,x1=x1,x2=x2)
res <- lm(y~x1*x2,data=dat)
z1 <- z2 <- seq(-1,1)
newdf <- expand.grid(x1=z1,x2=z2)
library(ggplot2)
p <-
ggplot(data=transform(newdf, yp=predict(res,
newdf)),
p +
scale_colour_discrete(name="x2")
+
dat$y0 <- res$coefficients[[1]] + res$coefficients[[2]]*dat$x1 + res$coefficients[[3]]*0 + res$coefficients[[4]]*dat$x1*0
dat$y1m <- res$coefficients[[1]] + res$coefficients[[2]]*dat$x1 + res$coefficients[[3]]*-1 + res$coefficients[[4]]*dat$x1*-1
dat$y1p <- res$coefficients[[1]] + res$coefficients[[2]]*dat$x1 + res$coefficients[[3]]*1 + res$coefficients[[4]]*dat$x1*1
plot(dat$x1, dat$y0, type="l", xlab="x1", ylab="Estimates")
lines(dat$x1, dat$y1m, col="red")
lines(dat$x1, dat$y1p, col="blue")
http://s2/mw690/001Rt2X3zy6OC3WLRcJ31&690effect" TITLE="R做回归中的调节效应interaction
http://s11/mw690/001Rt2X3zy6OC3WXDYu2a&690effect" TITLE="R做回归中的调节效应interaction
http://s16/mw690/001Rt2X3zy6OC3WZpxl4f&690effect" TITLE="R做回归中的调节效应interaction