Closed lang-benjamin closed 6 days ago
thank you @lang-benjamin fore reporting this, this is for sure high priority and we will fix soon!
I am not sure if this is a bug or feature but let me try to make this clear
so when we have a transformed value in the covariates, how we should decide the mean of that covariate, do we use mean of untransformed, or mean of transformed?
currently in emmeans
the mean of untransformed value is always used. this is also true for glm
and other fits
examples see below
library(emmeans)
d <- data.frame(
y = rbinom(100, 1, 0.5),
x = rnorm(100) + 100
)
d$x2 <- log(d$x)
a <- glm(y ~ log(x), data = d)
b <- glm(y ~ x2, data = d)
ref_grid(a, ~ 1)
ref_grid(b, ~ 1)
there will be minor differences
I guess this could be a emmeans
question (and hopefully answer somewhere there) of how to make it work?
@wlandau we just went through these types of questions for emmeans in brms.mmrm, do you recall anything like this?
library(mmrm)
library(emmeans)
#> mmrm() registered as emmeans extension
#> Welcome to emmeans.
#> Caution: You lose important information if you filter this package's results.
#> See '? untidy'
library(broom)
#> mmrm() registered as emmeans extension
#> Welcome to emmeans.
#> Caution: You lose important information if you filter this package's results.
#> See '? untidy'
fit1 <- mmrm(
formula = FEV1 ~ log(FEV1_BL) + RACE + SEX + ARMCD * AVISIT + us(AVISIT | USUBJID),
data = fev_data
)
fit2 <- mmrm(
formula = FEV1 ~ log_FEV1_BL + RACE + SEX + ARMCD * AVISIT + us(AVISIT | USUBJID),
data = within(fev_data, log_FEV1_BL <- log(FEV1_BL))
)
ref_grid(fit1)
#> 'emmGrid' object with variables:
#> FEV1_BL = 40.191
#> RACE = Asian, Black or African American, White
#> SEX = Male, Female
#> ARMCD = PBO, TRT
#> AVISIT = VIS1, VIS2, VIS3, VIS4
ref_grid(fit2)
#> 'emmGrid' object with variables:
#> log_FEV1_BL = 3.667
#> RACE = Asian, Black or African American, White
#> SEX = Male, Female
#> ARMCD = PBO, TRT
#> AVISIT = VIS1, VIS2, VIS3, VIS4
emmeans(fit1, ~ ARMCD | AVISIT,at = list(FEV1_BL = exp(3.667))) |>
tidy()
#> # A tibble: 8 × 7
#> ARMCD AVISIT estimate std.error df statistic p.value
#> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 PBO VIS1 33.2 0.734 144. 45.3 4.72e- 87
#> 2 TRT VIS1 37.3 0.741 140. 50.3 1.64e- 91
#> 3 PBO VIS2 38.0 0.579 144. 65.7 3.34e-109
#> 4 TRT VIS2 42.0 0.569 141. 73.8 1.61e-114
#> 5 PBO VIS3 43.6 0.442 129. 98.8 2.23e-123
#> 6 TRT VIS3 46.6 0.488 130. 95.3 4.70e-122
#> 7 PBO VIS4 48.4 1.17 133. 41.3 6.28e- 78
#> 8 TRT VIS4 52.9 1.17 132. 45.2 3.03e- 82
emmeans(fit2, ~ ARMCD | AVISIT) |>
tidy()
#> # A tibble: 8 × 7
#> ARMCD AVISIT estimate std.error df statistic p.value
#> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 PBO VIS1 33.2 0.734 144. 45.3 4.70e- 87
#> 2 TRT VIS1 37.3 0.741 140. 50.3 1.63e- 91
#> 3 PBO VIS2 38.0 0.579 144. 65.7 3.35e-109
#> 4 TRT VIS2 42.0 0.569 141. 73.8 1.61e-114
#> 5 PBO VIS3 43.6 0.442 129. 98.8 2.23e-123
#> 6 TRT VIS3 46.6 0.488 130. 95.3 4.71e-122
#> 7 PBO VIS4 48.4 1.17 133. 41.3 6.28e- 78
#> 8 TRT VIS4 52.9 1.17 132. 45.2 3.03e- 82
Created on 2024-07-12 by the reprex package (v2.0.1)
I am not sure if this is a bug or feature [...]
so when we have a transformed value in the covariates, how we should decide the mean of that covariate, do we use mean of untransformed, or mean of transformed?
currently in
emmeans
the mean of untransformed value is always used. this is also true forglm
and other fits
Thank you! If one opts for having a log-transformation of a covariate (e.g. to enable a relationship to the response that is approximately linear), then I would say that the mean should be considered from this transformed scale. I assumed that emmeans
itself would calculate the mean of log-transformed values once the model specification includes log(covariate). It seems that this is not the case, though. So, I guess this is more a question to emmeans
itself and not directly to mmrm
.
Yes, I think it sounds like this is more a question to the emmeans
team
I think we can close this issue as this is not really mmrm related
closing as it is a question for emmeans
When doing some transformation (e.g. log) as part of the formula specification, a subsequent emmeans call does not provide the correct results. I am using the most up to date development version of mmrm and the newest CRAN release from emmeans.
Consider the following example:
Created on 2024-07-11 with reprex v2.1.0