0

I have used the package lsmeans in R to get the average estimate for all observations for my treatment factor (across the levels of a block factor in the experimental design that has been included with systematic effect because it only had 3 levels). I have used a sqrt transformation for my response variable.

Thus I have used the following commands in R.

First defining model

model<-sqrt(response)~treatment+block

Then applying lsmeans

model_lsmeans<-lsmeans(model,~treatment)

Then plotting this

plot(model_lsmeans,ylab="treatment", xlab="response(with 95% CI)")

This gives a very nice graph with estimates and 95% confidense intervals for the different treatment.

The problems is just that this graph is for the transformed response.

How do I get this same plot with the backtransformed response (so the squared response)?

I have tried to create a new data frame and extract the lsmean, lower.CL, and upper.CL:

a<-summary(model_lsmeans)

New_dataframe<-as.data.frame(a[c("treatment","lsmean","lower.CL","upper.CL")])

And then make these squared

New_dataframe$lsmean<-New_dataframe$lsmean^2

New_dataframe$lower.CL<-New_dataframe$lower.CL^2

New_dataframe$upper.CL<-New_dataframe$upper.CL^2


New_dataframe

This gives me the estimates and CI boundaries squared that I need.

The problem is that I cannot make the same graph for thise estimates and CI as the one that I did in LS means above.

How can I do this? The reason that I ask is that I want to have graphs that are all of a similar style for my article. Since I very much like this LSmeans plot, and it is very convenient for me to use on the non-transformed response variables, I would like to have all my graphs in this style.

Thank you very much for your help! Hope everything is clear!

Kind regards

Ditlev

user3640617
  • 1,546
  • 13
  • 21
  • Just add `type = "response"` to the first `plot` call. – Russ Lenth May 10 '17 at 11:57
  • Thank you @user3640617. I tried this approach but R gives the following warning messages: " Warning messages: 1: In if (inv) { : the condition has length > 1 and only the first element will be used 2: In if (inv) { : the condition has length > 1 and only the first element will be used " And the plots is the same afterwards. What does this error message mean? – Ditlev Reventlow May 10 '17 at 13:50
  • You meant to respond to @rvl. I was able to reproduce the error you show by specifying a vector for the `type` argument. Please use `plot(model_lsmeans, ylab = "treatment", xlab = "response(with 95% CI)", type = "response")` and don't try to do anything fancy with the `type` argument. – Russ Lenth May 10 '17 at 23:40
  • Sorry thanks, @rvl. I tried this approach but I get the same results. (the axis are still square root transformed. When I call str(model_lsmeans) then R shows that it know that it is squareroot transformed (says sqrt.abs.) – Ditlev Reventlow May 12 '17 at 09:41
  • 1
    Well, it is hard to help when you don't describe what you did. Apparently, the model you actually fitted had `sqrt(abs(response)) ~ ...`, which explains why you see `sqrt.abs`. Do `model_lsmeans <- update(model_lsmeans, tran = "sqrt")`. Then it should work. – Russ Lenth May 12 '17 at 11:38
  • 1
    thinking further I am also troubled by your apparent use of `sqrt(abs(y))` transform. If `y` has both negative and positive values, then this transformation is not monotone, and thus does not preserve the ranks of the `y` values -- leading to a meaningless model. – Russ Lenth May 13 '17 at 16:24
  • Thank you @rvl. This solved my problem! I am very grateful! I am Sorry that I didn't state the absolute part in the question statement, I was not aware that this would make a principal difference. And thank you for this perspective regarding the transformation of absolute variables. I have used absolute values because I want e.g. 5 and -5 to mean the same in my model. Considering that sqrt(x) and sqrt(abs(-x)) is the same, I cannot understand why the transformation should give a problem (as long as the negative values are made absolute and should be treated as such in the model)? – Ditlev Reventlow May 15 '17 at 10:27
  • Well as long as you truly do want to model abs(y), that's fine. – Russ Lenth May 15 '17 at 12:25
  • How can I mark this question as answered? When I look in the help section there should apply a green tick next the answer that solved my problem, but I don't see any. Is this because my question was edited by another user? – Ditlev Reventlow May 21 '17 at 13:46
  • Hmmm, I don't think that edit should matter. Make sure you're logged-on??? At any rate, I am glad the answer works. – Russ Lenth May 22 '17 at 12:58
  • 1
    You need at least 15 reputation points before you can upvote. Maybe the same is true of accepting answers... – Russ Lenth May 23 '17 at 02:33
  • I am logged in so it must be my reputation that is too low! Thank you for your help! – Ditlev Reventlow May 23 '17 at 13:45

0 Answers0