Skip to content

Commit

Permalink
Try doing #95: does it make sense? Don't think so...
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Howes committed Apr 20, 2022
1 parent 85c8b21 commit 092ff21
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/process_variance-proportions/orderly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ depends:
id: latest
use:
depends/variance-proportions.csv: variance-proportions.csv
depends/multi-sexbehav-sae.csv: multi-sexbehav-sae.csv
depends/multi-sexbehav-sae-fits.rds: multi-sexbehav-sae-fits.rds
- aaa_fit_multi-sexbehav-sae:
id: latest(parameter:iso3 == "BWA" && parameter:three_category == TRUE)
Expand Down
56 changes: 56 additions & 0 deletions src/process_variance-proportions/script.R
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,60 @@ df %>%
mutate(across(everything(), ~ 100 * round(.x, 3)))

#' Now to try the alternative method for looking within country when the model is fit jointly between all countries
#' Probably there is a better way to do this

fits <- readRDS("depends/multi-sexbehav-sae-fits.rds")
fit <- fits[[1]]

#' Use the results from the model as dictionary for variable to idx correspondence
#' * indicator: cat_idx
#' * iso3: iso3_idx
#' * year: year_idx
#' * area_id: area_idx
#' * age_group: age_idx
idx_dictionary <- read_csv("depends/multi-sexbehav-sae.csv") %>%
select(indicator, cat_idx, age_group, age_idx, iso3, iso3_idx, area_id, area_idx, year, year_idx) %>%
mutate(
age_idx_rowname = age_idx * cat_idx,
iso3_idx_rowname = iso3_idx * cat_idx,
area_idx_rowname = area_idx * cat_idx,
year_idx_rowname = year_idx * cat_idx
)

cat_df <- fit$summary.random$cat_idx
age_df <- rownames_to_column(fit$summary.random$age_idx) %>% mutate(rowname = as.numeric(rowname))
iso3_df <- rownames_to_column(fit$summary.random$iso3_idx) %>% mutate(rowname = as.numeric(rowname))
area_df <- rownames_to_column(fit$summary.random$area_idx) %>% mutate(rowname = as.numeric(rowname))
year_df <- rownames_to_column(fit$summary.random$year_idx) %>% mutate(rowname = as.numeric(rowname))

re_df <-idx_dictionary %>%
left_join(
select(cat_df, cat_idx = ID, cat_val = mean),
by = "cat_idx"
) %>%
left_join(
select(age_df, age_idx_rowname = rowname, age_val = mean),
by = "age_idx_rowname"
) %>%
left_join(
select(iso3_df, iso3_idx_rowname = rowname, iso3_val = mean),
by = "iso3_idx_rowname"
) %>%
left_join(
select(area_df, area_idx_rowname = rowname, area_val = mean),
by = "area_idx_rowname"
) %>%
left_join(
select(year_df, year_idx_rowname = rowname, year_val = mean),
by = "year_idx_rowname"
)

re_df %>%
group_by(iso3) %>%
summarise(
cat_idx = mean(abs(cat_val)),
age_idx = mean(abs(age_val)),
iso3_idx = mean(abs(iso3_val)),
area_idx = mean(abs(area_val)),
year_idx = mean(abs(year_val))
)

0 comments on commit 092ff21

Please sign in to comment.