pbreheny / visreg

Visualization of regression functions
http://pbreheny.github.io/visreg/
61 stars 18 forks source link

No variation in partial residual plots #5

Closed jasonrohr closed 9 years ago

jasonrohr commented 9 years ago

Hi Patrick. I am trying to understand why it is that when I run some mixed effects models and produce contrast plots, I get variation for some of my response variables in visreg plots but other response variables have all the data points falling directly on the regression line. An example is provided below (script pasted, data pasted as an image, and visreg plots also pasted). In the example below, I am attempting to conduct a random effects meta-analysis treating study as a random effect and weighting by the inverse of the variance estimate for the parameter of interest. The response variables are parameters describing the shape of organismal performance curves and the predictors are acclimation temp., latitude, body size, habitat, and trophic position. I suspect it has to do with the weights in the regression analysis that are somehow affecting the display of the partial residual plots. I am just not sure if I should trust the plots that are being produced. Thanks.

library(visreg)
library(nlme)

detach(mydatajl)
mydatajl<-read.delim("clipboard")
attach(mydatajl)

model1<-lme(joint_jl~AccTemp2*LogMass*absLatitude+Habitat+Trophic2,data=subset(mydatajl, Param=="E"), random = ~ 1 | DataSeriesID2, weights = varFixed(~ Var), na.action=na.omit,method="ML")
model2<-lme(joint_jl~AccTemp2*LogMass*absLatitude+Habitat+Trophic2,data=subset(mydatajl, Param=="tpk"), random = ~ 1 | DataSeriesID2, weights = varFixed(~ Var), na.action=na.omit, method="ML")

visreg(model1, "AccTemp2", "LogMass",  type = "contrast", points=list(col="black", cex=.75), line.par=list(lty=2, col="black", lwd=0.5), strip=FALSE, breaks=2,
       xlab="Acclimation temperature (degrees C)", cex.lab=1.25, cex.axis=1.25,
       ylab="Relative change in E parameter (degrees C)", cex.lab=1.25, cex.axis=1.25)

visreg(model2, "AccTemp2", "LogMass",  type = "contrast", points=list(col="black", cex=.75), line.par=list(lty=2, col="black", lwd=0.5), strip=FALSE, breaks=2,
       xlab="Acclimation temperature (degrees C)",
       ylab="Relative change in optimal temperature (degrees C)")

image

image

image

pbreheny commented 9 years ago

This isn't a problem with the display -- visreg is correctly displaying the model. The problem is that the residuals are zero:

> range(residuals(model2)) [1] -9.926502e-08 1.745643e-08

You can trust the plot. What you probably shouldn't trust is the model -- those residuals do not seem believable to me...nor do variances of 10^-30!

jasonrohr commented 9 years ago

Thanks. Appreciate it.