An R package for obtaining least-squares means for many linear, generalized linear, and mixed models. Compute contrasts or linear functions of least-squares means, and comparisons of slopes. Plots and compact letter displays.
Questions tagged [lsmeans]
111 questions
19
votes
1 answer
R: Tukey posthoc tests for nnet multinom multinomial fit to test for overall differences in multinomial distribution
I fitted a mutinomial model using nnet's multinom function using (in this case on data giving the diet preference of male and female and different size classes of alligators in different lakes)…

Tom Wenseleers
- 7,535
- 7
- 63
- 103
15
votes
1 answer
R: Plotting predictions of MASS polr ordinal model
I fitted a proportional odds cumulative logit model on ordinal data using MASS's polr function using (in this case on data giving the preference for different kinds of cheese)…

Tom Wenseleers
- 7,535
- 7
- 63
- 103
15
votes
1 answer
Extracting elements of lsmobj from lsmeans package in R
I wonder how to get the element of lsmobj from lsmeans package in R.
require(lsmeans)
fiber.lm <- lm(strength ~ diameter + machine, data = fiber)
fiber.lsm <- lsmeans (fiber.lm, "machine")
fiber.lsm
machine lsmean SE df lower.CL upper.CL
…

MYaseen208
- 22,666
- 37
- 165
- 309
7
votes
1 answer
multcomp Tukey-Kramer
I have an experiment that is unbalanced where at three sites (L, M, H) we measure a parameter (met) in four different vegetation types (a, b, c, d). All vegetation types are present at all three sites. Vegetation types are replicated 4 times at L…

thijs van den bergh
- 608
- 1
- 9
- 17
5
votes
1 answer
Can't get arcsin back-transformation with emmeans to work
I am doing a GAM with my response variable as a percentage (0-100). I have used an arcsin transformation to improve model fit (asin(sqrt(myvariable/100))). I now want to evaluate contrasts between levels of my explanatory factor variable on the…

evelyn
- 63
- 5
4
votes
1 answer
increasing max.print does not always work in R and neither does global options for lsmeans()
Half of the time, without pattern, I get rows omitted from the output even though I increase max.print and the global options in R studio. Details below:
I am running an lmer model on large datasets (more than 100,000 observations of 14 variables)…

catcool7
- 71
- 1
- 7
4
votes
1 answer
Mean variance of a difference of BLUEs or BLUPs in `lme4`
Given below is the code for analysis of a resolvable alpha design (alpha lattice design) using the R package asreml.
# load the data
library(agridat)
data(john.alpha)
dat <- john.alpha
# load asreml
library(asreml)
# model1 - random…

Crops
- 5,024
- 5
- 38
- 65
4
votes
2 answers
Post-hoc tests linear mixed model lsmeans error
I have a question about running post hoc tests on linear mixed models:
I am running a linear mixed model in lme4 with 3 groups, 5 snakes per group, each group at a different ventilation rate (Vent), measurements taken at different time points…

Catherine Williams
- 41
- 2
4
votes
2 answers
Plot least-squares means for groups of factor levels
I'm looking for a simple way to extract (and plot) the least-squares means of specified combinations of levels of one factor, for each level of another factor.
Example data:
set.seed(1)
model.data <- data.frame(time = factor(paste0("day", rep(1:8,…

tractorjack
- 127
- 8
3
votes
2 answers
Getting Generalized Least Squares Means for fixed effects in nlme or lme4
Least Squares Means with their standard errors for aov object can be obtained with model.tables function:
npk.aov <- aov(yield ~ block + N*P*K, npk)
model.tables(npk.aov, "means", se = TRUE)
I wonder how to get the generalized least squares means…

MYaseen208
- 22,666
- 37
- 165
- 309
3
votes
1 answer
lapply: Fitting thousands of mixed models and being able to extract lsmeans
I have a list of formulas (> 10,000) for linear mixed models (lme4) that I fitted to a data set. Successfully, I have used lapply() and a custom function that incorporated tryCatch() to fit these models. Now I would like to extract the P-values and…

rsp
- 35
- 4
3
votes
1 answer
Is there a way to obtain event probability from a coxme model?
I would like to obtain prediction of an event probability from a coxme model, for a given values of my explanatory variables, and at a given timestep. My data are structured like this:
# Generate data
set.seed(123)
mydata <- data.frame(Site =…

Julien Barrère
- 51
- 4
3
votes
2 answers
Estimating difference in lsmeans
How does one use lsmeans to estimate the difference in two pairwise contrasts? For instance--imagine a continuous dv and two factor predictors
library(lsmeans)
library(tidyverse)
dat <- data.frame(
y = runif(30),
x1 = 1:2 %>%
factor %>%
…

tomw
- 3,114
- 4
- 29
- 51
3
votes
2 answers
Generating similar estimates of interactions in afex, lsmeans, and lme4 packages
I would like to know if there is a way get the same estimates of an interaction effect in afex & lsmeans packages as in lmer. The toy data below is for two groups with different intercepts and slopes.
set.seed(1234)
A0 <- rnorm(4,2,1)
B0 <-…

llewmills
- 2,959
- 3
- 31
- 58
3
votes
2 answers