3

I transformed a variable (e.g. leaf_area) using a simple square transformation and then fitted to the following model containing an interaction:

fit <- lmer(leaf_area^2 ~genotype*soil_type + date_measurement + light + (1|repetition) + (1|y_position) + (1|x_position), data = dataset)

To obtain the emmeans averaged accross genotypes and soil type for each measurement date, I further use the following command:

fit.emm <- emmeans(fit, ~ genotype*soil_type + date_measurement, type = "response")

The emmeans are, nevertheless, averaged for the variable date_measurement. As represented in the following example, emmeans are averages of genotypes x, y and z in the soil MT and in the date of measurement 27.4, but the measurement dates actually occured on 21, 23, 28, 30 and 35 das.

genotype soil_type  date_measurement emmean     SE       df     lower.CL upper.CL
 x         MT         27.4            0.190    0.0174    126.0    0.155    0.224
 y         MT         27.4            0.220    0.0147    74.1     0.191    0.250
 z         MT         27.4            0.210    0.0157    108.6    0.179    0.241

When I fit the model without interaction between genotype and soil type and run the emmeans, the results are still averaged for the measurement dates.

fit <- lmer(leaf_area^2 ~genotype + soil_type + date_measurement + light + (1|repetition) + (1|y_position) + (1|x_position), data = dataset)

fit.emm <- emmeans(fit, ~ genotype + soil_type + date_measurement, type = "response")

My question is: how can I obtain the emmeans averaged accross genotype and soil but separated for each date of measurement?

Class of variables: date_measurement, light, x_position, y_position: numeric genotype and soil_type: factor

Thank you in advance.

Russ Lenth
  • 5,922
  • 2
  • 13
  • 21
Elisa
  • 31
  • 1

1 Answers1

1

When you have a numerical predictor in the model, the default is to obtain predictions at the average value of that covariate. If you want the covariates treated like factors, you have to say so:

fit.emm <- emmeans(fit, ~ genotype*soil_type + date_measurement, 
    cov.reduce = FALSE)

In addition, emmeans cannot auto-detect your square transformation. You can fix it up by doing

fit.emm <- update(fit.emm, tran = make.tran("power", 2),
    type = "response")

Then I think you will want to subsequently obtain marginal means by averaging over date_measurement at least -- i.e.,

fit.emm2 <- emmeans(fit.emm, ~ genotype*soil_type)

It will retain the transformation and type = "response" setting.

Russ Lenth
  • 5,922
  • 2
  • 13
  • 21
  • I just realized that there is also a predictor `light` in the model. The `cov.reduce = FALSE` argument causes that to be treated like a factor too. Are you sure you are not satisfied with the covariates being reduced to their means? That's typically what is done, e.g. "adjusted means" in ANCOVA – Russ Lenth Jul 11 '22 at 20:55