report.lsmeans.Rd
Creates a desc object for "LS Means" statistics reporting.
For more examples see the website: ClinReport website
report.lsmeans(lsm, at.row = NULL, infer = c(T, T), round = 2, x1, x2, x3, x1.name, x2.name, x3.name, data, contrast, contrast.name, type, transpose = FALSE, y.label = NULL)
lsm | emmGrid object (result of a |
---|---|
at.row | Character. Passed to spacetable function. Used to space the results per levels of the mentioned variable |
infer | A vector of one or two logical values. Passed to |
round | Numeric. Specify the number of digits to round the statistics |
x1 | deprecated |
x2 | deprecated |
x3 | deprecated |
x1.name | deprecated |
x2.name | deprecated |
x3.name | deprecated |
data | deprecated |
contrast | deprecated |
contrast.name | deprecated |
type | deprecated |
transpose | Logical. If TRUE Statistics will be reported in columns |
y.label | Character Indicates the label for y parameter to be displayed in the title of the table |
A desc object that can be used by the report.doc
function.
You can produce formatted Least Square Means table for up to 3 factors. It doesn't work for quantitative covariates.
See examples below.
library(emmeans) library(lme4) data(datafake) #Simple lm model mod=lm(Petal.Width~Species,data=iris) raw.lsm=emmeans(mod,~Species) report.lsmeans(raw.lsm)#> #> ############################################ #> LS-Means table of: Petal.Width #> ############################################ #> #> Statistics setosa versicolor virginica #> 1 Estimate (SE) 0.25(0.03) 1.33(0.03) 2.03(0.03) #> 2 95% CI [0.19;0.30] [1.27;1.38] [1.97;2.08] #> 3 P-value <0.001 <0.001 <0.001 #> #> ############################################ #># You can display the Statistics in columns report.lsmeans(raw.lsm,transpose=TRUE)#> #> ############################################ #> LS-Means table of: Petal.Width #> ############################################ #> #> Species Estimate (SE) 95% CI P-value #> 1 setosa 0.25(0.03) [0.19;0.30] <0.001 #> 2 versicolor 1.33(0.03) [1.27;1.38] <0.001 #> 3 virginica 2.03(0.03) [1.97;2.08] <0.001 #> #> ############################################ #># In case of just one intercept mod=glm(Species~1,data=iris,family=binomial) raw.lsm=emmeans(mod,~1) report.lsmeans(raw.lsm)#> #> ############################################ #> LS-Means table of: Species #> ############################################ #> #> Statistics 1 #> 1 Estimate (SE) 0.69(0.17) #> 2 95% CI [0.35;1.03] #> 3 P-value <0.001 #> #> ############################################ #># Display statistics in columns report.lsmeans(raw.lsm,transpose=TRUE)#> #> ############################################ #> LS-Means table of: Species #> ############################################ #> #> 1 Estimate (SE) 95% CI P-value #> 1 1 0.69(0.17) [0.35;1.03] <0.001 #> #> ############################################ #>#Mixed model example using lme4 mod=lmer(y_numeric~GROUP+TIMEPOINT+GROUP*TIMEPOINT+(1|SUBJID),data=datafake)#>#> #> ############################################ #> LS-Means table of: y_numeric #> ############################################ #> #> TIMEPOINT Statistics A B C #> 1 D0 Estimate (SE) -0.93(0.20) -0.67(0.24) -1.19(0.26) #> 2 D0 95% CI [-1.32;-0.54] [-1.16;-0.19] [-1.72;-0.66] #> 3 D0 P-value <0.001 0.010 <0.001 #> 4 #> 5 D1 Estimate (SE) 1.83(0.20) 4.17(0.24) 4.98(0.26) #> 6 D1 95% CI [1.44;2.22] [3.70;4.63] [4.46;5.50] #> 7 D1 P-value <0.001 <0.001 <0.001 #> 8 #> 9 D2 Estimate (SE) 1.97(0.20) 4.04(0.24) 4.90(0.26) #> 10 D2 95% CI [1.58;2.35] [3.56;4.52] [4.38;5.42] #> 11 D2 P-value <0.001 <0.001 <0.001 #> 12 #> 13 D3 Estimate (SE) 1.78(0.19) 3.81(0.24) 5.07(0.27) #> 14 D3 95% CI [1.40;2.16] [3.33;4.29] [4.54;5.61] #> 15 D3 P-value <0.001 <0.001 <0.001 #> 16 #> 17 D4 Estimate (SE) 1.83(0.20) 3.80(0.24) 5.17(0.27) #> 18 D4 95% CI [1.44;2.22] [3.32;4.28] [4.64;5.71] #> 19 D4 P-value <0.001 <0.001 <0.001 #> 20 #> 21 D5 Estimate (SE) 2.27(0.19) 3.64(0.24) 4.43(0.26) #> 22 D5 95% CI [1.89;2.65] [3.18;4.11] [3.91;4.95] #> 23 D5 P-value <0.001 <0.001 <0.001 #> #> ############################################ #># Display statistics in columns report.lsmeans(lsm=raw.lsm,at="TIMEPOINT",transpose=TRUE)#> #> ############################################ #> LS-Means table of: y_numeric #> ############################################ #> #> TIMEPOINT GROUP Estimate (SE) 95% CI P-value #> 1 D0 A -0.93(0.20) [-1.32;-0.54] <0.001 #> 2 D0 B -0.67(0.24) [-1.16;-0.19] 0.010 #> 3 D0 C -1.19(0.26) [-1.72;-0.66] <0.001 #> 4 #> 5 D1 A 1.83(0.20) [1.44;2.22] <0.001 #> 6 D1 B 4.17(0.24) [3.70;4.63] <0.001 #> 7 D1 C 4.98(0.26) [4.46;5.50] <0.001 #> 8 #> 9 D2 A 1.97(0.20) [1.58;2.35] <0.001 #> 10 D2 B 4.04(0.24) [3.56;4.52] <0.001 #> 11 D2 C 4.90(0.26) [4.38;5.42] <0.001 #> 12 #> 13 D3 A 1.78(0.19) [1.40;2.16] <0.001 #> 14 D3 B 3.81(0.24) [3.33;4.29] <0.001 #> 15 D3 C 5.07(0.27) [4.54;5.61] <0.001 #> 16 #> 17 D4 A 1.83(0.20) [1.44;2.22] <0.001 #> 18 D4 B 3.80(0.24) [3.32;4.28] <0.001 #> 19 D4 C 5.17(0.27) [4.64;5.71] <0.001 #> 20 #> 21 D5 A 2.27(0.19) [1.89;2.65] <0.001 #> 22 D5 B 3.64(0.24) [3.18;4.11] <0.001 #> 23 D5 C 4.43(0.26) [3.91;4.95] <0.001 #> #> ############################################ #># LM model with specific contrast warp.lm <- lm(breaks ~ wool+tension+wool:tension, data = warpbreaks) warp.emm <- emmeans(warp.lm, ~ tension | wool) contr=contrast(warp.emm, "trt.vs.ctrl", ref = "M") report.lsmeans(lsm=contr,at="wool")#> #> ############################################ #> LS-Means table of: breaks #> ############################################ #> #> wool Statistics L - M H - M #> 1 A Estimate (SE) 20.56(5.16) 0.56(5.16) #> 2 A 95% CI [8.74;32.37] [-11.26;12.37] #> 3 A P-value <0.001 0.990 #> 4 #> 5 B Estimate (SE) -0.56(5.16) -10.00(5.16) #> 6 B 95% CI [-12.37;11.26] [-21.81;1.81] #> 7 B P-value 0.990 0.110 #> #> ############################################ #># Display statistics in columns report.lsmeans(lsm=contr,at="wool",transpose=TRUE)#> #> ############################################ #> LS-Means table of: breaks #> ############################################ #> #> wool contrast Estimate (SE) 95% CI P-value #> 1 A L - M 20.56(5.16) [8.74;32.37] <0.001 #> 2 A H - M 0.56(5.16) [-11.26;12.37] 0.990 #> 3 #> 4 B L - M -0.56(5.16) [-12.37;11.26] 0.990 #> 5 B H - M -10.00(5.16) [-21.81;1.81] 0.110 #> #> ############################################ #># Cox model library(survival) data(time_to_cure) fit <- coxph(Surv(time, status) ~ Group, data = time_to_cure) em=emmeans(fit,~Group,type="response") pairs=pairs(em,adjust="none",exclude="Untreated") pairs#> contrast ratio SE df z.ratio p.value #> Group A / Group B 0.657 0.251 NA -1.098 0.2723 #> Group A / Group C 0.487 0.188 NA -1.866 0.0620 #> Group B / Group C 0.740 0.269 NA -0.829 0.4071 #> #> Tests are performed on the log scalereport.lsmeans(pairs)#> #> ############################################ #> LS-Means comparisons of: time #> ############################################ #> #> Statistics Group A / Group B Group A / Group C Group B / Group C #> 1 Estimate (SE) 0.66(0.25) 0.49(0.19) 0.74(0.27) #> 2 95% CI [0.31;1.39] [0.23;1.04] [0.36;1.51] #> 3 P-value 0.270 0.060 0.410 #> #> ############################################ #># Display statistics in columns report.lsmeans(pairs,transpose=TRUE)#> #> ############################################ #> LS-Means comparisons of: time #> ############################################ #> #> contrast Estimate (SE) 95% CI P-value #> 1 Group A / Group B 0.66(0.25) [0.31;1.39] 0.270 #> 2 Group A / Group C 0.49(0.19) [0.23;1.04] 0.060 #> 3 Group B / Group C 0.74(0.27) [0.36;1.51] 0.410 #> #> ############################################ #>