Take the simple simulation below.
set.seed(3424131)
x_1 = rnorm(100, mean = 10, sd = 4)
x_2 = rnorm(100, mean = 3, sd = 2)
covariate = 0.05-0.03*x+0.04*x_2
y = rnbinom(n= length(x_1), mu = exp(covariate), size = 50)
temp = glm.nb(y~x_1+x_2+x_1*x_2)
summary(temp)
x_new_1 = scale(x_1)
x_new_2 = scale(x_2)
temp_2 = glm.nb(y~x_new_1+x_new_2+x_new_1*x_new_2)
summary(temp_2)
Before standardizing(temp_1), the coefficients are as follow:
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -1.01450 0.60287 -1.683 0.0924 .
x_1 0.05332 0.05079 1.050 0.2937
x_2 0.26133 0.13552 1.928 0.0538 .
x_1:x_2 -0.01718 0.01235 -1.391 0.1643
And after standardizing(temp_2), the coefficients are as follow.
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -0.18402 0.11300 -1.629 0.103
x_new_1 -0.01949 0.11293 -0.173 0.863
x_new_2 0.14715 0.10979 1.340 0.180
x_new_1:x_new_2 -0.14799 0.10640 -1.391 0.164
After standardizing, the sign of the coefficient for $x_1$ flipped. How do we interpret this?
It seems like before standardizing, an increase in $x_1$ resulted in the increase of the mean, but after standardizing, an increase in $x_1$ results in a decrease of the mean, which seems paradoxical.
Also, does the change of sign have to do with the interaction term? I couldn't replicate the flipping of the sign without the interaction term.
covariate = 0.05-0.03*x+0.04*x_2
but, in the given code,x
is not defined anywhere and you usex1
andx_new_1
in your models. Is it possible that you have definedx
elsewhere which would cause problems? $\endgroup$rnbinom
or some other linear regression model is irrelevant. It's not even an appropriate model for the data you generated. $\endgroup$