From dca229be117b26c85076a56eb2143e32f841b9f0 Mon Sep 17 00:00:00 2001 From: Closed-Limelike-Curves Date: Fri, 28 May 2021 10:31:02 -0700 Subject: [PATCH 1/9] Add LOO variation plot --- R/loo_variation_plot.R | 151 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 R/loo_variation_plot.R diff --git a/R/loo_variation_plot.R b/R/loo_variation_plot.R new file mode 100644 index 00000000..6ae56916 --- /dev/null +++ b/R/loo_variation_plot.R @@ -0,0 +1,151 @@ +#' Compare models across domains +#' +#' The LOO variation plot shows how the predictive accuracy of two different +#' models changes as the predictor is varied. This can is useful for identifying +#' opportunities for model stacking or expansion. +#' +#' @param y A vector of observations. See Details. +#' @param psis_object_1,psis_object_2 If using loo version 2.0.0 or greater, +#' an object returned by the `[loo::psis()]` function (or by the +#' `[loo::loo()]` function with argument `save_psis` set to `TRUE`). +#' @param ... Currently unused. +#' @param group A grouping variable (a vector or factor) the same length +#' as `y`. Each value in group is interpreted as the group level pertaining +#' to the corresponding value of `y`. If `FALSE`, ignored. +#' @param size,alpha,jitter Passed to `[ggplot2::geom_point()]` to control +#' aesthetics. `size` and `alpha` are passed to to the `size` and `alpha` +#' arguments of `[ggplot2::geom_jitter()]` to control the appearance of +#' points. `jitter` can be either a number or a vector of numbers. +#' Passing a single number will jitter variables along the x axis only, while +#' passing a vector will jitter along both axes. +#' @param quantiles Boolean that determines whether to plot the quantiles of +#' `y` rather than `y` itself. Useful when `y` has a very irregular +#' distribution. +#' @param sortByGroup Sort observations by `group`, then plot against an +#' arbitrary index. Plotting by index can be useful when categories have +#' very different sample sizes. +#' +#' +#' @template return-ggplot +#' +#' @template reference-vis-paper +#' +#' @examples +#' +#' library(loo) +#' +#' cbPalette <- c("#636363", "#E69F00", "#56B4E9", "#009E73", +#' "#F0E442", "#0072B2","#CC79A7") +#' +#' # Plot using groups from WHO +#' +#' plot_loo_dif(factor(GM@data$super_region_name), loo3, loo2, +#' group = GM@data$super_region_name, alpha = .5, +#' jitter = c(.45, .2) +#' ) + +#' xlab("Region") + scale_colour_manual(values=cbPalette) +#' +#' # Plot using groups identified with clustering +#' +#' plot_loo_dif(factor(GM@data$cluster_region), loo3, loo2, +#' group = GM@data$super_region_name, alpha = .5, +#' jitter = c(.45, .2) +#' ) + +#' xlab("Cluster Group") + scale_colour_manual(values=cbPalette) +#' +#' # Plot using an index variable to reduce crowding +#' +#' plot_loo_dif(1:2980, loo3, loo2, group = GM@data$super_region_name, +#' alpha = .5, sortByGroup = TRUE, +#' ) + +#' xlab("Index") + scale_colour_manual(values=cbPalette) +#' +#' +plot_loo_dif <- + function(y, + psis_object_1, + psis_object_2, + ..., + group = FALSE, + outlier_thresh = FALSE, + size = 1, + alpha = 1, + jitter = 0, + quantiles = FALSE, + sortByGroup = FALSE + ){ + + # Adding a 0 at the end lets users provide a single number as input. + # In this case, only horizontal jitter is applied. + jitter <- c(jitter, 0) + + elpdDif <- psis_object_1$pointwise[, "elpd_loo"] - + psis_object_2$pointwise[, "elpd_loo"] + + + if (quantiles){ + # If quantiles is set to true, replace all y values with their quantile + y <- ecdf(y)(y) + } + + + if (sortByGroup){ + if (identical(group, FALSE) || !identical(y, 1:length(y))){ + stop("ERROR: sortByGroup should only be used for grouping categorical + variables, then plotting them with an arbitrary index. You can + create such an index using `1:length(data)`. + ") + } + + values <- group_by(tibble(group, elpdDif), factor(group)) %>% + arrange(.by_group = TRUE) + + elpdDif <- pull(values, elpdDif) + group <- pull(values, group) + + } + + + plot <- ggplot(mapping=aes(y, elpdDif)) + + geom_hline(yintercept=0) + + xlab(ifelse(sortByGroup, "y", "Index")) + + ylab(expression(ELPD[i][1] - ELPD[i][2])) + + labs(color = "Groups") + + + + if (identical(group, FALSE)){ + # Don't color by group if no groups are passed + plot <- plot + + geom_jitter(width = jitter[1], height = jitter[2], + alpha = alpha, size = size + ) + } + else{ + # If group is passed, use color + plot <- plot + + geom_jitter(aes(color = factor(group)), + width = jitter[1], height = jitter[2], + alpha = alpha, size = size + ) + } + + if (!identical(outlier_thresh, FALSE)){ + # Flag outliers + is_outlier <- elpdDif > outlier_thresh + index <- 1:length(y) + outlier_labs <- index[is_outlier] + + plot <- plot + annotate("text", + x = y[is_outlier], + y = elpdDif[outlier_labs], + label = outlier_labs, + size = 4 + ) + + + } + + return(plot) + } + From 8786be39692e796c34d48d1a987ecbff753bea6a Mon Sep 17 00:00:00 2001 From: Closed-Limelike-Curves Date: Fri, 28 May 2021 10:32:06 -0700 Subject: [PATCH 2/9] typo --- R/loo_variation_plot.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/loo_variation_plot.R b/R/loo_variation_plot.R index 6ae56916..98d9fd5f 100644 --- a/R/loo_variation_plot.R +++ b/R/loo_variation_plot.R @@ -1,7 +1,7 @@ #' Compare models across domains #' -#' The LOO variation plot shows how the predictive accuracy of two different -#' models changes as the predictor is varied. This can is useful for identifying +#' The LOO difference plot shows how the difference in the ELPD of two different +#' models changes when a predictor is varied. This can is useful for identifying #' opportunities for model stacking or expansion. #' #' @param y A vector of observations. See Details. @@ -61,7 +61,7 @@ #' xlab("Index") + scale_colour_manual(values=cbPalette) #' #' -plot_loo_dif <- +plot_loo_variation <- function(y, psis_object_1, psis_object_2, From 8e329d06efb76c53f977a55afa56c1c62d75d037 Mon Sep 17 00:00:00 2001 From: Closed-Limelike-Curves Date: Fri, 28 May 2021 12:34:33 -0700 Subject: [PATCH 3/9] Typo --- R/loo_difference_plot.R | 151 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 R/loo_difference_plot.R diff --git a/R/loo_difference_plot.R b/R/loo_difference_plot.R new file mode 100644 index 00000000..8f2ba6f5 --- /dev/null +++ b/R/loo_difference_plot.R @@ -0,0 +1,151 @@ +#' Compare models across domains +#' +#' The LOO difference plot shows how the ELPD of two different models +#' changes when a predictor is varied. This can is useful for identifying +#' opportunities for model stacking or expansion. +#' +#' @param y A vector of observations. See Details. +#' @param psis_object_1,psis_object_2 If using loo version 2.0.0 or greater, +#' an object returned by the `[loo::psis()]` function (or by the +#' `[loo::loo()]` function with argument `save_psis` set to `TRUE`). +#' @param ... Currently unused. +#' @param group A grouping variable (a vector or factor) the same length +#' as `y`. Each value in group is interpreted as the group level pertaining +#' to the corresponding value of `y`. If `FALSE`, ignored. +#' @param size,alpha,jitter Passed to `[ggplot2::geom_point()]` to control +#' aesthetics. `size` and `alpha` are passed to to the `size` and `alpha` +#' arguments of `[ggplot2::geom_jitter()]` to control the appearance of +#' points. `jitter` can be either a number or a vector of numbers. +#' Passing a single number will jitter variables along the x axis only, while +#' passing a vector will jitter along both axes. +#' @param quantiles Boolean that determines whether to plot the quantiles of +#' `y` rather than `y` itself. Useful when `y` has a very irregular +#' distribution. +#' @param sortByGroup Sort observations by `group`, then plot against an +#' arbitrary index. Plotting by index can be useful when categories have +#' very different sample sizes. +#' +#' +#' @template return-ggplot +#' +#' @template reference-vis-paper +#' +#' @examples +#' +#' library(loo) +#' +#' cbPalette <- c("#636363", "#E69F00", "#56B4E9", "#009E73", +#' "#F0E442", "#0072B2","#CC79A7") +#' +#' # Plot using groups from WHO +#' +#' plot_loo_dif(factor(GM@data$super_region_name), loo3, loo2, +#' group = GM@data$super_region_name, alpha = .5, +#' jitter = c(.45, .2) +#' ) + +#' xlab("Region") + scale_colour_manual(values=cbPalette) +#' +#' # Plot using groups identified with clustering +#' +#' plot_loo_dif(factor(GM@data$cluster_region), loo3, loo2, +#' group = GM@data$super_region_name, alpha = .5, +#' jitter = c(.45, .2) +#' ) + +#' xlab("Cluster Group") + scale_colour_manual(values=cbPalette) +#' +#' # Plot using an index variable to reduce crowding +#' +#' plot_loo_dif(1:2980, loo3, loo2, group = GM@data$super_region_name, +#' alpha = .5, sortByGroup = TRUE, +#' ) + +#' xlab("Index") + scale_colour_manual(values=cbPalette) +#' +#' +plot_loo_variation <- + function(y, + psis_object_1, + psis_object_2, + ..., + group = FALSE, + outlier_thresh = FALSE, + size = 1, + alpha = 1, + jitter = 0, + quantiles = FALSE, + sortByGroup = FALSE + ){ + + # Adding a 0 at the end lets users provide a single number as input. + # In this case, only horizontal jitter is applied. + jitter <- c(jitter, 0) + + elpdDif <- psis_object_1$pointwise[, "elpd_loo"] - + psis_object_2$pointwise[, "elpd_loo"] + + + if (quantiles){ + # If quantiles is set to true, replace all y values with their quantile + y <- ecdf(y)(y) + } + + + if (sortByGroup){ + if (identical(group, FALSE) || !identical(y, 1:length(y))){ + stop("ERROR: sortByGroup should only be used for grouping categorical + variables, then plotting them with an arbitrary index. You can + create such an index using `1:length(data)`. + ") + } + + values <- group_by(tibble(group, elpdDif), factor(group)) %>% + arrange(.by_group = TRUE) + + elpdDif <- pull(values, elpdDif) + group <- pull(values, group) + + } + + + plot <- ggplot(mapping=aes(y, elpdDif)) + + geom_hline(yintercept=0) + + xlab(ifelse(sortByGroup, "y", "Index")) + + ylab(expression(ELPD[i][1] - ELPD[i][2])) + + labs(color = "Groups") + + + + if (identical(group, FALSE)){ + # Don't color by group if no groups are passed + plot <- plot + + geom_jitter(width = jitter[1], height = jitter[2], + alpha = alpha, size = size + ) + } + else{ + # If group is passed, use color + plot <- plot + + geom_jitter(aes(color = factor(group)), + width = jitter[1], height = jitter[2], + alpha = alpha, size = size + ) + } + + if (!identical(outlier_thresh, FALSE)){ + # Flag outliers + is_outlier <- elpdDif > outlier_thresh + index <- 1:length(y) + outlier_labs <- index[is_outlier] + + plot <- plot + annotate("text", + x = y[is_outlier], + y = elpdDif[outlier_labs], + label = outlier_labs, + size = 4 + ) + + + } + + return(plot) + } + From 90ecb40c25919c69a9693780fbcce433df1b2113 Mon Sep 17 00:00:00 2001 From: Closed-Limelike-Curves Date: Fri, 28 May 2021 12:35:16 -0700 Subject: [PATCH 4/9] Rename file --- R/loo_variation_plot.R | 151 ----------------------------------------- 1 file changed, 151 deletions(-) delete mode 100644 R/loo_variation_plot.R diff --git a/R/loo_variation_plot.R b/R/loo_variation_plot.R deleted file mode 100644 index 98d9fd5f..00000000 --- a/R/loo_variation_plot.R +++ /dev/null @@ -1,151 +0,0 @@ -#' Compare models across domains -#' -#' The LOO difference plot shows how the difference in the ELPD of two different -#' models changes when a predictor is varied. This can is useful for identifying -#' opportunities for model stacking or expansion. -#' -#' @param y A vector of observations. See Details. -#' @param psis_object_1,psis_object_2 If using loo version 2.0.0 or greater, -#' an object returned by the `[loo::psis()]` function (or by the -#' `[loo::loo()]` function with argument `save_psis` set to `TRUE`). -#' @param ... Currently unused. -#' @param group A grouping variable (a vector or factor) the same length -#' as `y`. Each value in group is interpreted as the group level pertaining -#' to the corresponding value of `y`. If `FALSE`, ignored. -#' @param size,alpha,jitter Passed to `[ggplot2::geom_point()]` to control -#' aesthetics. `size` and `alpha` are passed to to the `size` and `alpha` -#' arguments of `[ggplot2::geom_jitter()]` to control the appearance of -#' points. `jitter` can be either a number or a vector of numbers. -#' Passing a single number will jitter variables along the x axis only, while -#' passing a vector will jitter along both axes. -#' @param quantiles Boolean that determines whether to plot the quantiles of -#' `y` rather than `y` itself. Useful when `y` has a very irregular -#' distribution. -#' @param sortByGroup Sort observations by `group`, then plot against an -#' arbitrary index. Plotting by index can be useful when categories have -#' very different sample sizes. -#' -#' -#' @template return-ggplot -#' -#' @template reference-vis-paper -#' -#' @examples -#' -#' library(loo) -#' -#' cbPalette <- c("#636363", "#E69F00", "#56B4E9", "#009E73", -#' "#F0E442", "#0072B2","#CC79A7") -#' -#' # Plot using groups from WHO -#' -#' plot_loo_dif(factor(GM@data$super_region_name), loo3, loo2, -#' group = GM@data$super_region_name, alpha = .5, -#' jitter = c(.45, .2) -#' ) + -#' xlab("Region") + scale_colour_manual(values=cbPalette) -#' -#' # Plot using groups identified with clustering -#' -#' plot_loo_dif(factor(GM@data$cluster_region), loo3, loo2, -#' group = GM@data$super_region_name, alpha = .5, -#' jitter = c(.45, .2) -#' ) + -#' xlab("Cluster Group") + scale_colour_manual(values=cbPalette) -#' -#' # Plot using an index variable to reduce crowding -#' -#' plot_loo_dif(1:2980, loo3, loo2, group = GM@data$super_region_name, -#' alpha = .5, sortByGroup = TRUE, -#' ) + -#' xlab("Index") + scale_colour_manual(values=cbPalette) -#' -#' -plot_loo_variation <- - function(y, - psis_object_1, - psis_object_2, - ..., - group = FALSE, - outlier_thresh = FALSE, - size = 1, - alpha = 1, - jitter = 0, - quantiles = FALSE, - sortByGroup = FALSE - ){ - - # Adding a 0 at the end lets users provide a single number as input. - # In this case, only horizontal jitter is applied. - jitter <- c(jitter, 0) - - elpdDif <- psis_object_1$pointwise[, "elpd_loo"] - - psis_object_2$pointwise[, "elpd_loo"] - - - if (quantiles){ - # If quantiles is set to true, replace all y values with their quantile - y <- ecdf(y)(y) - } - - - if (sortByGroup){ - if (identical(group, FALSE) || !identical(y, 1:length(y))){ - stop("ERROR: sortByGroup should only be used for grouping categorical - variables, then plotting them with an arbitrary index. You can - create such an index using `1:length(data)`. - ") - } - - values <- group_by(tibble(group, elpdDif), factor(group)) %>% - arrange(.by_group = TRUE) - - elpdDif <- pull(values, elpdDif) - group <- pull(values, group) - - } - - - plot <- ggplot(mapping=aes(y, elpdDif)) + - geom_hline(yintercept=0) + - xlab(ifelse(sortByGroup, "y", "Index")) + - ylab(expression(ELPD[i][1] - ELPD[i][2])) + - labs(color = "Groups") - - - - if (identical(group, FALSE)){ - # Don't color by group if no groups are passed - plot <- plot + - geom_jitter(width = jitter[1], height = jitter[2], - alpha = alpha, size = size - ) - } - else{ - # If group is passed, use color - plot <- plot + - geom_jitter(aes(color = factor(group)), - width = jitter[1], height = jitter[2], - alpha = alpha, size = size - ) - } - - if (!identical(outlier_thresh, FALSE)){ - # Flag outliers - is_outlier <- elpdDif > outlier_thresh - index <- 1:length(y) - outlier_labs <- index[is_outlier] - - plot <- plot + annotate("text", - x = y[is_outlier], - y = elpdDif[outlier_labs], - label = outlier_labs, - size = 4 - ) - - - } - - return(plot) - } - From 48b97b61dd5fa47ccf72dbac71595afbd8ecc6e3 Mon Sep 17 00:00:00 2001 From: Closed-Limelike-Curves Date: Fri, 28 May 2021 15:00:03 -0700 Subject: [PATCH 5/9] Made recommended changes --- R/loo_difference_plot.R | 66 ++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/R/loo_difference_plot.R b/R/loo_difference_plot.R index 8f2ba6f5..8d3bc6cb 100644 --- a/R/loo_difference_plot.R +++ b/R/loo_difference_plot.R @@ -12,6 +12,8 @@ #' @param group A grouping variable (a vector or factor) the same length #' as `y`. Each value in group is interpreted as the group level pertaining #' to the corresponding value of `y`. If `FALSE`, ignored. +#' @param outlier_thresh Flag values when the difference in the ELPD exceeds +#' this threshold. Defaults to `NULL`, in which case no values are flagged. #' @param size,alpha,jitter Passed to `[ggplot2::geom_point()]` to control #' aesthetics. `size` and `alpha` are passed to to the `size` and `alpha` #' arguments of `[ggplot2::geom_jitter()]` to control the appearance of @@ -21,7 +23,7 @@ #' @param quantiles Boolean that determines whether to plot the quantiles of #' `y` rather than `y` itself. Useful when `y` has a very irregular #' distribution. -#' @param sortByGroup Sort observations by `group`, then plot against an +#' @param sort_by_group Sort observations by `group`, then plot against an #' arbitrary index. Plotting by index can be useful when categories have #' very different sample sizes. #' @@ -56,23 +58,23 @@ #' # Plot using an index variable to reduce crowding #' #' plot_loo_dif(1:2980, loo3, loo2, group = GM@data$super_region_name, -#' alpha = .5, sortByGroup = TRUE, +#' alpha = .5, sort_by_group = TRUE, #' ) + #' xlab("Index") + scale_colour_manual(values=cbPalette) #' #' -plot_loo_variation <- +plot_loo_dif <- function(y, psis_object_1, psis_object_2, ..., - group = FALSE, - outlier_thresh = FALSE, + group = NULL, + outlier_thresh = NULL, size = 1, alpha = 1, jitter = 0, quantiles = FALSE, - sortByGroup = FALSE + sort_by_group = FALSE ){ # Adding a 0 at the end lets users provide a single number as input. @@ -89,59 +91,57 @@ plot_loo_variation <- } - if (sortByGroup){ - if (identical(group, FALSE) || !identical(y, 1:length(y))){ - stop("ERROR: sortByGroup should only be used for grouping categorical + if (sort_by_group){ + if (identical(group, NULL) || !identical(y, 1:length(y))){ + stop("ERROR: sort_by_group should only be used for grouping categorical variables, then plotting them with an arbitrary index. You can create such an index using `1:length(data)`. ") } - values <- group_by(tibble(group, elpdDif), factor(group)) %>% - arrange(.by_group = TRUE) - - elpdDif <- pull(values, elpdDif) - group <- pull(values, group) + ordering <- order(group) + elpdDif <- elpdDif[ordering] + group <- group[ordering] } - plot <- ggplot(mapping=aes(y, elpdDif)) + - geom_hline(yintercept=0) + - xlab(ifelse(sortByGroup, "y", "Index")) + - ylab(expression(ELPD[i][1] - ELPD[i][2])) + - labs(color = "Groups") + plot <- ggplot2::ggplot(mapping=aes(y, elpdDif)) + + ggplot2::geom_hline(yintercept=0) + + ggplot2::xlab(ifelse(sort_by_group, "y", "Index")) + + ggplot2::ylab(expression(ELPD[i][1] - ELPD[i][2])) + + ggplot2::labs(color = "Groups") if (identical(group, FALSE)){ # Don't color by group if no groups are passed plot <- plot + - geom_jitter(width = jitter[1], height = jitter[2], - alpha = alpha, size = size - ) + ggplot2::geom_jitter(width = jitter[1], height = jitter[2], + alpha = alpha, size = size + ) } else{ # If group is passed, use color plot <- plot + - geom_jitter(aes(color = factor(group)), - width = jitter[1], height = jitter[2], - alpha = alpha, size = size - ) + ggplot2::geom_jitter(aes(color = factor(group)), + width = jitter[1], height = jitter[2], + alpha = alpha, size = size + ) } - if (!identical(outlier_thresh, FALSE)){ + if (!identical(outlier_thresh, NULL)){ # Flag outliers is_outlier <- elpdDif > outlier_thresh index <- 1:length(y) outlier_labs <- index[is_outlier] - plot <- plot + annotate("text", - x = y[is_outlier], - y = elpdDif[outlier_labs], - label = outlier_labs, - size = 4 - ) + plot <- plot + ggplot2::annotate("text", + x = y[is_outlier], + y = elpdDif[outlier_labs], + label = outlier_labs, + size = 4 + ) } From 5399cb8ccd92e5ddb8e76c3e2aeed6c6c2d93354 Mon Sep 17 00:00:00 2001 From: Closed-Limelike-Curves Date: Sun, 30 May 2021 21:28:19 -0700 Subject: [PATCH 6/9] Added continuous example, removed quantile option --- R/loo_difference_plot.R | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/R/loo_difference_plot.R b/R/loo_difference_plot.R index 8d3bc6cb..119a8be1 100644 --- a/R/loo_difference_plot.R +++ b/R/loo_difference_plot.R @@ -20,9 +20,6 @@ #' points. `jitter` can be either a number or a vector of numbers. #' Passing a single number will jitter variables along the x axis only, while #' passing a vector will jitter along both axes. -#' @param quantiles Boolean that determines whether to plot the quantiles of -#' `y` rather than `y` itself. Useful when `y` has a very irregular -#' distribution. #' @param sort_by_group Sort observations by `group`, then plot against an #' arbitrary index. Plotting by index can be useful when categories have #' very different sample sizes. @@ -73,7 +70,6 @@ plot_loo_dif <- size = 1, alpha = 1, jitter = 0, - quantiles = FALSE, sort_by_group = FALSE ){ @@ -83,12 +79,6 @@ plot_loo_dif <- elpdDif <- psis_object_1$pointwise[, "elpd_loo"] - psis_object_2$pointwise[, "elpd_loo"] - - - if (quantiles){ - # If quantiles is set to true, replace all y values with their quantile - y <- ecdf(y)(y) - } if (sort_by_group){ From 4d085d61e698d10adefe348537a8eae3f56fe54a Mon Sep 17 00:00:00 2001 From: Closed-Limelike-Curves Date: Mon, 31 May 2021 09:54:27 -0700 Subject: [PATCH 7/9] Fixed error in example --- R/loo_difference_plot.R | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/R/loo_difference_plot.R b/R/loo_difference_plot.R index 119a8be1..9cdf49a0 100644 --- a/R/loo_difference_plot.R +++ b/R/loo_difference_plot.R @@ -58,8 +58,45 @@ #' alpha = .5, sort_by_group = TRUE, #' ) + #' xlab("Index") + scale_colour_manual(values=cbPalette) +#' +#' cbPalette <- c("#636363", "#E69F00", "#56B4E9", "#009E73", +#' "#F0E442", "#0072B2","#CC79A7") +#' +#' options(mc.cores = parallel::detectCores()) +#' options(loo.cores = parallel::detectCores()) +#' +#' data(kidiq) +#' +#' t_prior <- student_t(df = 10, location = 0, scale = .5) +#' coef_prior <- student_t(df = 10, location = .5, scale = .25) +#' kidiq$kid_std <- (kidiq$kid_score - 100) / 15 +#' kidiq$mom_std <- (kidiq$mom_iq - 100) / 15 +#' kidiq$age_std <- (kidiq$mom_age - mean(kidiq$mom_age)) / sd(kidiq$mom_age) +#' kidiq$hs_cent <- kidiq$mom_hs - mean(kidiq$mom_hs) +#' +#' coFit <- stan_glm(kid_std ~ hs_cent, data = kidiq, +#' family = gaussian(), prior = coef_prior, +#' prior_intercept = t_prior, +#' seed = 1776, chains = 2 +#' ) +#' iqFit <- stan_glm(kid_std ~ mom_std + hs_cent, data = kidiq, +#' family = gaussian(), +#' prior = coef_prior, prior_intercept = t_prior, +#' seed = 1776, chains = 2 +#' ) +#' +#' +#' coLoo <- loo(iqFit, save_psis = TRUE) +#' iqLoo <- loo(coFit, save_psis = TRUE) +#' +#' +#' plot_loo_dif(kidiq$mom_iq, coLoo, iqLoo, group = kidiq$mom_hs, +#' alpha = .5, jitter = c(.1, .1) +#' ) + ggplot2::geom_smooth() + +#' ggplot2::xlab("IQ of Mother") + +#' ggplot2::scale_colour_manual(values=cbPalette) #' -#' + plot_loo_dif <- function(y, psis_object_1, From d4b86415dbb5279f020850b2de4cef32502cb4b2 Mon Sep 17 00:00:00 2001 From: Closed-Limelike-Curves Date: Mon, 31 May 2021 09:55:22 -0700 Subject: [PATCH 8/9] Typo --- R/loo_difference_plot.R | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/R/loo_difference_plot.R b/R/loo_difference_plot.R index 9cdf49a0..557e3d4a 100644 --- a/R/loo_difference_plot.R +++ b/R/loo_difference_plot.R @@ -59,11 +59,8 @@ #' ) + #' xlab("Index") + scale_colour_manual(values=cbPalette) #' -#' cbPalette <- c("#636363", "#E69F00", "#56B4E9", "#009E73", -#' "#F0E442", "#0072B2","#CC79A7") -#' -#' options(mc.cores = parallel::detectCores()) -#' options(loo.cores = parallel::detectCores()) +#' +#' # Example using kid IQ Dataset with a continuous predictor #' #' data(kidiq) #' From a0417dda24128c6a36cf87c1e50d0a97befaedf4 Mon Sep 17 00:00:00 2001 From: Closed-Limelike-Curves Date: Thu, 3 Jun 2021 10:07:56 -0700 Subject: [PATCH 9/9] Typo/formatting --- R/loo_difference_plot.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/loo_difference_plot.R b/R/loo_difference_plot.R index 557e3d4a..78cba763 100644 --- a/R/loo_difference_plot.R +++ b/R/loo_difference_plot.R @@ -89,7 +89,8 @@ #' #' plot_loo_dif(kidiq$mom_iq, coLoo, iqLoo, group = kidiq$mom_hs, #' alpha = .5, jitter = c(.1, .1) -#' ) + ggplot2::geom_smooth() + +#' ) + +#' ggplot2::geom_smooth() + #' ggplot2::xlab("IQ of Mother") + #' ggplot2::scale_colour_manual(values=cbPalette) #'