This function aggregates individual mental models in an mtoolr object. If a grouping variable (eg. a column "likes_cycling" added to the object, see `add_user_data()`) is supplied and a grouping value (eg. "yes") is supplied, only mental models of this group are aggregated (so only the mental models of users who like cycling). Currently, models are aggregated using the median value of edge weights to establish edges and edge weight.
Usage
aggregate_mentalmodel(
mentalmodel,
aggregate_function = "median",
group_var = NULL,
group_value = NULL
)
Arguments
- mentalmodel
A mtoolr object
- aggregate_function
Currently, this defaults to the median value.
- group_var
A character string giving a (preferably factor) variable in the user data to group by (eg. "likes_cycling").
- group_value
A value in group_var to match by (eg. "yes")
Examples
# aggregate all models in example data
aggregate_mentalmodel(example_models)
#> # A tibble: 103 × 3
#> From To Weight
#> <chr> <chr> <dbl>
#> 1 Carbon capture and storage Climate compensation 2
#> 2 Carbon capture and storage Energy transition 2
#> 3 Climate compensation Carbon capture and storage 2
#> 4 Climate compensation Electrics cars 1
#> 5 Climate compensation Energy efficient home appliances 1
#> 6 Climate compensation Energy efficient houses 1
#> 7 Climate compensation Energy transition 2
#> 8 Climate compensation Hydropower 1
#> 9 Climate compensation Nuclear power 1
#> 10 Climate compensation Science 1
#> # … with 93 more rows
#> IGRAPH 15d2063 DNW- 17 103 --
#> + attr: name (v/c), Weight (e/n), weight (e/n)
#> + edges from 15d2063 (vertex names):
#> [1] Carbon capture and storage->Climate compensation
#> [2] Carbon capture and storage->Energy transition
#> [3] Climate compensation ->Carbon capture and storage
#> [4] Climate compensation ->Electrics cars
#> [5] Climate compensation ->Energy efficient home appliances
#> [6] Climate compensation ->Energy efficient houses
#> [7] Climate compensation ->Energy transition
#> [8] Climate compensation ->Hydropower
#> + ... omitted several edges
# simulate user data to add
user_df <- data.frame(id = example_models$user_data$id,var = rnorm(length(example_models$user_data$id)))
user_df$group <- ifelse(user_df$var > 0, "group1","group2")
# add user data
example_models <- example_models |> add_user_data(user_data = user_df,id_key = "id")
# aggregate by group
agg_model_group1 <- aggregate_mentalmodel(example_models,group_var = "group",group_value = "group1")
agg_model_group1
#> # A tibble: 63 × 3
#> From To Weight
#> <chr> <chr> <dbl>
#> 1 Carbon capture and storage Energy transition 2
#> 2 Climate compensation Carbon capture and storage 2
#> 3 Climate compensation Energy efficient home appliances 1
#> 4 Climate compensation Energy efficient houses 1
#> 5 Climate compensation Energy transition 1.5
#> 6 Climate compensation Hydropower 1
#> 7 Electrics cars Energy saving 2
#> 8 Electrics cars Energy transition 2
#> 9 Energy efficient home appliances Energy saving 2
#> 10 Energy efficient home appliances Energy transition 2.5
#> # … with 53 more rows
#> IGRAPH c0f6c93 DNW- 17 63 --
#> + attr: name (v/c), Weight (e/n), weight (e/n)
#> + edges from c0f6c93 (vertex names):
#> [1] Carbon capture and storage ->Energy transition
#> [2] Climate compensation ->Carbon capture and storage
#> [3] Climate compensation ->Energy efficient home appliances
#> [4] Climate compensation ->Energy efficient houses
#> [5] Climate compensation ->Energy transition
#> [6] Climate compensation ->Hydropower
#> [7] Electrics cars ->Energy saving
#> [8] Electrics cars ->Energy transition
#> + ... omitted several edges