View source: R/model_helpers.R
| prepare_jsd_beta | R Documentation |
JSD lives in [0,1]. This helper adds a jsd_beta column bounded in
(0,1) so it can be used with the Beta family (e.g., in mgcv).
prepare_jsd_beta(jsd_df, jsd_col = "jsd_mean", eps = 1e-06)
jsd_df |
Data frame containing a JSD column. |
jsd_col |
String: name of the JSD column (default "jsd_mean"). |
eps |
Small constant used to bound JSD away from 0 and 1. |
A modified data frame with an added jsd_beta column.
jsd_by_speaker <- data.frame(
speaker = paste0("s", 1:8),
age = c(18, 22, 27, 31, 38, 45, 52, 60),
jsd_mean = c(0.02, 0.05, 0.08, 0.13, 0.18, 0.24, 0.31, 0.39)
)
model_data <- prepare_jsd_beta(jsd_by_speaker)
model_data
if (requireNamespace("mgcv", quietly = TRUE)) {
fit <- mgcv::gam(
jsd_beta ~ age,
data = model_data,
family = mgcv::betar(),
method = "REML"
)
stats::predict(fit, type = "response")
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.