Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flexible distributional standard deviations. #105

Merged
merged 24 commits into from
May 29, 2024
Merged

Flexible distributional standard deviations. #105

merged 24 commits into from
May 29, 2024

Conversation

wlandau
Copy link
Collaborator

@wlandau wlandau commented May 16, 2024

This PR fixes #102. @andrew-bean, @chstock, and @yonicd, would you be willing to have a look?

There is a new brm_formula_sigma() function to flexibly model residual variances.

set.seed(0)
data <- brm_data(
  data = brm_simulate_simple()$data,
  outcome = "response",
  role = "response",
  group = "group",
  time = "time",
  patient = "patient",
  reference_group = "group_1",
  reference_time = "time_1"
)

brm_formula_sigma(data) # heterogeneous
# sigma ~ 0 + AVISIT
# attr(,"brm_allow_effect_size")
# [1] TRUE
# <environment: 0x144d60588>
brm_formula_sigma(data, time = FALSE, intercept = TRUE) # homogeneous
# sigma ~ 1
# attr(,"brm_allow_effect_size")
# [1] TRUE
# <environment: 0x16f95e5f8>
brm_formula_sigma(
  data,
  time = TRUE,
  group = TRUE,
  subgroup = TRUE,
  covariates = TRUE
)
# sigma ~ 0 + ARMCD + SEX + AVISIT + RACE
# attr(,"brm_allow_effect_size")
# [1] FALSE
# <environment: 0x145407fe0>

The formula from brm_formula_sigma() serves as the sigma argument of brm_formula():

brm_formula(
  data = data,
  sigma = brm_formula_sigma(
    data,
    time = TRUE,
    group = TRUE,
    subgroup = TRUE,
    covariates = TRUE
  )
)
#> FEV1 ~ ARMCD + ARMCD:SEX + ARMCD:SEX:AVISIT + ARMCD:AVISIT + SEX + SEX:AVISIT + AVISIT + RACE + unstr(time = AVISIT, gr = USUBJID) 
#> sigma ~ 0 + ARMCD + SEX + AVISIT + RACE

As I mentioned in #102 (comment), this flexibility creates issues calculating effect size, so brm_marginal_draws() now omits effect size when the brm_formula_sigma() formula uses baseline or covariates.

@wlandau wlandau self-assigned this May 16, 2024
@wlandau
Copy link
Collaborator Author

wlandau commented May 16, 2024

Also, this PR is downstream of #100, so it would be good to merge #100 first.

@wlandau
Copy link
Collaborator Author

wlandau commented May 20, 2024

In e836b70, I rewrote the model vignette to be much friendlier, more readable, and more in line with the notation and vignettes in brms (c.f. #108).

@wlandau wlandau merged commit ffe3b39 into main May 29, 2024
2 of 8 checks passed
@wlandau wlandau deleted the 102 branch May 29, 2024 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Treatment-group-specific variances
1 participant