# lsmeans() to infer if a mean is different from 0 after using mixed-model

my data:

values:
[1]  0.69  0.99  0.49  1.10 -0.34  0.76  0.88  1.98 -0.14 -3.96 -2.73 -0.39  1.72
[14] -5.76 -3.69  0.13  0.42  0.27  1.10  0.87  0.84  0.54 -0.41 -0.36

groups:
[1] "2"  "2"  "2"  "3"  "3"  "3"  "4w" "4w" "4w" "5n" "5n" "5n" "5s" "5s" "5s"
[16] "7"  "7"  "7"  "8"  "8"  "8"  "9n" "9n" "9n"


I fitted a mixed model with the mean as predictor and got an output.

mod<- lmer(values~1 + (1|groups))

Scaled residuals:
Min      1Q  Median      3Q     Max
-2.6092 -0.2184  0.2177  0.4001  2.0879

Random effects:
Groups                  Name        Variance Std.Dev.
DFClay_groups$$B$$D.a.akt (Intercept) 1.215    1.102
Residual                            2.536    1.592
Number of obs: 24, groups:  DFClay_groups$$B$$D.a.akt, 8

Fixed effects:
Estimate Std. Error t value
(Intercept)  -0.2083     0.5075  -0.411


The reason I chose this model (with ~1) is because I want to test if the mean of the data-set is the same as zero while accounting for the random effect governing the values.

To test for H0: mean = 0 I used the lsmeans() function:

lsmeansmod<-lsmeans(mod, ~1) ### In the special case where the mean (or weighted mean) of all the predictions is desired, specify specs as ~ 1 or "1". (R-Handbook)


I wrapped the lsmeansmod into the summary() function.

summary(lsmeansmod, infer = c(TRUE,TRUE))

output:
1       lsmean    SE df lower.CL upper.CL t.ratio p.value
overall -0.208 0.507  7    -1.41    0.992 -0.411  0.6937


Is the p-value now telling me that the mean of the data that have been "corrected" for the random effect is not different from 0?

I think the relevant question is whether the hierarchical structure of the design/data is "meaningful" enough to be modeled. To test this, you need to first run an lmer() model with the grouping structure specified and then run an lm() model without the random effect(s). Once you have both of those, you need to estimate a likelihood ratio (LR) test comparing the two models using exactLRT() from RLRsim(). If the LR test is significant, that indicates that you need to account for the dependency in the data. It doesn't necessarily tell you how to account for such dependency. There are many different ways to do so (e.g., adjust standard errors, use dummy 'fixed effects' for the groups, or use a gee) and it is up to you to decide which is best for your application.