Computes statistics for a MaxDiff model at either the aggregate or individual level, including probabilities, mean100 scores, and significance tests.
Arguments
- model
A fitted MaxDiff model object created by
md_model().- cohorts
A
cohort,cohort_set, orNULL(for full population). Only applicable for individual-level models. Create cohorts usingcreate_cohort()orcreate_cohort_set().
Value
A data frame with item statistics:
For aggregate models: Statistics for the whole population
For individual models with a single cohort: A dataframe with item statistics
For individual models with a cohort set: A modified cohort set with a new
statscolumn containing statistics for each cohort
Examples
# For aggregate models
mod_mlogit <- md_model(example_md_parsed_data, type = "mlogit")
stats_mlogit <- md_stats(mod_mlogit)
# For individual models (full population)
# list(R = 500, keep = 1) means that 500 draws are made and
# every 1st draw is kept = each draw
mod_bayesm <- md_model(
example_md_parsed_data,
type = "bayesm",
mcmc = list(R = 500, keep = 1)
)
#> Z not specified
#> Table of Y values pooled over all units
#> ypooled
#> 1 2 3 4 5
#> 1504 1276 1170 1137 1103
#>
#> Starting MCMC Inference for Hierarchical Logit:
#> Normal Mixture with 1 components for first stage prior
#> 5 alternatives; 25 variables in X
#> for 213 cross-sectional units
#>
#> Prior Parms:
#> nu = 28
#> V
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
#> [1,] 28 0 0 0 0 0 0 0 0 0 0 0 0
#> [2,] 0 28 0 0 0 0 0 0 0 0 0 0 0
#> [3,] 0 0 28 0 0 0 0 0 0 0 0 0 0
#> [4,] 0 0 0 28 0 0 0 0 0 0 0 0 0
#> [5,] 0 0 0 0 28 0 0 0 0 0 0 0 0
#> [6,] 0 0 0 0 0 28 0 0 0 0 0 0 0
#> [7,] 0 0 0 0 0 0 28 0 0 0 0 0 0
#> [8,] 0 0 0 0 0 0 0 28 0 0 0 0 0
#> [9,] 0 0 0 0 0 0 0 0 28 0 0 0 0
#> [10,] 0 0 0 0 0 0 0 0 0 28 0 0 0
#> [11,] 0 0 0 0 0 0 0 0 0 0 28 0 0
#> [12,] 0 0 0 0 0 0 0 0 0 0 0 28 0
#> [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 0 0 0 0 0
#> [19,] 0 0 0 0 0 28 0 0 0 0 0 0
#> [20,] 0 0 0 0 0 0 28 0 0 0 0 0
#> [21,] 0 0 0 0 0 0 0 28 0 0 0 0
#> [22,] 0 0 0 0 0 0 0 0 28 0 0 0
#> [23,] 0 0 0 0 0 0 0 0 0 28 0 0
#> [24,] 0 0 0 0 0 0 0 0 0 0 28 0
#> [25,] 0 0 0 0 0 0 0 0 0 0 0 28
#> mubar
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14]
#> [1,] 0 0 0 0 0 0 0 0 0 0 0 0 0 0
#> [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23] [,24] [,25]
#> [1,] 0 0 0 0 0 0 0 0 0 0 0
#> Amu
#> [,1]
#> [1,] 0.01
#> a
#> [1] 5
#>
#> MCMC Parms:
#> s= 0.476 w= 0.1 R= 500 keep= 1 nprint= 100
#>
#> initializing Metropolis candidate densities for 213 units ...
#> completed unit # 50
#> completed unit # 100
#> completed unit # 150
#> completed unit # 200
#> MCMC Iteration (est time to end - min)
#> 100 (0.0)
#> 200 (0.0)
#> 300 (0.0)
#> 400 (0.0)
#> 500 (0.0)
#> Total Time Elapsed: 0.05
stats_bayesm <- md_stats(mod_bayesm)
# For individual models with specific cohorts
female_cohort <- example_md_data |>
haven::as_factor() |>
dplyr::filter(s_gender == "Female") |>
g6tr.cohorts::create_cohort(id_col = "response_id")
#> ℹ No weights provided. Using equal weights of 1.
stats_female <- md_stats(mod_bayesm, cohorts = female_cohort)
#> Warning: Cohort contains 5 respondents unknown to the model:
#>
#> "R_40B4m0P4eRx5OZr", "R_3lAnv54h4RHHV2v", "R_1f9RoTYlh6qSWfA",
#> "R_ZjxB4uG9OOXRG49", and "R_2CdeYg6vSpk6hdY"
# For individual models with cohort sets
cohort_set <- example_md_data |>
haven::as_factor() |>
g6tr.cohorts::create_cohort_set(
id_col = "response_id",
grp_cols = "s_gender"
)
#> ℹ No weights provided. Using equal weights of 1.
stats_by_gender <- md_stats(mod_bayesm, cohorts = cohort_set)
#> Warning: Cohort contains 7 respondents unknown to the model:
#>
#> "R_40B4m0P4eRx5OZr", "R_3lAnv54h4RHHV2v", "R_1f9RoTYlh6qSWfA",
#> "R_3n8Hi62m4U6Z7cX", "R_u83bGPAUc7oqIRr", "R_ZjxB4uG9OOXRG49", and
#> "R_2CdeYg6vSpk6hdY"
#> Warning: Cohort contains 2 respondents unknown to the model:
#>
#> "R_3n8Hi62m4U6Z7cX" and "R_u83bGPAUc7oqIRr"
#> Warning: Cohort contains 5 respondents unknown to the model:
#>
#> "R_40B4m0P4eRx5OZr", "R_3lAnv54h4RHHV2v", "R_1f9RoTYlh6qSWfA",
#> "R_ZjxB4uG9OOXRG49", and "R_2CdeYg6vSpk6hdY"
#> ℹ Using the first cohort in the cohort set as the reference for comparisons.
#> If you need a different reference, please reorder the cohort set accordingly.
#> • column: "population"
#> • label: "Overall population"
#> • level: "population"