## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
options(rmarkdown.html_vignette.check_title = FALSE)

## ----setup--------------------------------------------------------------------
library(CHOIRBM)

## ----load_data----------------------------------------------------------------
# loading the validation data included in the CHOIRBM package
data(validation)
head(validation)

## ----proc_data----------------------------------------------------------------
# isolate and process male data
male_data <- validation[validation[["gender"]] == "Male", ]
male_bodymap_list <- lapply(male_data[["bodymap_regions_csv"]], string_to_map)
male_bodymap_df <- agg_choirbm_list(male_bodymap_list)

# isolate and process female data
female_data <- validation[validation[["gender"]] == "Female", ]
female_bodymap_list <- lapply(
  female_data[["bodymap_regions_csv"]]
  , string_to_map
)
female_bodymap_df <- agg_choirbm_list(female_bodymap_list)

# quick snapshot of each
head(male_bodymap_df)
head(female_bodymap_df)

## ----comp_chi-----------------------------------------------------------------
# name each data frame in the list as male or female
chi_res <- comp_choirbm_chi(
  list("male" = male_bodymap_df, "female" = female_bodymap_df)
  , method = "bonferroni"
)

# visualize the chi-square results
head(chi_res)

## ----ztest--------------------------------------------------------------------
comp_choirbm_ztest(list( "male" = male_data, "female" = female_data), tail = "two")

## ----comp_glm-----------------------------------------------------------------
# for the sake of speed, randomly sample 100 maps...
set.seed(123)
sampled_data <- validation[
  sample(
    seq_len(nrow(validation))
    , 100
    , replace = FALSE
  )
  , ]
colnames(sampled_data)[5] <- "bodymap"
model_output <- comp_choirbm_glm(sampled_data, "age", family = "binomial")
head(model_output)

