I am interested in determining the effect of climate shocks on nutrition outcomes. I am modeling nutrition outcomes in terms of several explanatory variables, including climate. I would like to determine which individual's nutrition outcome was most affected by the climate variable, after accounting for the effects of all other variables.
The best approach I can think of for this would be to run two models, one including every explanatory variable besides climate (such as birth weight, diet, etc), and one with all of those variables but also including climate. Then, the differencing the residuals between the two models would show which observations climate has the greatest impact on.
To test whether this is a good approach, I have run some R code to simulate this sort of situation:
b0 <- -3 b1 <- 3 b2 <- -3 b3 <- 3 x0 <- rnorm(100, 0, 1) x1 <- rnorm(100, 0, 1) x2 <- rnorm(100, 0, 1) x3 <- rnorm(100, 0, 1) #Variable x3 only affects y for the first 5 observations x3[6:100] <- 0 y <- x0*b0 + x1*b1 + x2*b2 + x3*b3 + rnorm(100, 0, 3) mod1 <- lm(y~x0 + x1 + x2) mod2 <- lm(y~x0 + x1 + x2 + x3) diff <- mod2$residuals - mod1$residuals tail(names(diff)[order(diff)])
After differencing the residuals, the first five observations always among the largest, but there are also observations with a large difference in residuals where
x3 had no effect. Have I taken the correct approach here? Would there be a better way to estimate the impact of a particular explanatory variable on each observation? Additionally, when running the model with actual data, it will likely be a mixed-effects model, not a simple linear model like I have simulated.