How To Interpret Least Square Means and Standard Error

205 views Asked by At

I am trying to understand the results I got for a fake dataset. I have two independent variables, hours, type and response pain.

First question: How was 82.46721 calculated as the lsmeans for the first type?

Second question: Why is the standard error exactly the same (8.24003) for both types?

Third question: Why is the degrees of freedom 3 for both types?

data = data.frame(
  type = c("A", "A", "A", "B", "B", "B"),
  hours = c(60,72,61, 54,68,66),
  # pain = c(85,95,69, 73, 29, 30)
  pain = c(85,95,69, 85,95,69)
)

model = lm(pain ~ hours + type, data = data)  
lsmeans(model, c("type", "hours"))
> data
  type hours pain
1    A    60   85
2    A    72   95
3    A    61   69
4    B    54   85
5    B    68   95
6    B    66   69
> lsmeans(model, c("type", "hours"))
 type hours   lsmean      SE df lower.CL upper.CL
 A     63.5 82.46721 8.24003  3 56.24376 108.6907
 B     63.5 83.53279 8.24003  3 57.30933 109.7562
1

There are 1 answers

0
Russ Lenth On BEST ANSWER

Try this:

newdat <- data.frame(type = c("A", "B"), hours = c(63.5, 63.5))
predict(model, newdata = newdat)

An important thing to note here is that your model has hours as a continuous predictor, not a factor.