prepare_jsd_beta: Prepare JSD estimates for beta regression / GAMs

View source: R/model_helpers.R

prepare_jsd_betaR Documentation

Prepare JSD estimates for beta regression / GAMs

Description

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).

Usage

prepare_jsd_beta(jsd_df, jsd_col = "jsd_mean", eps = 1e-06)

Arguments

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.

Value

A modified data frame with an added jsd_beta column.

Examples

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")
}

phontrast documentation built on Oct. 7, 2026, 5:06 p.m.