0
$\begingroup$

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

$\endgroup$
2
  • $\begingroup$ Although asked in the context of R code, this is a statistical question (& hence on topic) IMO. $\endgroup$ Commented Aug 9, 2016 at 11:14
  • $\begingroup$ That's true, but i'd like to have a specific answer for r, how to back-transform square root dependent variables within lstrends, and not just lsmeans how all the tutorials show it. $\endgroup$ Commented Aug 9, 2016 at 13:20

1 Answer 1

1
$\begingroup$

I've thought about this some now, and I'm realizing we can sort this out. Let $t$ denote your time variable, $r$ denote your rv response variable, and let $y=\sqrt r$ be the response you actually used in the model. Then $$dr/dt = dy^2/dt =2y\cdot dy/dt$$ and note that lstrends can calculate values of $dy/dt$. It follows that $$ SE(dr/dt) \approx |2y|\cdot SE(dy/dt) $$ Note also that $y$ depends on $t$ (as well as other variables), so you need to take due care and probably include some specific key values of $t$ in the reference grid (use the at argument).

Once you do that, you can use summary(lsmeans()) to calculate a data frame lsms whose least-squares means estimate the needed values of $y$; and usesummary(lstrends()) to create a data frame slopes whose least-squares means are the corresponding estimates of $dy/dt$. Finally, the estimated slopes $dr/dt$ will be 2 * lsms$lsmean * slopes$lsmean, and estimates of $SE(dr/dt)$ will be abs(2 * lsms$lsmean) * slopes$SE.

In principle, this idea could be incorporated in the lstrends function (e.g., as its way of supporting type = "response" situations). I'll poke around with that and see how easily this feature could be added.

$\endgroup$
5
  • $\begingroup$ Using the pairs comment, i already to a sub-group analysis (young race 1, old race1, young race2, old race2, having 1 slope and SE for each combination of race and age). So the pairs-comment, compares the slope of dv over time for the how you call them specific key values of age and race. Instead of having a slope for all dv over time-values, i'm having now with your method different slopes for each timepoint, right? So the slope would not be just "2.4 +/- 0.8", but something like "0.3*t +/- 0.5*(sqrt(t))"? So i need to add specifc t-value, or can i get a slope in function of the time? $\endgroup$ Commented Aug 15, 2016 at 12:56
  • $\begingroup$ I was talking about specific time values. If you want to work on the response scale, the trends are not linear: the slope is different at each time, and if you want numerical estimates, you have to say which time(s) to use. $\endgroup$ Commented Aug 15, 2016 at 13:01
  • $\begingroup$ I edited my entry post and calculated the estimated values for the timepoint time=4. Is the calculation the right interpretation of your solution mentioned above? And is it right to use the lsmeans from the pairs() argument as i did in my calculations? $\endgroup$ Commented Aug 15, 2016 at 16:36
  • $\begingroup$ It is not right to use the pairs results. Basically I think I'd better try to get lstrends to do the right thing and send it to you. This'll take a day or two at least. $\endgroup$ Commented Aug 15, 2016 at 19:15
  • $\begingroup$ Ok, thanks a lot!! I'm also struggeling getting the confidence levels out of the back-transformed lstrends, but the new lstrends would sure save me a lot of trouble! $\endgroup$ Commented Aug 15, 2016 at 21:08

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.