Back-Transforming contrast of Least square trends RRS feed

  • Question

  • Hello everyone!

    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) ~ .))
    # 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!


    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, ~vns | gen * 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 of the lstrends?

    Tuesday, August 9, 2016 8:46 PM

All replies

  • This isn't an MRO-specific issue; it's a general R question about the lme package. You might have better luck asking your question on StackOverflow. Here are some questions that might be relevant:

    Hope this helps,

    # David

    Tuesday, August 9, 2016 10:35 PM