I calculated a linear mixed model using the packages lme4 and lsmeans with the lmer-function, where i have one dependent variable rv and the interacting factors treatment, time, age and race. I'm interested in the response variable change over time, that's why i use the lstrends-function. So far so good. The problem is, i have to square root the response variable in order to fit the model properly. But the pairs-function only gives out a response to the square root of the rv, hard to interpret!
So i tried to back-transform the response variable after pairs:
model.lmer <- lmer(sqrt(rv) ~ treat*time*age*race + (1|individual), data=mydata)
model.lst <- lstrends(model.lmer, ~treat | age*race , var = "time", type="response")
pairs(mouse.lst, type="response")
This obviously doesn't work, as stated by the package itself:
# Transformed response
sqwarp.rg <- ref.grid(update(warp.lm, sqrt(breaks) ~ .))
summary(sqwarp.rg)
# Back-transformed results - compare with summary of 'warp.rg'
summary(sqwarp.rg, type = "response")
# But differences of sqrts can't be back-transformed
summary(pairs(sqwarp.rg, by = "wool"), type = "response")
# We can do it via regrid
sqwarp.rg2 <- regrid(sqwarp.rg)
summary(sqwarp.rg2) # same as for sqwarp.rg with type = "response"
pairs(sqwarp.rg2, by = "wool")
Anybode got an idea how to solve this particular problem? Thanks in advance!
edit1:
It could look like the following code:
summary(pairs(lsmeans(rg.regrid, ~ treat | race*age, trend="time")), type="response")
The problem is, i can't alter the reference grid for lstrends, just for lsmeans, because the first argument in lstrends or lsmeans with trend="time" requires the linear mixed effect model (model.lmer) intead of just the reference grid like in lsmeans, without the trend-argument... That's probably why i can't back-transform the data with
edit2: This here sums up my problem pretty well:
model.sqrt <- lmer(sqrt(rv) ~ time*treat*race*age, data=mydata)
rg <- ref.grid(model.sqrt)
rg.regrid <- regrid(rg)
summary(pairs(lsmeans(rg.regrid, ~treat | race*age*time), type = "response"))
works perfectly.
summary(pairs(lsmeans(rg.regrid, ~treat | race*age, trend="time"), type = "response"))
Gives the following error:
Error in summary(pairs(lsmeans(rg.regrid, ~treat | race * age, trend = "time"), :
error in evaluating the argument 'object' in selecting a method for function 'summary': Error in data[[var]] : subscript out of bounds
How to avoid the error and still be able to back-transform my data?
edit3:
model <- lme(sqrt(dv) ~ time*treat*race*age, random=~1|individual, data=mydata, weights=varPower(0.19, form = ~time|individual), method="ML")
lsms <- summary(pairs(model, ~treat | time*race*age, at=list(time=4))))$estimate
slome <- summary(pairs(lstrends(model, ~treat | race*age, var="time")))$estimate
slose <- summary(pairs(lstrends(model, ~treat | race*age, var="time")))$SE
for(i in 1:4){
eslo[i] <- 2 * lsms[i] * slome[i]
ese[i] <- abs(2*lsms[i]) * slose[i]
}
i = 1 is race1 at age1;
i = 2 is race1 at age2;
i = 3 is race2 at age1;
i = 4 is race2 at age2;
slose: slope-SE from lstrends for sqrt(dv)-difference between treated and untreated group
slome: slope from lstrends for sqrt(dv)-difference per time between treated and untreated group
eslo and ese: estimated slope and se for dv-difference per time between treated and untreated group