# Diagnosing linearity for multiple regression model

I have the following model in R to estimate the change in mosquito abundance each year when controlling for climate variables:

modela <- lm(count_trapnights ~ temp + rain + year, data=wnv) summary(modela)

I am running regression diagnostics and my RVF plot (shown below) looks like it may have some slight curvature. I'm not really familiar with what constitutes a clear violation of the linearity assumption. Would this be acceptable or does this violate the linearity assumption? Is there any way to quantify the violation with some kind of cut-off value?

Non-transformed dependent variable:

Following dietervdf's suggestion, Box-cox transformed dependent variable:

• Have you tried a Box-Cox transformation? Perhaps a simple transformation of your outcome results in a better linearity. See also: r-bloggers.com/on-box-cox-transform-in-regression-models Oct 14, 2017 at 21:55
• @ dietervdf: Thank you for the suggestion. The transformation helped with the normality of the dependent variable and I think it may have helped with the linearity of the model, too. I added the RVF plot for the Box-Cox transformation. I don't really have much experience evaluating these types of graphs so it's hard for me to say if linearity has been violated. Oct 14, 2017 at 22:36
• In my experience checking the assumptions isn't all black or white. Sometimes it's a bit fuzzy. Some things to note in this example. Observation 35 seems to be an outlier, is it a correct measurment? Perhaps there are valid reasons to exclude it from the analysis. The Box-Cox transformation really reduced the residual size, zooming out and the lowess line would appear nearly straight. On the other hand, perhaps a non-linear regression makes more sense? Polynomial regression? You should look for a regression model which makes the most sense, which implies testing around a bit. Oct 14, 2017 at 22:49
• Note that playing around to find the best model could have drastic consequences on the correctness of confidence intervals (being to small since the model has been overfitted). Can you share the dataset, I wouldn't mind playing around with it for a bit. Oct 14, 2017 at 22:53
• @dieterdvf I would love to share the data with you - not sure if there is a way to do it over this site but I uploaded it to google drive and the link is below; note that in my model I have years coded as numeric, 1 through 11. drive.google.com/file/d/0B6fQt0A4oacaTXIwMjdBbTR2cDg/… Oct 14, 2017 at 23:13

I would build a different model. (I'm not entirely sure what the research question is though). How did you decide on the model? Did you just performed linear regression on all possible predictors and then selected the significant ones? Which are the possible predictors?

If you build the regression model step by step, you have more control on which variable should be added to the model, and in what way. I would keep the Box-Cox transformation anyway. It helps reducing skewness of the residuals.

lm.fit <- lm(count_trapnights ~ year + temp + rain, data=wnv)
bc <- boxcox(lm.fit)
lambda <- bc$x[which.max(bc$y)]
wnv$bc.count_trapnights <- (wnv$count_trapnights^lambda-1)/lambda

1. Looking at the primary variable of interest (year)

lm.fit.bc <- lm(bc.count_trapnights ~ year, data=wnv)
plot(lm.fit.bc)


You will notice that all assumptions seem satisfied.

2. How will we add rain to the model?

You can use an added-variable plot to test this out.

lm.fit.t <- lm(rain ~ year, data=wnv)
plot(lm.fit.bc$residuals ~ lm.fit.t$residuals)
lines(lowess(lm.fit.bc$residuals ~ lm.fit.t$residuals))


This graph suggests a linear relation.

3. Lets use the same method to decide on how to add temp First, lets define the current regression model.

lm.fit.bc1 <- lm(bc.count_trapnights ~ year + rain, data=wnv)
plot(lm.fit.bc1)


lm.fit.t <- lm(temp ~ year + rain, data=wnv)
plot(lm.fit.bc1$residuals ~ lm.fit.t$residuals)
lines(lowess(lm.fit.bc1$residuals ~ lm.fit.t$residuals))


This plot seems to suggest a different way to add temp. I've tried temp^2 and exp(temp). The latter seems to work the best.

4. The full model is now:

lm.fit.full <- lm(bc.count_trapnights ~ year + rain + exp(temp), data=wnv)


With the following residual plot.

Keep in mind that I'm not an expert on regression. It's just some ideas from an statistics enthousiast ;)

• Wow - thank you for this detailed and specific answer!! To answer your questions, I chose only significant climate predictors; rhumid and wind were not significant. The disease variables were also not significant, being percentpcr (percent of mosquito traps that tested positive for West Nile Virus) and totalcase (number of human West Nile Virus cases in that time period). This research question is simply: "What climate variables can be used to estimate the mean change in mosquito abundance?" A review of the literature also indicates temperature and rain are the most important. Oct 15, 2017 at 2:19