I'm stuck in using R. In a simple linear regression;
y=a b_1*x
I wanna know how much increase or decrease when one standard deviation of Independent Variable increases in R.
Do you know the way how to do it by using sapply() syntax?
CodePudding user response:
Scale your explanatory variable by the inverse of its standard deviation and re-run your model. Then a 1-unit increase of the scaled explanatory variable equals a 1-SD increase of the unscaled one.
You can also have a look at these two packages:
...or just multiply the coefficient from the unscaled model by the standard deviation, of course.
CodePudding user response:
Using the marginaleffects
package – as suggested by @dufei – you can do:
library(marginaleffects)
mod <- lm(mpg ~ hp, data = mtcars)
cmp <- comparisons(mod, variables = list(hp = "sd"))
summary(cmp)
Term Contrast Effect Std. Error z value Pr(>|z|) 2.5 %
1 hp (x sd/2) - (x - sd/2) -4.678 0.6938 -6.742 1.558e-11 -6.038
97.5 %
1 -3.318
Model type: lm
Prediction type: response
Disclaimer: I am the author of marginaleffects
.