
Generate adaptive priors based on data characteristics
Source:R/utils-priors.R
generate_adaptive_priors.RdGenerate adaptive priors based on data characteristics
Arguments
- data
A data frame containing the outcome and grouping variables.
- structure
A list describing the hierarchical structure (from
detect_hierarchical_structure).- model_type
Character string specifying the model family. Any brms family name is accepted and resolved to an intercept-link group via
.prior_model_type: identity-link families use a response-scale intercept, log-link families ("poisson","negbinomial","Gamma", ...) a log-scale intercept, and logit-link families ("bernoulli","beta","cumulative", ...) a logit-scale intercept.
Value
A list of prior specifications including intercept, treatment, sigma (for Gaussian), random effects (if multilevel), hedging weight (if historical data available), and recommendations.
Examples
d <- simulate_scd_data(n_cases = 3)
structure <- list(n_levels = 2, levels = list(case = "case"))
generate_adaptive_priors(d, structure)
#> $intercept
#> $intercept$distribution
#> [1] "student_t"
#>
#> $intercept$df
#> [1] 3
#>
#> $intercept$location
#> [1] 48.78038
#>
#> $intercept$scale
#> [1] 4.945789
#>
#> $intercept$description
#> [1] "student_t(3, 48.78, 4.95)"
#>
#>
#> $treatment
#> $treatment$distribution
#> [1] "normal"
#>
#> $treatment$mean
#> [1] 0
#>
#> $treatment$sd
#> [1] 2.472895
#>
#> $treatment$description
#> [1] "normal(0, 2.47)"
#>
#>
#> $sigma
#> $sigma$distribution
#> [1] "student_t"
#>
#> $sigma$df
#> [1] 3
#>
#> $sigma$location
#> [1] 0
#>
#> $sigma$scale
#> [1] 2.472895
#>
#> $sigma$description
#> [1] "student_t(3, 0, 2.47)"
#>
#>
#> $random_effects
#> $random_effects$correlation
#> $random_effects$correlation$distribution
#> [1] "lkj"
#>
#> $random_effects$correlation$eta
#> [1] 2
#>
#> $random_effects$correlation$description
#> [1] "lkj(2)"
#>
#>
#>
#> $recommendations
#> $recommendations$sample_size
#> [1] "Small sample size detected. Using informative priors for stability."
#>
#> $recommendations$overall
#> [1] "Prior strength: strong (scale factor: 0.50)"
#>
#>