Package {WMFM}


Title: Explore Fitted Linear and Generalised Linear Models with 'shiny'
Version: 1.0.4
Description: Provides a 'shiny' application that helps learners connect regression tables to fitted generalised linear models. Users construct models via drag-and-drop controls, obtain fitted equations and plain-language explanations generated by a large language model, and can view plots of the fitted model in settings with a single continuous covariate.
License: GPL (≥ 3)
Encoding: UTF-8
URL: https://github.com/jmcurran/WMFM
BugReports: https://github.com/jmcurran/WMFM/issues
Depends: R (≥ 4.1.0)
Imports: bslib, ellmer, ggplot2, ggrepel, glue, grDevices, htmltools, jsonlite, patchwork, rlang, s20x, sandwich, scales, shiny, sodium, sortable, tibble, utils, yaml
Suggests: clipr, devtools, rstudioapi, testthat (≥ 3.0.0), withr
Config/testthat/edition: 3
Config/roxygen2/version: 8.0.0
RoxygenNote: 7.3.3
NeedsCompilation: no
Packaged: 2026-06-21 21:50:38 UTC; james
Author: James Curran [aut, cre]
Maintainer: James Curran <j.curran@auckland.ac.nz>
Repository: CRAN
Date/Publication: 2026-07-04 08:10:06 UTC

Environment for caching LLM results

Description

Internal cache for equations and explanations from fitted models.

Usage

.env_cache

Format

An object of class environment of length 0.


Add a derived variable to a data frame from a single assignment line

Description

Validates and evaluates a single assignment statement such as t = 1:nrow(data) or month = factor(rep(1:12, 12)). The RHS is evaluated in a safe environment created by makeSafeEvalEnv(), so only the data columns plus a small allowlist of base functions are available.

Usage

addDerivedVariableToData(data, txt, allowOverwrite = FALSE)

Arguments

data

A data frame to modify.

txt

A length-1 character string containing one assignment statement.

allowOverwrite

Logical; if FALSE (default), refuse to overwrite an existing column.

Details

The derived variable is appended to the data frame as a new column. Scalars are recycled to the number of rows; otherwise the result must have length nrow(data).

Value

A list with elements:

Examples

df = data.frame(passengers = 1:144)
res = addDerivedVariableToData(df, "t = 1:nrow(data)")
res$ok
names(res$data)

res2 = addDerivedVariableToData(res$data, "month = factor(rep(1:12, 12))")
table(res2$data$month)


Add the two-by-two interaction contrast for a factor-by-factor model

Description

Add the two-by-two interaction contrast for a factor-by-factor model

Usage

addFactorByFactorDifferenceOfDifferencesRow(
  model,
  mf,
  level,
  firstFactor,
  secondFactor,
  appendRow
)

Arguments

model

A fitted model object.

mf

Model frame.

level

Confidence level.

firstFactor

First factor name.

secondFactor

Second factor name.

appendRow

Row appender closure.

Value

Invisibly returns NULL.


Add simple factor-difference rows within levels of another factor

Description

Add simple factor-difference rows within levels of another factor

Usage

addFactorByFactorSimpleDifferenceRows(
  model,
  mf,
  level,
  focalFactor,
  conditioningFactor,
  appendRow
)

Arguments

model

A fitted model object.

mf

Model frame.

level

Confidence level.

focalFactor

Factor whose levels are being compared.

conditioningFactor

Factor level held fixed.

appendRow

Row appender closure.

Value

Invisibly returns NULL.


Add fitted-quantity CI rows for a single predictor setting

Description

Add fitted-quantity CI rows for a single predictor setting

Usage

addFittedQuantityRows(
  model,
  mf,
  familyObj,
  level,
  newData,
  labelContext,
  settings,
  numericReference,
  appendRow
)

Arguments

model

A fitted model object.

mf

Model frame.

familyObj

Optional GLM family object.

level

Confidence level.

newData

One-row new-data frame.

labelContext

Context used to build row labels.

settings

Human-readable settings text.

numericReference

Numeric reference choice used when completing any omitted numeric predictors in newData.

appendRow

Row appender closure.

Value

Invisibly returns NULL.


Add a response-scale factor difference row for a linear model

Description

Add a response-scale factor difference row for a linear model

Usage

addLinearFactorDifferenceRow(
  model,
  mf,
  level,
  referenceData,
  comparisonData,
  focalFactor,
  referenceLevel,
  comparisonLevel,
  contextText,
  appendRow
)

Arguments

model

A fitted model object.

mf

Model frame.

level

Confidence level.

referenceData

New data for the reference level.

comparisonData

New data for the comparison level.

focalFactor

Factor being compared.

referenceLevel

Reference factor level.

comparisonLevel

Comparison factor level.

contextText

Additional setting context.

appendRow

Row appender closure.

Value

Invisibly returns NULL.


Add a response-scale difference row for a two-level linear factor

Description

Adds the direct factor comparison for a two-level linear model without interactions. The fitted-value rows remain available, while this effect row gives the student-facing difference at the same reference settings.

Usage

addLinearTwoLevelFactorComparisonRow(
  model,
  mf,
  level,
  baseInfo,
  factorName,
  appendRow
)

Arguments

model

A fitted model object.

mf

Model frame.

level

Confidence level.

baseInfo

Base-setting information.

factorName

Name of the two-level factor predictor.

appendRow

Row appender closure.

Value

Invisibly returns NULL.


Add conditional odds-ratio rows within levels of another factor

Description

Add conditional odds-ratio rows within levels of another factor

Usage

addLogisticFactorByFactorConditionalOddsRatioRows(
  model,
  mf,
  level,
  focalFactor,
  conditioningFactor,
  appendRow
)

Arguments

model

A fitted logistic model.

mf

Model frame.

level

Confidence level.

focalFactor

Factor whose levels are being compared.

conditioningFactor

Factor level held fixed.

appendRow

Row appender closure.

Value

Invisibly returns NULL.


Add the two-by-two ratio-of-odds-ratios row for a logistic interaction

Description

Add the two-by-two ratio-of-odds-ratios row for a logistic interaction

Usage

addLogisticFactorByFactorRatioOfOddsRatiosRow(
  model,
  mf,
  level,
  firstFactor,
  secondFactor,
  appendRow
)

Arguments

model

A fitted logistic model.

mf

Model frame.

level

Confidence level.

firstFactor

First factor name.

secondFactor

Second factor name.

appendRow

Row appender closure.

Value

Invisibly returns NULL.


Add an odds-ratio row for a two-level logistic factor comparison

Description

Adds a direct factor-comparison row for two-level binomial-logit models. Fitted values remain available on the probability scale, while this row gives the direct odds-ratio comparison needed to answer factor-comparison questions without reasoning from separate raw group odds or interval overlap.

Usage

addLogisticTwoLevelFactorComparisonRow(
  model,
  mf,
  familyObj,
  level,
  baseInfo,
  factorName,
  appendRow
)

Arguments

model

A fitted model object.

mf

Model frame.

familyObj

Optional GLM family object.

level

Confidence level.

baseInfo

Base-setting information.

factorName

Name of the two-level factor predictor.

appendRow

Row appender closure.

Value

Invisibly returns NULL.


Add a numeric-effect CI row

Description

Add a numeric-effect CI row

Usage

addNumericEffectRow(
  model,
  mf,
  familyObj,
  level,
  weights,
  numericName,
  factorLevelText,
  appendRow
)

Arguments

model

A fitted model object.

mf

Model frame.

familyObj

Optional GLM family object.

level

Confidence level.

weights

Named coefficient weights for the linear combination.

numericName

Name of the numeric predictor.

factorLevelText

Optional factor-level context.

appendRow

Row appender closure.

Value

Invisibly returns NULL.


Application server logic

Description

Defines the server-side logic for the Model Builder app. Handles data upload, variable assignment via buckets, model fitting, calls to the language model for fitted equations and explanations, and plotting of the fitted model when appropriate.

Usage

appServer(input, output, session)

Arguments

input

Shiny input object.

output

Shiny output object.

session

Shiny session object.

Value

No return value; called for its side effects.


Application user interface

Description

Constructs the Shiny user interface for the Model Builder app.

Usage

appUI()

Details

The interface is organised into the main teaching and analysis tabs:

Value

A Shiny UI definition created with fluidPage().


Build a pure LLM score record from parsed scores

Description

Validates a parsed LLM scoring response and returns a score record containing only judged fields, score summaries, and LLM scoring metadata.

Usage

applyWmfmLlmScoresToRecord(
  parsedScores,
  modelName = NA_character_,
  rawResponse = NA_character_
)

Arguments

parsedScores

Named list produced by parseWmfmScoringJson().

modelName

Optional character identifier for the scoring model.

rawResponse

Raw character response returned by the LLM.

Value

Named list containing only scoring fields.


Build simple arithmetic transformation information

Description

Build simple arithmetic transformation information

Usage

arithmeticTransformationInfo(funName, constant, variablePosition)

Arguments

funName

Character arithmetic operator.

constant

Numeric constant.

variablePosition

Character position of the data variable.

Value

Transformation information.


Coerce a WMFM scores object to a data frame

Description

Flattens a wmfmScores object into a long or wide data frame for analysis, plotting, and comparison.

Usage

## S3 method for class 'wmfmScores'
as.data.frame(
  x,
  row.names = NULL,
  optional = FALSE,
  format = c("long", "wide"),
  ...
)

Arguments

x

A wmfmScores object.

row.names

Ignored. Included for S3 compatibility.

optional

Ignored. Included for S3 compatibility.

format

Character. One of "long" or "wide".

...

Unused. Included for S3 compatibility.

Value

A data frame.


Attach response-transformation handling metadata to a fitted model

Description

Attach response-transformation handling metadata to a fitted model

Usage

attachResponseTransformationModeToModel(
  model,
  responseTransformationMode = "both"
)

Arguments

model

A fitted model object.

responseTransformationMode

Character scalar requested mode.

Value

The fitted model with a wmfm_response_transformation_mode attribute.


Attach derived-variable transformation metadata to a fitted model

Description

Attach derived-variable transformation metadata to a fitted model

Usage

attachVariableTransformationsToModel(
  model,
  formula,
  variableTransformations = NULL
)

Arguments

model

A fitted model object.

formula

A model formula.

variableTransformations

A list of transformation records, or NULL.

Value

The fitted model with a wmfm_variable_transformations attribute.


Audit whether bad explanations are being penalised by the current rubric

Description

Builds a compact audit summary around a set of already graded bad explanations, with optional comparison against a graded good explanation. This is intended as a lightweight helper for diagnosing adversarial or deliberately flawed explanations that may be slipping through the current deterministic rubric.

Usage

auditBadExplanationGrading(
  x,
  goodGrade = NULL,
  method = c("deterministic", "llm"),
  minExpectedDrop = 1,
  flaggedThreshold = 9,
  expectedMetrics = NULL,
  ...
)

Arguments

x

A wmfmGradeListObj containing graded bad explanations.

goodGrade

Optional wmfmGrade object for a reference good explanation.

method

Character scalar. Grading method to audit. One of "deterministic" or "llm".

minExpectedDrop

Numeric scalar. Minimum drop in mark, relative to the good explanation, required before an explanation is treated as clearly penalised.

flaggedThreshold

Numeric scalar. Any explanation with a mark greater than or equal to this threshold is flagged.

expectedMetrics

Optional named list. Each element name should match an explanation name in x, and each element value should be a character vector of metric names that you expected to lose marks.

...

Unused.

Value

An object of class wmfmBadExplanationAudit.

Examples

if (interactive()) {
badGrades = grade(modelObj, explanation = badVec, method = "deterministic")
goodGrade = grade(modelObj, explanation = modelObj$explanation, method = "deterministic")

audit = auditBadExplanationGrading(
  badGrades,
  goodGrade = goodGrade,
  expectedMetrics = list(
    effectDirectionError = c("factualScore"),
    wrongScaleError = c("factualScore", "clarityScore"),
    rSquaredOverclaim = c("factualScore", "calibrationScore"),
    logicalContradiction = c("factualScore", "clarityScore")
  )
)

print(audit)
}

Back-transform one transformed-scale difference row

Description

Back-transform one transformed-scale difference row

Usage

backTransformResponseDifferenceRow(row, responseRecord)

Arguments

row

One CI table row.

responseRecord

Response transformation record.

Value

One-row data frame or NULL.


Back-transform transformed-scale differences where mathematically safe

Description

Back-transform transformed-scale differences where mathematically safe

Usage

backTransformResponseDifferenceValues(values, inverseType)

Arguments

values

Numeric vector of transformed-scale differences.

inverseType

Character inverse label.

Value

Numeric vector.


Back-transform one fitted-value row

Description

Back-transform one fitted-value row

Usage

backTransformResponseRow(row, responseRecord, rowMeaning)

Arguments

row

One CI table row.

responseRecord

Response transformation record.

rowMeaning

Meaning label for the new row.

Value

One-row data frame or NULL.


Apply an inverse response transformation to fitted values

Description

Apply an inverse response transformation to fitted values

Usage

backTransformResponseValues(values, inverseType, parameters = list())

Arguments

values

Numeric vector on the transformed-response scale.

inverseType

Character inverse label.

parameters

Transformation parameter list.

Value

Numeric vector.


Wrap variable names in backticks for UI display

Description

Wrap variable names in backticks for UI display

Usage

backtickNames(x)

Arguments

x

Character vector.

Value

Character vector.


Build confirm label for add-derived-variable modal.

Description

Build confirm label for add-derived-variable modal.

Usage

buildAddDerivedVariableConfirmLabel()

Value

A character scalar button label.


Build help text for add-derived-variable modal.

Description

Build help text for add-derived-variable modal.

Usage

buildAddDerivedVariableHelpText()

Value

A character scalar help text.


Build placeholder for add-derived-variable expression input.

Description

Build placeholder for add-derived-variable expression input.

Usage

buildAddDerivedVariablePlaceholder()

Value

A character scalar placeholder.


Build title for add-derived-variable modal.

Description

Build title for add-derived-variable modal.

Usage

buildAddDerivedVariableTitle()

Value

A character scalar modal title.


Build deterministic explanation scaffold for adjustment workflows

Description

Build deterministic explanation scaffold for adjustment workflows

Usage

buildAdjustmentExplanationScaffold(model, mf = NULL)

Arguments

model

A fitted model object.

mf

Optional model frame.

Value

A character scalar containing a deterministic scaffold, or an empty string when no adjustment variables are selected.


Build sanitized adjustment metadata for a fitted formula

Description

Restricts selected adjustment variables to non-empty predictors present in the fitted formula so downstream prompts and summaries do not receive stale adjustment state after UI invalidations or model-type switches.

Usage

buildAdjustmentMetadata(selectedVariables, formulaPredictors)

Arguments

selectedVariables

Character vector selected in the UI.

formulaPredictors

Character vector of predictor names from the fitted formula.

Value

Character vector of sanitized adjustment-variable metadata.


Build adjustment-aware scoring context text

Description

Build adjustment-aware scoring context text

Usage

buildAdjustmentScoringContextBlock(runRecord, policy = NULL)

Arguments

runRecord

Named run-record list.

policy

Optional output from buildAdjustmentScoringPolicy().

Value

Character scalar containing adjustment scoring context.


Build adjustment-aware scoring policy metadata

Description

Build adjustment-aware scoring policy metadata

Usage

buildAdjustmentScoringPolicy(runRecord)

Arguments

runRecord

Named run-record list.

Value

A list containing normalized role metadata for scoring prompts.


Build adjustment-aware rubric guidance text

Description

Build adjustment-aware rubric guidance text

Usage

buildAdjustmentScoringRubricGuidance()

Value

Character vector of field-specific adjustment scoring guidance lines.


Build adjustment-variable guidance for explanation prompts

Description

Builds a prompt block that separates primary predictors from adjustment variables using Stage 20 adjustment metadata stored on the fitted model. The block instructs downstream explanation generation to interpret primary predictors substantively while mentioning adjustment variables only as adjusted-for controls.

Usage

buildAdjustmentVariablePromptBlock(model, mf = NULL)

Arguments

model

A fitted model object.

mf

Optional model frame.

Value

A character scalar containing adjustment-variable guidance, or an empty string when no adjustment variables are present.


Build explanation-anchor audit metadata

Description

Build explanation-anchor audit metadata

Usage

buildAnchorAuditEntry(anchorInfo)

Arguments

anchorInfo

Anchor metadata from chooseExplanationAnchor().

Value

A named list suitable for audit or developer-feedback use.


Build anchored baseline fitted-value context for explanation prompts

Description

Uses the confidence-interval teaching helpers to compute baseline fitted values at the chosen numeric anchor, so the explanation prompt does not rely on the language model to derive anchored counts, odds, or means from the intercept alone.

Usage

buildAnchoredBaselinePromptBlock(model, mf = NULL, predictorNames = NULL)

Arguments

model

A fitted model object.

mf

Optional model frame.

predictorNames

Optional predictor names.

Value

A character scalar, or an empty string if no suitable anchored baseline summary is available.


Build app-side explanation text for a fitted model

Description

Build app-side explanation text for a fitted model

Usage

buildAppExplanation(model, chatProvider = NULL, useExplanationCache = TRUE)

Arguments

model

A fitted model object, typically of class lm or glm.

chatProvider

Optional chat provider object. Defaults to NULL.

useExplanationCache

Logical. Passed through to lmExplanation() when chat is available. Defaults to TRUE.

Value

A character string containing the generated explanation, or NULL if no explanation could be produced.


Build app-side explanation audit output for a fitted model

Description

Creates the deterministic audit trail used by the transparency panel in the app. This does not depend on an active chat provider.

Usage

buildAppExplanationAudit(model)

Arguments

model

A fitted model object, typically of class lm or glm.

Details

The returned object is expected to match the same contract used by buildModelExplanationAudit() so that later UI and teaching-summary helpers can rely on one stable audit structure.

Value

A wmfmExplanationAudit object or NULL if audit construction fails.


Build app-side equation and explanation outputs for a fitted model

Description

Centralises the logic used by the app after a model has been fitted. Deterministic equations are now the default app output. When explicitly requested, the older LLM equation path can still be used while keeping a deterministic fallback if the LLM equation request fails.

Usage

buildAppModelOutputs(
  model,
  chatProvider = NULL,
  useExplanationCache = TRUE,
  equationMethod = c("deterministic", "llm")
)

Arguments

model

A fitted model object, typically of class lm or glm.

chatProvider

Optional chat provider object. Defaults to NULL.

useExplanationCache

Logical. Passed through to lmExplanation() when chat is available. Defaults to TRUE.

equationMethod

Character string giving the equation engine. Must be one of "deterministic" or "llm". Defaults to "deterministic".

Details

Explanations remain on the LLM path. If no chat provider is available, deterministic equations are still returned and the explanation remains empty.

The explanation audit is always built from the deterministic model-side audit helper rather than from separate app-specific audit logic.

Value

A named list with elements equations, explanation, explanationAudit, and equationMethodUsed.


Build user-facing progress text for fitted-model output generation

Description

Centralises app wording for the post-fit output pipeline so that the UI can reflect deterministic equation generation without using old LLM request language. Explanations may still be generated with a language model when one is available.

Usage

buildAppOutputMessages(
  equationMethod = c("deterministic", "llm"),
  explanationAvailable = FALSE,
  explanationRequested = FALSE
)

Arguments

equationMethod

Character string. One of "deterministic" or "llm".

explanationAvailable

Logical indicating whether a narrative explanation is available.

explanationRequested

Logical indicating whether the app is attempting to generate an explanation.

Value

A named list of character strings for progress and notification text.


Build an optional tutor-style explanation of the explanation

Description

Build an optional tutor-style explanation of the explanation

Usage

buildAppTeachingTutorExplanation(
  teachingSummary,
  chatProvider = NULL,
  modelExplanation = NULL,
  researchQuestion = NULL
)

Arguments

teachingSummary

A wmfmExplanationTeachingSummary object.

chatProvider

A chat provider object with a ⁠$chat()⁠ method.

modelExplanation

Optional character scalar.

researchQuestion

Optional character scalar.

Value

A character string or NULL.


Build message for empty average contrast groups.

Description

Build message for empty average contrast groups.

Usage

buildAverageContrastEmptyGroupMessage()

Value

A character scalar notification message.


Build message for invalid average contrast levels.

Description

Build message for invalid average contrast levels.

Usage

buildAverageContrastInvalidLevelMessage()

Value

A character scalar notification message.


Build message for overlapping average contrast levels.

Description

Build message for overlapping average contrast levels.

Usage

buildAverageContrastOverlappingLevelMessage()

Value

A character scalar notification message.


Build explanation-specific instructions for bad explanation generation

Description

Build explanation-specific instructions for bad explanation generation

Usage

buildBadExplanationInstructionBlock(plan)

Arguments

plan

A plan object produced by buildBadExplanationPlan().

Value

A character scalar.


Build compact model context for bad explanation generation

Description

Build compact model context for bad explanation generation

Usage

buildBadExplanationModelContext(x)

Arguments

x

A wmfmModel object.

Value

A character scalar.


Build a bad explanation generation plan

Description

Build a bad explanation generation plan

Usage

buildBadExplanationPlan(
  x,
  type = "auto",
  severity = "moderate",
  n = 1,
  mixTypes = FALSE
)

Arguments

x

A wmfmModel object.

type

Character vector of bad explanation types, or "auto".

severity

Character scalar.

n

Integer number of explanations to generate.

mixTypes

Logical.

Value

A named list describing the requested generation plan.


Build an LLM prompt for generating bad explanations

Description

Build an LLM prompt for generating bad explanations

Usage

buildBadExplanationPrompt(x, baseExplanation, plan)

Arguments

x

A wmfmModel object.

baseExplanation

Character scalar giving the good explanation.

plan

A plan object produced by buildBadExplanationPlan().

Value

A character scalar containing the prompt text.


Build reference-level context for factor predictors

Description

Build reference-level context for factor predictors

Usage

buildBadExplanationReferenceLevels(x)

Arguments

x

A wmfmModel object.

Value

A character scalar describing factor predictors and their reference levels.


Build textual definitions for supported bad explanation types

Description

Build textual definitions for supported bad explanation types

Usage

buildBadExplanationTypeGuide()

Value

A character scalar.


Build message for a failed chat provider connection.

Description

Build message for a failed chat provider connection.

Usage

buildChatProviderConnectionFailedMessage(details)

Arguments

details

Character scalar error details.

Value

A character scalar notification message.


Build the chat provider set confirmation message

Description

Build the chat provider set confirmation message

Usage

buildChatProviderSetMessage(backend, ollamaModel, ollamaThinkLow)

Arguments

backend

Requested chat backend.

ollamaModel

Active Ollama model name.

ollamaThinkLow

Whether Ollama low-thinking mode is active.

Value

A character string for a notification.


Build the current chat provider status message

Description

Build the current chat provider status message

Usage

buildChatProviderStatus(backend, ollamaModel, ollamaThinkLow)

Arguments

backend

Active chat backend.

ollamaModel

Active Ollama model name.

ollamaThinkLow

Whether Ollama low-thinking mode is active.

Value

A character string for the chat provider status display.


Build message for missing example selection.

Description

Build message for missing example selection.

Usage

buildChooseExampleFirstMessage()

Value

A character scalar notification message.


Build a coefficient-only confidence-interval table

Description

Build a coefficient-only confidence-interval table

Usage

buildCoefficientOnlyConfidenceIntervalData(model, level = 0.95)

Arguments

model

A fitted model object.

level

Confidence level.

Value

A list in the same format as buildModelConfidenceIntervalData().


Build factor-summary rows for comparison control

Description

Build factor-summary rows for comparison control

Usage

buildComparisonControlFactorSummary(mf, predictorTypes)

Arguments

mf

Model frame.

predictorTypes

Predictor-type metadata from buildExplanationModelProfile().

Value

A data frame with one row per factor predictor.


Build comparison-control prompt text

Description

Builds deterministic prompt guidance that limits group or treatment comparisons to the scope implied by the model profile and the user-supplied research question. This keeps explanations from enumerating every pairwise comparison when a concise global summary is more appropriate.

Usage

buildComparisonControlPromptBlock(model, mf = NULL)

Arguments

model

A fitted model object.

mf

Optional model frame.

Value

A character scalar containing comparison-control guidance, or an empty string if no comparison-control guidance is needed.


Build base-setting information for CI summaries

Description

Build base-setting information for CI summaries

Usage

buildConfidenceIntervalBaseInfo(mf, numericReference, predictorNames)

Arguments

mf

Model frame.

numericReference

Numeric reference choice.

predictorNames

Predictor names.

Value

A list with base-row information.


Build CI notation labels for supported models

Description

Build CI notation labels for supported models

Usage

buildConfidenceIntervalNotation(model, mf)

Arguments

model

A fitted model object.

mf

Model frame.

Value

A named list of notation labels.


Build a prediction and CI on the linear predictor scale

Description

Build a prediction and CI on the linear predictor scale

Usage

buildConfidenceIntervalPrediction(
  model,
  newData,
  level,
  numericReference = NULL
)

Arguments

model

A fitted model object.

newData

One-row new-data frame.

level

Confidence level.

numericReference

Numeric reference choice used if newData omits a numeric predictor.

Value

A list with fit, interval bounds, and non-zero weights.


Build a stable sort key for a CI display table

Description

Build a stable sort key for a CI display table

Usage

buildConfidenceIntervalSortKey(ciTable)

Arguments

ciTable

Confidence-interval table with metadata columns.

Value

An integer vector.


Build a newdata grid for factor-only contrasts

Description

Constructs a newData data frame suitable for generating predictions or contrasts that vary one target factor across its levels while holding all other factor predictors constant at user-specified values.

Usage

buildContrastNewData(mf, factorPreds, targetFactor, condValues)

Arguments

mf

A model frame (typically model.frame(m)) that contains the variables referenced by the fitted model.

factorPreds

Character vector of factor predictor names present in mf.

targetFactor

A single string naming the factor predictor to vary.

condValues

Named list (or named vector) giving the conditioning value (level) to hold each non-target factor predictor at. Names should correspond to entries in factorPreds. The targetFactor entry is ignored if present.

Details

The function returns:

Value

A list with elements:

newData

A data frame with one row per level of targetFactor.

targetLevels

A character vector of the target factor levels.


Build message for too few non-zero custom contrast weights.

Description

Build message for too few non-zero custom contrast weights.

Usage

buildCustomContrastTooFewWeightsMessage()

Value

A character scalar notification message.


Build message for non-zero custom contrast weight sums.

Description

Build message for non-zero custom contrast weight sums.

Usage

buildCustomContrastWeightsMustSumToZeroMessage()

Value

A character scalar notification message.


Build message shown after clearing user data context.

Description

Build message shown after clearing user data context.

Usage

buildDataContextClearedMessage()

Value

A character scalar notification message.


Build message shown after saving user data context.

Description

Build message shown after saving user data context.

Usage

buildDataContextSavedMessage()

Value

A character scalar notification message.


Build title for the package data description modal.

Description

Build title for the package data description modal.

Usage

buildDataDescriptionTitle(datasetName = "")

Arguments

datasetName

Character scalar dataset name.

Value

A character scalar modal title.


Build message for a failed delimited file read.

Description

Build message for a failed delimited file read.

Usage

buildDelimitedFileReadFailedMessage()

Value

A character scalar notification message.


Build derived CI output for supported model structures

Description

Build derived CI output for supported model structures

Usage

buildDerivedConfidenceIntervalData(
  model,
  mf,
  level,
  numericReference,
  derivedPlan
)

Arguments

model

A fitted model object.

mf

Model frame.

level

Confidence level.

numericReference

Numeric reference choice.

derivedPlan

Plan from classifyModelConfidenceIntervalPlan().

Value

A list in the same format as buildModelConfidenceIntervalData().


Build the default note for derived CI output

Description

Build the default note for derived CI output

Usage

buildDerivedModeNote(mf, numericReference)

Arguments

mf

Model frame.

numericReference

Numeric reference choice.

Value

A character scalar or NULL.


Build a deterministic equation table from a fitted model

Description

Runs the deterministic equation pipeline by building an equation specification, enumerating teaching cases, and rendering those cases into a tabular output suitable for printing or downstream storage.

Usage

buildDeterministicEquationTable(model, digits = 2)

Arguments

model

A fitted model object, typically of class lm or glm.

digits

Integer number of decimal places for displayed coefficients. Defaults to 2.

Details

The returned table includes a compatibility equation column containing the rendered scales collapsed into one text field, along with separate scale columns for later UI use.

Value

A data.frame with one row per displayed teaching case.


Build the incorrect developer mode password message

Description

Build the incorrect developer mode password message

Usage

buildDeveloperModeIncorrectPasswordMessage()

Value

A character string for the notification.


Build the developer mode locked message

Description

Build the developer mode locked message

Usage

buildDeveloperModeLockedMessage()

Value

A character string for the notification.


Build developer mode status text

Description

Build developer mode status text

Usage

buildDeveloperModeStatus(isUnlocked)

Arguments

isUnlocked

Logical value indicating whether developer mode is currently unlocked.

Value

A character string for the developer mode status display.


Build the developer mode unlock error status text

Description

Build the developer mode unlock error status text

Usage

buildDeveloperModeUnlockErrorStatus(message)

Arguments

message

Character scalar giving the underlying unlock error.

Value

A character string for the developer mode status display.


Build the developer mode unlocked message

Description

Build the developer mode unlocked message

Usage

buildDeveloperModeUnlockedMessage()

Value

A character string for the notification.


Build a compact developer repeated scoring export

Description

Build a compact developer repeated scoring export

Usage

buildDeveloperRepeatedScoringExport(repeatedResult, method = "deterministic")

Arguments

repeatedResult

A developer repeated scoring result object.

method

Character scalar naming the scoring method to inspect.

Value

A list suitable for JSON serialisation.


Build developer repeated scoring run table

Description

Build developer repeated scoring run table

Usage

buildDeveloperRepeatedScoringRunTable(repeatedResult)

Arguments

repeatedResult

A developer repeated scoring result object.

Value

A data frame suitable for renderTable().


Build developer repeated scoring summary table

Description

Build developer repeated scoring summary table

Usage

buildDeveloperRepeatedScoringSummaryTable(repeatedResult)

Arguments

repeatedResult

A developer repeated scoring result object.

Value

A one-row data frame suitable for renderTable().


Build a compact developer scoring grade export

Description

Build a compact developer scoring grade export

Usage

buildDeveloperScoringGradeExport(gradeObj, method = "deterministic")

Arguments

gradeObj

A wmfmGrade object.

method

Character scalar naming the scoring method to inspect.

Value

A list suitable for JSON serialisation.


Build developer scoring JSON export payload

Description

Build developer scoring JSON export payload

Usage

buildDeveloperScoringJsonPayload(
  model = NULL,
  rv = NULL,
  input = NULL,
  gradeObj = NULL,
  repeatedResult = NULL,
  method = "deterministic"
)

Arguments

model

A fitted model object from the app.

rv

App reactive values object.

input

Shiny input object.

gradeObj

Current single-run grade object.

repeatedResult

Current repeated-run result object.

method

Character scalar naming the scoring method to inspect.

Value

A list suitable for JSON serialisation.


Build developer scoring JSON export text

Description

Build developer scoring JSON export text

Usage

buildDeveloperScoringJsonText(payload)

Arguments

payload

A developer scoring export payload.

Value

A JSON character scalar.


Build developer scoring loss table

Description

Extracts a named feedback table from a scored wmfmGrade object.

Usage

buildDeveloperScoringLossTable(gradeObj, tableName, method = "deterministic")

Arguments

gradeObj

A wmfmGrade object.

tableName

Character scalar naming a feedback table.

method

Character scalar naming the scoring method to inspect.

Value

A data frame suitable for renderTable().


Build developer scoring metric table

Description

Extracts the metric summary from a scored wmfmGrade object.

Usage

buildDeveloperScoringMetricTable(gradeObj, method = "deterministic")

Arguments

gradeObj

A wmfmGrade object.

method

Character scalar naming the scoring method to inspect.

Value

A data frame suitable for renderTable().


Build developer scoring object text

Description

Captures the printed summary of a scored wmfmGrade object for developer inspection.

Usage

buildDeveloperScoringObjectText(gradeObj)

Arguments

gradeObj

A wmfmGrade object.

Value

A character scalar.


Build developer scoring repeated-run progress text

Description

Build developer scoring repeated-run progress text

Usage

buildDeveloperScoringProgressText(completed, total, elapsedSeconds)

Arguments

completed

Number of completed runs.

total

Total number of requested runs.

elapsedSeconds

Elapsed runtime in seconds.

Value

A character scalar.


Extracts semantic evidence diagnostics from a scored wmfmGrade object.

Description

Extracts semantic evidence diagnostics from a scored wmfmGrade object.

Usage

buildDeveloperScoringSemanticEvidenceTable(gradeObj, method = "deterministic")

Arguments

gradeObj

A wmfmGrade object.

method

Character scalar naming the scoring method to inspect.

Value

A semantic evidence diagnostics data frame, or NULL.


Build developer scoring summary table

Description

Converts a scored wmfmGrade object into a compact one-row table for the developer scoring and grading panel.

Usage

buildDeveloperScoringSummaryTable(gradeObj, method = "deterministic")

Arguments

gradeObj

A wmfmGrade object.

method

Character scalar naming the scoring method to inspect.

Value

A data frame suitable for renderTable().


Build a WMFM model object for developer scoring

Description

The app stores the current fitted model as a native fitted model object. The grading API is intentionally defined on wmfmModel, so this helper wraps the current app state in the same classed object before calling grade().

Usage

buildDeveloperScoringWmfmModel(model, rv, input, explanationText = NULL)

Arguments

model

A fitted model object from the app.

rv

App reactive values object.

input

Shiny input object.

explanationText

Character scalar explanation text.

Value

A wmfmModel object, or NULL when the current state is incomplete.


Build message for duplicate pairwise contrast requests.

Description

Build message for duplicate pairwise contrast requests.

Usage

buildDuplicateContrastPairMessage()

Value

A character scalar notification message.


Build eligible adjustment variables from predictor buckets

Description

Returns factor and numeric predictors that are currently eligible to be marked as adjustment variables. The response variable is always excluded.

Usage

buildEligibleAdjustmentVariables(
  responseVariable,
  factorVariables,
  continuousVariables
)

Arguments

responseVariable

Name of the current response variable.

factorVariables

Character vector of variables in the factor bucket.

continuousVariables

Character vector of variables in the continuous bucket.

Value

Character vector of eligible adjustment variables.


Build deterministic teaching cases from an equation specification

Description

Enumerates the displayed teaching cases implied by a deterministic equation specification. A case represents one condition to be shown later by the rendering layer, such as a general equation, one factor level, or one factor-level combination.

Usage

buildEquationCases(spec)

Arguments

spec

A deterministic equation specification, typically produced by buildEquationSpec().

Details

The current policy is intentionally simple:

This helper decides which cases to show, but it does not render any algebra or response-scale expressions.

Value

A list of class "wmfmEquationCases" containing one element per displayed case.


Collapse coefficient components into a displayable expression term

Description

Builds one deterministic algebra term from one or more coefficient components. The result carries its own sign so later joining can avoid malformed patterns such as "+ (-1.23)".

Usage

buildEquationComponentText(values, variable = NULL, digits = 2)

Arguments

values

Numeric vector of coefficient components.

variable

Optional character scalar naming the retained variable.

digits

Integer number of decimal places. Defaults to 2.

Value

A character scalar.


Build adjustment-role metadata for fitted equation display

Description

Creates metadata describing which predictors are primary versus adjustment variables while preserving the original fitted formula terms. This helper is display-focused only and does not alter model fitting, model matrices, or stored model objects.

Usage

buildEquationDisplayRoleMetadata(model)

Arguments

model

A fitted model object, typically of class "lm" or "glm".

Value

A list containing predictor grouping metadata for equation display.


Build UI summary text for fitted equation role metadata

Description

Formats concise text describing which predictors are primary and which are adjustment variables so the fitted-equation display can label term roles without hiding any fitted terms.

Usage

buildEquationDisplayRoleSummary(roleMetadata)

Arguments

roleMetadata

Output from buildEquationDisplayRoleMetadata().

Value

Character vector of summary lines for display.


Build a deterministic equation specification from a fitted model

Description

Extracts the core structural information needed by a deterministic equation renderer. The returned specification is intended to separate model inspection from later case enumeration and string rendering.

Usage

buildEquationSpec(model)

Arguments

model

A fitted model object, typically of class lm or glm.

Details

The specification includes:

This helper is intentionally conservative. It aims to describe the fitted model clearly, not to perform symbolic algebra.

Value

A list of class "wmfmEquationSpec".


Build the example ready status message

Description

Build the example ready status message

Usage

buildExampleReadyStatus()

Value

A character string for the example load status display.


Build a deterministic claim-to-evidence map for a model explanation

Description

Creates a student-safe, inspectable mapping from the final explanation text back to the deterministic evidence used to support it. The mapping is built from sentence-level units in the final explanation and links each sentence to evidence categories drawn from the explanation audit and teaching summary.

Usage

buildExplanationClaimEvidenceMap(
  explanationText,
  audit,
  teachingSummary = NULL,
  model = NULL
)

Arguments

explanationText

Character scalar containing the final explanation.

audit

A wmfmExplanationAudit object.

teachingSummary

Optional wmfmExplanationTeachingSummary object. When NULL and model is supplied, one is built automatically.

model

Optional fitted model object, used to derive a teaching summary and to improve sentence matching.

Details

This object is intentionally not presented as hidden chain-of-thought. It is a transparent post hoc map showing which deterministic ingredients best match the visible explanation text.

The current implementation uses a tag-first hybrid approach:

Value

An object of class wmfmExplanationClaimEvidenceMap.


Build a combined plain-language support note for a mapped claim

Description

Build a combined plain-language support note for a mapped claim

Usage

buildExplanationClaimSupportNote(
  claimTags,
  matchedEvidence,
  supportNotes = NULL
)

Arguments

claimTags

Character vector.

matchedEvidence

Data frame of evidence rows.

supportNotes

Optional character vector.

Value

A single character string.


Build plain-language support notes for a mapped claim

Description

Build plain-language support notes for a mapped claim

Usage

buildExplanationClaimSupportNotes(claimTags, matchedEvidence)

Arguments

claimTags

Character vector.

matchedEvidence

Data frame of evidence rows.

Value

Character vector.


Build deterministic quality flags for a mapped explanation sentence

Description

Applies lightweight deterministic checks to a visible sentence. These flags are intended for developer feedback and validation. They do not change the explanation text and they do not replace the legacy claim-tag fields.

Usage

buildExplanationDeterministicQualityFlags(claimText, roles = character(0))

Arguments

claimText

Character scalar.

roles

Character vector of Stage 9 sentence roles.

Value

Character vector of quality-flag identifiers.


Build a deterministic evidence inventory for explanation mapping

Description

Build a deterministic evidence inventory for explanation mapping

Usage

buildExplanationEvidenceInventory(audit, teachingSummary = NULL, model = NULL)

Arguments

audit

A wmfmExplanationAudit object.

teachingSummary

Optional teaching summary object.

model

Optional fitted model object.

Value

A data frame.


Build deterministic quality flags for a claim-evidence map

Description

These map-level flags summarize omissions or structural problems across all mapped explanation sentences. They are deliberately conservative so Stage 9.6 adds developer-facing diagnostics without changing existing tagging behavior.

Usage

buildExplanationMapQualityFlags(claimsTable)

Arguments

claimsTable

Claim mapping data frame.

Value

Character vector of quality-flag identifiers.


Build deterministic model-profile metadata for explanations

Description

Builds a compact model profile that can be shared by explanation prompts, deterministic formatting, auditing, validation, and developer feedback. The profile describes the fitted model structure without changing the existing explanation-audit or claim-evidence systems.

Usage

buildExplanationModelProfile(model, data = NULL, modelType = NULL)

Arguments

model

A fitted model object.

data

Optional data frame used to fit the model. If omitted, the model frame is recovered from model where possible.

modelType

Optional WMFM model type, such as "lm", "logistic", or "poisson".

Value

A named list with deterministic model-profile metadata.


Build explanation provenance footer text

Description

Build explanation provenance footer text

Usage

buildExplanationProvenanceText(
  providerLabel,
  modelName = NULL,
  generatedAt = Sys.time()
)

Arguments

providerLabel

Character scalar provider/backend label.

modelName

Character scalar model name.

generatedAt

POSIXct or character time value.

Value

Character scalar provenance text.


Build deterministic model-aware explanation rules

Description

Converts explanation model-profile metadata into a compact set of deterministic rules for later prompt construction, validation, and developer feedback. This function does not generate explanation text and does not call an LLM. It records the scale, comparison scope, skeleton, language guidance, avoided terms, and quality flags implied by the model profile.

Usage

buildExplanationRuleProfile(modelProfile)

Arguments

modelProfile

A model-profile list, usually returned by buildExplanationModelProfile().

Value

A named list of deterministic model-aware explanation rules.


Build model-aware explanation skeleton text for prompt input

Description

Builds a deterministic prompt block from the Stage 9 model profile and rule profile. The block gives the language model an ordered explanation structure while leaving the wording of the student-facing explanation to the model.

Usage

buildExplanationSkeletonPromptBlock(model, mf = NULL)

Arguments

model

A fitted model object.

mf

Optional model frame.

Value

A character scalar containing model-aware skeleton instructions, or an empty string if a skeleton cannot be built.


Build the starting-values teaching text

Description

Build the starting-values teaching text

Usage

buildExplanationTeachingBaselineChoice(
  audit,
  numericPredictors,
  factorPredictors
)

Arguments

audit

A wmfmExplanationAudit object.

numericPredictors

Character vector of numeric predictor names.

factorPredictors

Character vector of factor predictor names.

Value

A single character string.


Build a plain-language description of the data used

Description

Build a plain-language description of the data used

Usage

buildExplanationTeachingDataDescription(
  model,
  responseName,
  numericPredictors,
  factorPredictors,
  outcomeLabel
)

Arguments

model

A fitted model object.

responseName

Name of the response variable.

numericPredictors

Character vector of numeric predictor names.

factorPredictors

Character vector of factor predictor names.

outcomeLabel

Student-friendly outcome label.

Value

A single character string.


Build the teaching evidence list

Description

Build the teaching evidence list

Usage

buildExplanationTeachingEvidenceTable(
  audit,
  responseName,
  outcomeLabel,
  numericPredictors,
  factorPredictors,
  researchQuestion,
  dataDescription
)

Arguments

audit

A wmfmExplanationAudit object.

responseName

Name of the response variable.

outcomeLabel

Student-friendly outcome label.

numericPredictors

Character vector of numeric predictor names.

factorPredictors

Character vector of factor predictor names.

researchQuestion

Optional research question string.

dataDescription

Plain-language data description.

Value

A data frame.


Build the interpretation teaching text

Description

Build the interpretation teaching text

Usage

buildExplanationTeachingInterpretationScale(audit, outcomeLabel)

Arguments

audit

A wmfmExplanationAudit object.

outcomeLabel

Student-friendly outcome label.

Value

A single character string.


Build the main-effect teaching text

Description

Build the main-effect teaching text

Usage

buildExplanationTeachingMainEffectDescription(
  audit,
  responseName,
  outcomeLabel,
  numericPredictors,
  factorPredictors
)

Arguments

audit

A wmfmExplanationAudit object.

responseName

Name of the response variable.

outcomeLabel

Student-friendly outcome label.

numericPredictors

Character vector of numeric predictor names.

factorPredictors

Character vector of factor predictor names.

Value

A single character string.


Format a teaching number for inline prose

Description

Format a teaching number for inline prose

Usage

buildExplanationTeachingNumber(x, digits = 2)

Arguments

x

A numeric-like value.

digits

Number of decimal places to show when needed.

Value

A single character string.


Build a student-friendly outcome label

Description

Build a student-friendly outcome label

Usage

buildExplanationTeachingOutcomeLabel(responseNounPhrase)

Arguments

responseNounPhrase

Character scalar describing the response.

Value

A single character string.


Description

Build the research-question teaching text

Usage

buildExplanationTeachingResearchQuestionLink(
  researchQuestion,
  responseName,
  outcomeLabel
)

Arguments

researchQuestion

Optional research question string.

responseName

Name of the response variable.

outcomeLabel

Student-friendly outcome label.

Value

A single character string.


Build a student-facing teaching summary for a model explanation

Description

Derives a plain-language teaching summary from the deterministic explanation audit. The returned object is designed for student-facing display and avoids exposing raw prompt ingredients or developer-facing internal structures.

Usage

buildExplanationTeachingSummary(audit, model, researchQuestion = NULL)

Arguments

audit

A wmfmExplanationAudit object.

model

A fitted model object, typically of class lm or glm.

researchQuestion

Optional character string giving the research question the model is being used to address. When NULL, the function falls back to any research question stored on the fitted model.

Value

An object of class wmfmExplanationTeachingSummary.


Build the uncertainty teaching text

Description

Build the uncertainty teaching text

Usage

buildExplanationTeachingUncertaintySummary(audit, outcomeLabel)

Arguments

audit

A wmfmExplanationAudit object.

outcomeLabel

Student-friendly outcome label.

Value

A single character string.


Build the derived-variable transformation teaching text

Description

Build the derived-variable transformation teaching text

Usage

buildExplanationTeachingVariableTransformationSummary(audit)

Arguments

audit

A wmfmExplanationAudit object.

Value

A single character string.


Build the x-change teaching text

Description

Build the x-change teaching text

Usage

buildExplanationTeachingXChangeDescription(
  numericPredictors,
  factorPredictors,
  outcomeLabel
)

Arguments

numericPredictors

Character vector of numeric predictor names.

factorPredictors

Character vector of factor predictor names.

outcomeLabel

Student-friendly outcome label.

Value

A single character string.


Build a constrained tutor-style prompt for explaining the explanation

Description

Uses the deterministic teaching summary as the main source of truth for an optional, more conversational explanation of how the model explanation was constructed. This avoids exposing raw audit internals and constrains the language model to the information already shown in the app.

Usage

buildExplanationTutorPrompt(
  teachingSummary,
  modelExplanation = NULL,
  researchQuestion = NULL
)

Arguments

teachingSummary

A wmfmExplanationTeachingSummary object.

modelExplanation

Optional character scalar giving the existing model explanation shown to the student.

researchQuestion

Optional character scalar.

Value

A single character string prompt.


Build CI rows for two-factor linear-model interactions

Description

Build CI rows for two-factor linear-model interactions

Usage

buildFactorByFactorInteractionConfidenceIntervalRows(
  model,
  mf,
  familyObj,
  level,
  baseInfo,
  factorNames,
  appendRow
)

Arguments

model

A fitted linear model.

mf

Model frame.

familyObj

Optional GLM family object.

level

Confidence level.

baseInfo

Base-setting information.

factorNames

Names of the two factor predictors.

appendRow

Row appender closure.

Value

Invisibly returns NULL.


Build new-data rows for a two-factor comparison

Description

Build new-data rows for a two-factor comparison

Usage

buildFactorByFactorNewData(
  mf,
  focalFactor,
  focalLevel,
  conditioningFactor,
  conditioningLevel
)

Arguments

mf

Model frame.

focalFactor

Factor whose level is being set.

focalLevel

Focal factor level.

conditioningFactor

Conditioning factor.

conditioningLevel

Conditioning factor level.

Value

A one-row data frame.


Build fitted-equation content UI

Description

Renders fitted-equation content for supported equation output structures while consistently prepending the predictor-role summary when available.

Usage

buildFittedEquationContentUi(eq, roleSummaryUi = NULL)

Arguments

eq

Equation object produced by the fitted-equation pipeline.

roleSummaryUi

Optional summary UI block from buildFittedEquationRoleSummaryUi().

Value

A shiny.tag or shiny.tag.list object.


Build fitted-equation role summary UI

Description

Builds the predictor-role summary block used above fitted equations when adjustment-variable metadata is present.

Usage

buildFittedEquationRoleSummaryUi(roleSummary)

Arguments

roleSummary

Character vector from buildEquationDisplayRoleSummary().

Value

A shiny.tag object, or NULL when no summary should be shown.


Build a fitted-quantity label

Description

Build a fitted-quantity label

Usage

buildFittedQuantityLabel(labelContext, notation, quantityType = NULL)

Arguments

labelContext

Context list.

notation

Notation list.

quantityType

Optional quantity type override.

Value

A character scalar.


Build formatted explanation quantities for prompt input

Description

Builds a student-ready prompt block from deterministic confidence-interval evidence. Raw coefficients and raw confidence-interval matrices should stay in audit/developer metadata; this block is for the language model prompt.

Usage

buildFormattedPromptQuantityBlock(model, mf = NULL, predictorNames = NULL)

Arguments

model

A fitted model object.

mf

Optional model frame.

predictorNames

Optional predictor names.

Value

A character scalar containing formatted prompt quantities, or an empty string if no deterministic quantity table can be built.


Build student-facing notation for GLM teaching output

Description

Creates a small bundle of notation strings used in equations and confidence interval output for common GLM families.

Usage

buildGlmTeachingNotation(model)

Arguments

model

A fitted model object, typically of class "glm".

Details

For binomial models, the helper extracts the response-variable name and the two observed outcome levels from the model response and returns labels such as "Pr(outcome = success)" and "Odds(outcome = success)". The second level is treated as the success level to match R's usual treatment coding for a two-level factor response.

For Poisson models, the helper returns labels based on the response-variable name, such as "E[count]".

Value

A named list of notation strings.


Build the default example load status message

Description

Build the default example load status message

Usage

buildInitialExampleLoadStatus()

Value

A character string for the example load status display.


Build the initial package scan status message

Description

Build the initial package scan status message

Usage

buildInitialPackageScanStatus(initialPackageChoices)

Arguments

initialPackageChoices

Character vector of immediately available package choices.

Value

A character string for the package scan status display.


Build interpretation-mode banner text for adjustment workflows

Description

Returns a compact interpretation-mode label shown near explanation surfaces when adjustment variables are selected.

Usage

buildInterpretationModeLabel(adjustmentVariables)

Arguments

adjustmentVariables

Character vector of selected adjustment variables.

Value

Character scalar banner text, or NULL when no adjustment variables are selected.


Build message for invalid custom contrast weights.

Description

Build message for invalid custom contrast weights.

Usage

buildInvalidCustomContrastWeightMessage()

Value

A character scalar notification message.


Build a CI for a linear combination of coefficients

Description

Build a CI for a linear combination of coefficients

Usage

buildLinearCombinationInterval(model, weights, level)

Arguments

model

A fitted model object.

weights

Named coefficient weights.

level

Confidence level.

Value

A list with estimate, bounds, and weights.


Build readable text for a linear combination of coefficients

Description

Build readable text for a linear combination of coefficients

Usage

buildLinearCombinationText(nonZero)

Arguments

nonZero

Named numeric vector of non-zero design weights.

Value

A character scalar.


Build readable variance text for a linear combination

Description

Build readable variance text for a linear combination

Usage

buildLinearCombinationVarianceText(nonZero)

Arguments

nonZero

Named numeric vector of non-zero design weights.

Value

A character scalar.


Build message for recoding a binary factor response for linear regression.

Description

Build message for recoding a binary factor response for linear regression.

Usage

buildLinearModelBinaryFactorRecodingMessage(responseName, levels)

Arguments

responseName

Character scalar response variable name.

levels

Character vector containing the two factor levels.

Value

A character scalar notification message.


Build cache key for plain-language explanation generation

Description

Build cache key for plain-language explanation generation

Usage

buildLmExplanationCacheKey(
  formulaStr,
  coefStr,
  numericAnchorCacheKey,
  researchQuestion,
  followupQuestion = "",
  adjustmentVariables = character(0)
)

Arguments

formulaStr

Character scalar model formula text.

coefStr

Character scalar coefficient payload text.

numericAnchorCacheKey

Character scalar numeric-anchor cache token.

researchQuestion

Character scalar research question.

followupQuestion

Character scalar bounded follow-up model question.

adjustmentVariables

Character vector adjustment variables.

Value

Character scalar cache key.


Build term-evidence guidance for explanation prompts

Description

Uses the linear-model ANOVA table as internal guidance for which additive or interaction terms deserve emphasis in the student-facing explanation. The block is prompt-side guidance only: explanations should not report p-values or ANOVA mechanics directly to students.

Usage

buildLmTermEvidencePromptBlock(model, mf = NULL, alpha = 0.05)

Arguments

model

A fitted model object.

mf

Optional model frame.

alpha

Numeric threshold for treating a term as clearly supported.

Value

A character scalar containing prompt guidance, or an empty string when term-level evidence is unavailable or not applicable.


Build message shown when data is required before opening model help.

Description

Build message shown when data is required before opening model help.

Usage

buildLoadDataFirstMessage()

Value

A character scalar notification message.


Build status text for a successfully loaded example.

Description

Build status text for a successfully loaded example.

Usage

buildLoadedExampleStatus(exampleName)

Arguments

exampleName

Character scalar example name.

Value

A character scalar status message.


Build the loading examples choice label

Description

Build the loading examples choice label

Usage

buildLoadingExampleChoice()

Value

A named character vector for the temporary example selector choice.


Build message for non-binary character logistic responses.

Description

Build message for non-binary character logistic responses.

Usage

buildLogisticCharacterResponseMessage(responseName, nValues)

Arguments

responseName

Character scalar response variable name.

nValues

Integer number of distinct values.

Value

A character scalar notification message.


Build message for non-binary factor logistic responses.

Description

Build message for non-binary factor logistic responses.

Usage

buildLogisticFactorResponseMessage(responseName, nLevels)

Arguments

responseName

Character scalar response variable name.

nLevels

Integer number of factor levels.

Value

A character scalar notification message.


Build message for numeric logistic responses with values other than 0/1.

Description

Build message for numeric logistic responses with values other than 0/1.

Usage

buildLogisticNumericResponseMessage(responseName, values)

Arguments

responseName

Character scalar response variable name.

values

Numeric vector of observed response values.

Value

A character scalar notification message.


Build message for unsupported logistic response types.

Description

Build message for unsupported logistic response types.

Usage

buildLogisticUnsupportedResponseMessage()

Value

A character scalar notification message.


Build summary statistics for metric diagnosis

Description

Internal helper for diagnose().

Usage

buildMetricDiagnosisSummary(metricDf, metric)

Arguments

metricDf

Run-level metric diagnosis data.

metric

Metric name.

Value

A one-row data frame.


Build metric-specific evidence summary for diagnosis

Description

Internal helper for diagnose() that creates a compact, metric-aware evidence summary from the run-level diagnosis data.

Usage

buildMetricEvidenceSummary(metricDf, metric)

Arguments

metricDf

Run-level metric diagnosis data.

metric

Metric name.

Details

The initial implementation focuses on fields that are especially useful for diagnosing disagreement on numericExpressionAdequate. For other metrics, the function returns a lighter generic summary.

Value

A one-row data frame containing metric-specific summary fields.


Build startup guidance for missing provider configuration

Description

Build startup guidance for missing provider configuration

Usage

buildMissingProviderStartupMessage()

Value

Character scalar.


Build message for a missing custom text separator.

Description

Build message for a missing custom text separator.

Usage

buildMissingSeparatorMessage()

Value

A character scalar notification message.


Build interpretable confidence-interval output for a fitted model

Description

Creates a compact table of confidence intervals for quantities that are easier for students to interpret than a raw coefficient table. For supported models, the helper prefers derived teaching rows such as fitted quantities at simple reference settings and one-unit covariate effects on the most natural teaching scale. When the model structure is too complex for a stable derived summary, the helper falls back to a coefficient table.

Usage

buildModelConfidenceIntervalData(
  model,
  level = 0.95,
  numericReference = c("mean", "zero")
)

Arguments

model

A fitted model object, typically of class "lm" or "glm".

level

Confidence level. Defaults to 0.95.

numericReference

How numeric predictors should be fixed when building fitted-quantity rows. One of "mean" or "zero". Defaults to "mean". The app may override this with a data-aware helper so that fitted-value summaries are anchored at sample means when 0 lies outside the observed numeric range.

Details

Derived mode currently supports:

All other interaction structures fall back to coefficient mode.

Value

A list with components:

table

A data frame ready for display in the confidence-interval tab.

details

A list of labelled derivation records for drill-down display.

note

Optional explanatory note for the UI.

teachingNote

Optional short teaching note about variance and covariance.

vcovTable

The variance-covariance matrix rounded for display.

mode

Either "derived" or "coefficient".


Build choices for the confidence-interval row selector

Description

Build choices for the confidence-interval row selector

Usage

buildModelConfidenceIntervalRowChoices(ciData)

Arguments

ciData

Output from buildModelConfidenceIntervalData().

Value

A named character vector suitable for selectInput().


Build a short teaching note for confidence-interval drill-down

Description

Build a short teaching note for confidence-interval drill-down

Usage

buildModelConfidenceIntervalTeachingNote(model)

Arguments

model

A fitted model object.

Value

A character scalar.


Build a deterministic audit trail for a model explanation

Description

Creates a structured, student-facing summary of the deterministic inputs, interpretation choices, and supporting model quantities used when WMFM asks the language model to write a plain-language explanation.

Usage

buildModelExplanationAudit(model)

Arguments

model

A fitted model object, typically of class lm or glm.

Details

This audit is intentionally not presented as hidden reasoning or private chain-of-thought. Instead, it records inspectable ingredients such as prompt rules, interpretation scale, numeric anchors, reference levels, and confidence-interval evidence.

The returned object is expected to follow a stable top-level contract with sections for overview metadata, prompt inputs, prompt rules, interpretation-scale metadata, numeric anchors, reference levels, confidence-interval summary, baseline and effect evidence, coefficient data, and raw prompt ingredients.

Value

An object of class wmfmExplanationAudit.


Build a model coefficient table while muffling known perfect-fit warnings

Description

Build a model coefficient table while muffling known perfect-fit warnings

Usage

buildModelExplanationAuditCoefficientTable(model)

Arguments

model

A fitted model object.

Value

A data frame of coefficient summaries.


Build explanation-audit confidence-interval summary

Description

Build explanation-audit confidence-interval summary

Usage

buildModelExplanationAuditConfidenceIntervals(ciData)

Arguments

ciData

Confidence-interval data from buildModelConfidenceIntervalData().

Value

A named list.


Build explanation-audit evidence table for CI sections

Description

Build explanation-audit evidence table for CI sections

Usage

buildModelExplanationAuditEvidenceTable(ciData, section)

Arguments

ciData

Confidence-interval data from buildModelConfidenceIntervalData().

section

Character vector of CI sections to keep.

Value

A data frame.


Build explanation-audit numeric-anchor summary

Description

Build explanation-audit numeric-anchor summary

Usage

buildModelExplanationAuditNumericAnchor(
  model,
  mf,
  predictorNames,
  numericAnchorInfo
)

Arguments

model

A fitted model object.

mf

Model frame for the fitted model.

predictorNames

Predictor names.

numericAnchorInfo

Numeric anchor info from buildModelNumericAnchorInfo().

Value

A named list.


Build explanation-audit overview metadata

Description

Build explanation-audit overview metadata

Usage

buildModelExplanationAuditOverview(model, mf, predictorNames, responseName)

Arguments

model

A fitted model object.

mf

Model frame for the fitted model.

predictorNames

Predictor names.

responseName

Response variable name.

Value

A named list.


Build explanation-audit prompt-input metadata

Description

Build explanation-audit prompt-input metadata

Usage

buildModelExplanationAuditPromptInputs(model, mf, predictorNames, responseName)

Arguments

model

A fitted model object.

mf

Model frame for the fitted model.

predictorNames

Predictor names.

responseName

Response variable name.

Value

A named list.


Build explanation-audit prompt-rule summary

Description

Build explanation-audit prompt-rule summary

Usage

buildModelExplanationAuditPromptRules(model)

Arguments

model

A fitted model object.

Value

A character vector of concise prompt-side rules.


Build explanation-audit reference-level summary

Description

Build explanation-audit reference-level summary

Usage

buildModelExplanationAuditReferenceLevels(mf, predictorNames)

Arguments

mf

Model frame for the fitted model.

predictorNames

Predictor names.

Value

A data frame.


Build explanation-audit interpretation-scale metadata

Description

Build explanation-audit interpretation-scale metadata

Usage

buildModelExplanationAuditScaleInfo(model)

Arguments

model

A fitted model object.

Value

A named list.


Build explanation-audit rows for derived-variable transformations

Description

Converts fitted-model transformation records into a compact data frame for the explanation audit. This is intentionally descriptive only; it does not perform numerical back-transformation.

Usage

buildModelExplanationAuditVariableTransformations(model)

Arguments

model

A fitted model object.

Value

A data frame with one row per fitted derived-variable transformation.


Build bounded follow-up model-question block for explanation prompts

Description

Build bounded follow-up model-question block for explanation prompts

Usage

buildModelFollowupPromptBlock(followupPayload = NULL, followupQuestion = NULL)

Arguments

followupQuestion

Optional character scalar entered in the app as a bounded follow-up model question.

Value

Character scalar prompt block. Empty when no follow-up question is provided.


Build numeric-anchor metadata for model prompts and cache keys

Description

Summarises the observed range and the chosen teaching anchor for each numeric predictor so prompt builders can avoid interpreting model quantities at meaningless values such as 0 when 0 lies well outside the data.

Usage

buildModelNumericAnchorInfo(model = NULL, mf = NULL, predictorNames = NULL)

Arguments

model

Optional fitted model object. Used only when mf is not supplied.

mf

Optional model frame. If omitted, it is computed from model.

predictorNames

Optional character vector of predictor names.

Value

A list with elements numericReference, promptText, and cacheKey.


Build deterministic model-plot data

Description

Build deterministic model-plot data

Usage

buildModelPlotData(model, plotType = c("observedFitted", "residualFitted"))

Arguments

model

A fitted lm, binomial glm, poisson glm, or wmfmModel object containing one of those fitted model objects.

plotType

Plot type. Supported values are "observedFitted" and "residualFitted".

Value

A list containing plot metadata and a data frame.


Build a file name for exported model plots

Description

Build a file name for exported model plots

Usage

buildModelPlotDownloadFilename(
  plotType = c("observedFitted", "residualFitted", "unsupported")
)

Arguments

plotType

Plot type.

Value

A PNG file name for the selected model plot.


Build model-plot axis labels

Description

Build model-plot axis labels

Usage

buildModelPlotLabels(responseName, plotFamily, plotType, residualType)

Arguments

responseName

Name of the response variable.

plotFamily

Model-plot family.

plotType

Plot type.

residualType

Residual type.

Value

A named list of plot labels.


Build a short model-plot summary sentence

Description

Build a short model-plot summary sentence

Usage

buildModelPlotSummaryText(
  model,
  plotType = c("observedFitted", "residualFitted", "unsupported")
)

Arguments

model

A fitted model object or wmfmModel object.

plotType

Plot type.

Value

A single character string for the Model plots UI.


Build a short teaching note for a model plot

Description

Build a short teaching note for a model plot

Usage

buildModelPlotTeachingNote(
  model,
  plotType = c("observedFitted", "residualFitted")
)

Arguments

model

A fitted model object or wmfmModel object.

plotType

Plot type.

Value

A named list with short explanatory strings.


Build available model-plot choices

Description

Build available model-plot choices

Usage

buildModelPlotTypeChoices(model)

Arguments

model

A fitted model object or a wmfmModel object.

Value

A named character vector suitable for selectInput().


Build coefficient weights for a difference between two new-data rows

Description

Build coefficient weights for a difference between two new-data rows

Usage

buildNewDataDifferenceWeights(model, referenceData, comparisonData)

Arguments

model

A fitted model object.

referenceData

One-row reference data frame.

comparisonData

One-row comparison data frame.

Value

A named numeric vector of non-zero coefficient weights.


Build message for missing pairwise contrast entries.

Description

Build message for missing pairwise contrast entries.

Usage

buildNoContrastPairsMessage()

Value

A character scalar notification message.


Build message for missing contrast removal selection.

Description

Build message for missing contrast removal selection.

Usage

buildNoContrastSelectionMessage()

Value

A character scalar notification message.


Build message for an RDA or RData file without a data frame.

Description

Build message for an RDA or RData file without a data frame.

Usage

buildNoDataFrameInRdaMessage()

Value

A character scalar notification message.


Build CI rows for models without interactions

Description

Build CI rows for models without interactions

Usage

buildNoInteractionConfidenceIntervalRows(
  model,
  mf,
  familyObj,
  level,
  baseInfo,
  appendRow
)

Arguments

model

A fitted model object.

mf

Model frame.

familyObj

Optional GLM family object.

level

Confidence level.

baseInfo

Base-setting information.

appendRow

Row appender closure.

Value

Invisibly returns NULL.


Build message for missing language model fallback.

Description

Build message for missing language model fallback.

Usage

buildNoLanguageModelAvailableMessage()

Value

A character scalar notification message.


Build the no package datasets status message

Description

Build the no package datasets status message

Usage

buildNoPackageDatasetsStatus()

Value

A character string for the package dataset status display.


Build a short UI note about numeric interpretation anchors

Description

Returns a concise note for student-facing UI sections when a fitted model has numeric predictors. The note explains whether baseline fitted values are being described at 0 or at sample means.

Usage

buildNumericAnchorUiNote(model = NULL, mf = NULL, predictorNames = NULL)

Arguments

model

Optional fitted model object. Used only when mf is not supplied.

mf

Optional model frame. If omitted, it is computed from model.

predictorNames

Optional character vector of predictor names.

Value

A character scalar. Returns "" when no numeric predictors are present.


Build cancel label for numeric-as-factor confirmation modal.

Description

Build cancel label for numeric-as-factor confirmation modal.

Usage

buildNumericFactorCancelLabel()

Value

A character scalar button label.


Build confirm label for numeric-as-factor confirmation modal.

Description

Build confirm label for numeric-as-factor confirmation modal.

Usage

buildNumericFactorConfirmLabel()

Value

A character scalar button label.


Build body text for numeric-as-factor confirmation modal.

Description

Build body text for numeric-as-factor confirmation modal.

Usage

buildNumericFactorConfirmMessage(variableName)

Arguments

variableName

Character scalar variable name.

Value

A character scalar modal body.


Build title for numeric-as-factor confirmation modal.

Description

Build title for numeric-as-factor confirmation modal.

Usage

buildNumericFactorConfirmTitle()

Value

A character scalar modal title.


Build text describing other predictors at base settings

Description

Build text describing other predictors at base settings

Usage

buildOtherBaseSettingsText(
  mf,
  baseRow,
  excludeVarName = NULL,
  numericReference
)

Arguments

mf

Model frame.

baseRow

One-row base data frame.

excludeVarName

Optional predictor to exclude.

numericReference

Numeric reference choice.

Value

A character scalar.


Build the package dataset checking status message

Description

Build the package dataset checking status message

Usage

buildPackageDatasetCheckingStatus(packageName)

Arguments

packageName

Name of the package being checked.

Value

A character string for the package dataset status display.


Build the default package dataset status message

Description

Build the default package dataset status message

Usage

buildPackageDatasetChoiceStatus()

Value

A character string for the package dataset status display.


Build the package dataset empty choice label

Description

Build the package dataset empty choice label

Usage

buildPackageDatasetEmptyChoiceLabel()

Value

A character string for the disabled dataset choice label.


Build the package dataset empty status message

Description

Build the package dataset empty status message

Usage

buildPackageDatasetEmptyStatus(packageName)

Arguments

packageName

Name of the package that has no datasets.

Value

A character string for the package dataset status display.


Build the package dataset loading notification message

Description

Build the package dataset loading notification message

Usage

buildPackageDatasetFindingMessage(packageName)

Arguments

packageName

Name of the package being scanned.

Value

A character string for the package dataset loading notification.


Build the package dataset found status message

Description

Build the package dataset found status message

Usage

buildPackageDatasetFoundStatus(packageName, datasetNames)

Arguments

packageName

Name of the package that was scanned.

datasetNames

Character vector of dataset names found in the package.

Value

A character string for the package dataset status display.


Build message for a package dataset loading failure.

Description

Build message for a package dataset loading failure.

Usage

buildPackageDatasetLoadFailedMessage(datasetName, packageName)

Arguments

datasetName

Character scalar dataset name.

packageName

Character scalar package name.

Value

A character scalar notification message.


Build the startup package dataset pending status message

Description

Build the startup package dataset pending status message

Usage

buildPackageDatasetPendingScanStatus()

Value

A character string for the package dataset status display.


Build the package list updating status message

Description

Build the package list updating status message

Usage

buildPackageListUpdatingStatus()

Value

A character string for the package scan status display.


Build the package scan completion status message

Description

Build the package scan completion status message

Usage

buildPackageScanCompleteStatus(packageNames, initialPackageChoices)

Arguments

packageNames

Character vector of packages with datasets.

initialPackageChoices

Character vector of package choices that were available before the full package scan completed.

Value

A character string, or NULL when no status message is needed.


Build message for Poisson response warnings.

Description

Build message for Poisson response warnings.

Usage

buildPoissonResponseWarningMessage()

Value

A character scalar notification message.


Build validation-guard prompt guidance

Description

Builds deterministic prompt guidance from the Stage 9 validation targets. The guard is deliberately prompt-side and diagnostic only: it asks the language model to avoid known failure modes, while leaving automatic regeneration for a later stage.

Usage

buildPromptValidationGuardBlock(model, mf = NULL)

Arguments

model

A fitted model object.

mf

Optional model frame.

Value

A character scalar containing validation-guard prompt guidance.


Build validation-guard target rows

Description

Build validation-guard target rows

Usage

buildPromptValidationGuardTargets(modelProfile = NULL, ruleProfile = NULL)

Arguments

modelProfile

Explanation model profile, or NULL.

ruleProfile

Explanation rule profile, or NULL.

Value

A data frame with flag and label columns.


Build help text for the user data context modal.

Description

Build help text for the user data context modal.

Usage

buildProvideDataContextHelpText()

Value

A character scalar help text.


Build placeholder text for the user data context modal.

Description

Build placeholder text for the user data context modal.

Usage

buildProvideDataContextPlaceholder()

Value

A character scalar placeholder text.


Build title for the user data context modal.

Description

Build title for the user data context modal.

Usage

buildProvideDataContextTitle()

Value

A character scalar modal title.


Build provider credential guidance text for settings

Description

Build provider credential guidance text for settings

Usage

buildProviderCredentialGuidance(provider)

Arguments

provider

Character scalar provider id.

Value

Character vector of concise guidance lines for the selected provider.


Build provider credential status lines for settings

Description

Build provider credential status lines for settings

Usage

buildProviderCredentialStatusLines(provider)

Arguments

provider

Character scalar provider id.

Value

Character vector describing whether credentials are detected and where they are expected.


Build provider settings UI state

Description

Build provider settings UI state

Usage

buildProviderSettingsState()

Value

Named list containing config-location details, provider status, and the resolved non-secret provider config values used by the settings UI.


Build provider settings status text lines

Description

Build provider settings status text lines

Usage

buildProviderSettingsStatusLines(settingsState)

Arguments

settingsState

Named list as returned by buildProviderSettingsState().

Value

Character vector of status lines for display in the settings UI.


Build a response back-transformation availability note

Description

Build a response back-transformation availability note

Usage

buildResponseBackTransformationAvailabilityNote(responseRecord, rows)

Arguments

responseRecord

Response transformation record.

rows

Back-transformation table.

Value

Character scalar.


Build response back-transformation mode guidance

Description

Build response back-transformation mode guidance

Usage

buildResponseBackTransformationModeGuidance(payload)

Arguments

payload

Response back-transformation payload.

Value

Character vector of prompt guidance lines.


Build deterministic response back-transformation metadata

Description

Uses recorded derived-variable metadata to construct conservative prompt payloads for models where the response variable itself was user-created from another variable. The helper only reports quantities WMFM can compute deterministically; it does not ask the language model to infer an inverse.

Usage

buildResponseBackTransformationPayload(model, mf = NULL, predictorNames = NULL)

Arguments

model

A fitted model object.

mf

Optional model frame.

predictorNames

Optional predictor names.

Value

A list describing availability and any original-response-scale rows.


Build response back-transformation prompt guidance

Description

Build response back-transformation prompt guidance

Usage

buildResponseBackTransformationPromptBlock(
  model,
  mf = NULL,
  predictorNames = NULL,
  payload = NULL
)

Arguments

model

A fitted model object.

mf

Optional model frame.

predictorNames

Optional predictor names.

payload

Optional precomputed response back-transformation payload.

Value

Character scalar prompt block.


Build safe response back-transformation rows

Description

Build safe response back-transformation rows

Usage

buildResponseBackTransformationRows(ciTable, responseRecord)

Arguments

ciTable

Confidence-interval table from WMFM.

responseRecord

Response transformation record.

Value

Data frame of back-transformed rows.


Build response-scale control guidance for explanation prompts

Description

Builds deterministic prompt guidance from the Stage 9 model profile and rule profile so the language model explains the fitted model on the intended student-facing scale rather than on the raw coefficient or link-function scale.

Usage

buildResponseScaleControlPromptBlock(model, mf = NULL)

Arguments

model

A fitted model object.

mf

Optional model frame.

Value

A character scalar containing response-scale prompt guidance, or an empty string if the profile cannot be built.


Build the missing s20x package dataset choice label

Description

Build the missing s20x package dataset choice label

Usage

buildS20xPackageMissingChoiceLabel()

Value

A character string for the disabled dataset choice label.


Build the missing s20x package dataset status message

Description

Build the missing s20x package dataset status message

Usage

buildS20xPackageMissingStatus()

Value

A character string for the package dataset status display.


Build message for identical pairwise contrast levels.

Description

Build message for identical pairwise contrast levels.

Usage

buildSameContrastLevelsMessage()

Value

A character scalar notification message.


Generate language rules for interpreting a linear contrast

Description

This helper constructs a short, deterministic set of language constraints to guide natural-language interpretation of a contrast. The rules are designed to enforce wording that is consistent with the model scale (identity, log, logit, etc.) and any transformation applied to the response in an lm() model.

Usage

buildScalePhrasingRules(
  isGlm,
  effectiveScale,
  respTransform,
  nounPhrase = NULL
)

Arguments

isGlm

Logical. TRUE if the fitted model inherits from "glm", FALSE for lm() models.

effectiveScale

Character string giving the interpretation scale. For GLMs this should typically be the model link (e.g. "identity", "log", "logit"). For lm() models this is usually "identity" or "other".

respTransform

Character string describing the detected response transformation for lm() models. Expected values include "none", "log", "log10", "log1p", "sqrt", "inverse", or "unknown".

nounPhrase

Optional character string naming the outcome in student-facing language (e.g. "expected count"). If NULL, a generic phrase ("the outcome") is used.

Details

The returned text is intended to be embedded verbatim in an LLM prompt to prevent inconsistent phrasing (e.g., additive vs multiplicative language).

Value

A single character string containing bullet-point language rules. The text is suitable for direct inclusion in an LLM prompt.

Examples

buildScalePhrasingRules(
  isGlm = FALSE,
  effectiveScale = "identity",
  respTransform = "none"
)

buildScalePhrasingRules(
  isGlm = TRUE,
  effectiveScale = "logit",
  respTransform = "none",
  nounPhrase = "disease status"
)

Build secondary-scale columns for a CI table

Description

Build secondary-scale columns for a CI table

Usage

buildSecondaryConfidenceIntervalColumns(modelFramework, ciTable)

Arguments

modelFramework

Teaching framework identifier.

ciTable

Confidence-interval table with primary values.

Value

A list of numeric vectors.


Build message for a selected object that is not a data frame.

Description

Build message for a selected object that is not a data frame.

Usage

buildSelectedObjectNotDataFrameMessage()

Value

A character scalar notification message.


Build CI rows for supported simple interactions

Description

Build CI rows for supported simple interactions

Usage

buildSimpleInteractionConfidenceIntervalRows(
  model,
  mf,
  familyObj,
  level,
  baseInfo,
  factorName,
  numericName,
  appendRow
)

Arguments

model

A fitted model object.

mf

Model frame.

familyObj

Optional GLM family object.

level

Confidence level.

baseInfo

Base-setting information.

factorName

Name of the factor predictor.

numericName

Name of the numeric predictor.

appendRow

Row appender closure.

Value

Invisibly returns NULL.


Build coefficient weights for a simple interaction slope

Description

Build coefficient weights for a simple interaction slope

Usage

buildSimpleInteractionSlopeWeights(model, factorName, factorLevel, numericName)

Arguments

model

A fitted model object.

factorName

Factor predictor name.

factorLevel

Selected factor level.

numericName

Numeric predictor name.

Value

A named numeric vector.


Build the startup notification message

Description

Build the startup notification message

Usage

buildStartupDataChoicesMessage()

Value

A character string for the startup notification.


Build message for too many predictors in the fitted model formula.

Description

Build message for too many predictors in the fitted model formula.

Usage

buildTooManyPredictorsMessage(predictorNames)

Arguments

predictorNames

Character vector of predictor names.

Value

A character scalar notification message.


Build the unknown chat provider message

Description

Build the unknown chat provider message

Usage

buildUnknownChatProviderMessage()

Value

A character string for an error notification.


Build message for unknown model type errors.

Description

Build message for unknown model type errors.

Usage

buildUnknownModelTypeMessage()

Value

A character scalar notification message.


Build message for an unsupported upload file type.

Description

Build message for an unsupported upload file type.

Usage

buildUnsupportedUploadFileTypeMessage()

Value

A character scalar notification message.


Build a per-variable summary for a data frame

Description

Creates a compact summary of each column in a data frame, intended for display in a Shiny "data help" panel. For each variable, the summary includes its name, class, number of missing values, and a short "details" string:

Usage

buildVarSummary(df, maxLevels = 30, maxUnique = 12)

Arguments

df

A data frame.

maxLevels

Maximum number of factor levels to display in the details string before truncating with an ellipsis.

maxUnique

Maximum number of unique values to display for character or logical variables before truncating with an ellipsis.

Value

A data frame with one row per column of df and columns:

var

Variable name.

class

First class label (e.g., "numeric", "factor").

missing

Count of NA values.

details

A short human-readable summary string.


Build a prompt block describing fitted derived-variable transformations

Description

Build a prompt block describing fitted derived-variable transformations

Usage

buildVariableTransformationPromptBlock(variableTransformations = NULL)

Arguments

variableTransformations

A variable-transformation audit table.

Value

Character scalar prompt block.


Build run-level paired comparison data for WMFM scores

Description

Creates run-level paired data for all metrics in the registry that are present in two score data frames. The returned object is intended to support downstream summaries and plotting.

Usage

buildWmfmComparisonPairs(leftDf, rightDf, registry, leftMethod, rightMethod)

Arguments

leftDf

Long-form score data for the left method.

rightDf

Long-form score data for the right method.

registry

Metric registry.

leftMethod

Name of the left method.

rightMethod

Name of the right method.

Value

A data frame of run-level paired values.


Build downstream support notes for a deterministic explanation audit

Description

Summarises how later rebuild streams can safely use each top-level section of a wmfmExplanationAudit object. This keeps the handoff guidance close to the code and provides a deterministic reference for later teaching-summary, claim-evidence, and UI work.

Usage

buildWmfmExplanationAuditSupportNotes(audit)

Arguments

audit

A wmfmExplanationAudit object.

Value

A data frame describing section purpose and downstream usage.


Build the shared language contract for WMFM explanations

Description

Central shared rules used by both overall model summaries and contrasts. Only the opening context lines vary; the core rules stay identical.

Usage

buildWmfmLanguageContractText(context = c("summary", "contrast"))

Arguments

context

One of "summary" or "contrast".

Value

A character scalar containing the shared language contract text.


Build a compact WMFM LLM scoring cache key

Description

Builds a short cache key for a scoring prompt. The full prompt can exceed R's maximum environment binding-name length, so the cache stores responses under a hash rather than the literal prompt text.

Usage

buildWmfmLlmScoringCacheKey(prompt)

Arguments

prompt

Character scalar containing the full scoring prompt.

Value

Character scalar cache key.


Build the system prompt for WMFM explanation scoring

Description

Creates the fixed system prompt used when asking a language model to score a plain-language model explanation against the WMFM scoring schema.

Creates the fixed system prompt used when asking a language model to score a plain-language model explanation against the WMFM scoring schema.

Usage

buildWmfmLlmScoringSystemPrompt()

buildWmfmLlmScoringSystemPrompt()

Value

A character scalar containing the system prompt.

A character scalar containing the system prompt.


Build a user prompt for WMFM explanation scoring

Description

Given a single run record produced by buildWmfmRunRecord(), construct a prompt asking a language model to score the explanation and return strict JSON matching the WMFM scoring schema.

Given a single run record produced by buildWmfmRunRecord(), construct a prompt asking a language model to score the explanation and return strict JSON matching the WMFM scoring schema.

Usage

buildWmfmLlmScoringUserPrompt(runRecord)

buildWmfmLlmScoringUserPrompt(runRecord)

Arguments

runRecord

Named list produced by buildWmfmRunRecord().

Details

This prompt includes field-specific rubric guidance so that the language model applies the WMFM scoring dimensions consistently rather than inferring its own definitions of what counts as adequate, clear, or appropriate.

This prompt includes field-specific rubric guidance so that the language model applies the WMFM scoring dimensions consistently rather than inferring its own definitions of what counts as adequate, clear, or appropriate.

Value

A character scalar containing the prompt text.

A character scalar containing the prompt text.


Build a user-facing provider model label

Description

Build a user-facing provider model label

Usage

buildWmfmProviderModelLabel(
  profile,
  providerConfig = resolveWmfmProviderConfig()
)

Arguments

profile

Named provider profile.

providerConfig

Resolved provider configuration.

Value

Character scalar model label.


Build a user-facing provider readiness label

Description

Build a user-facing provider readiness label

Usage

buildWmfmProviderReadinessLabel(
  profile,
  providerConfig = resolveWmfmProviderConfig()
)

Arguments

profile

Named provider profile.

providerConfig

Resolved provider configuration.

Value

Character scalar readiness label.


Build provider registry rows for the settings UI

Description

Build provider registry rows for the settings UI

Usage

buildWmfmProviderRegistryRows(
  profiles = readWmfmProviderProfiles(),
  providerConfig = resolveWmfmProviderConfig()
)

Arguments

profiles

List of provider profiles.

providerConfig

Resolved provider configuration.

Value

Data frame with user-facing provider registry rows.


Build provider setup policy text

Description

Build provider setup policy text

Usage

buildWmfmProviderSetupPolicyText()

Value

Character vector describing who controls provider setup in the current runtime context.


Build a single WMFM repeated-run record

Description

Creates a structured record for one repeated WMFM run using a schema that separates:

  1. metadata and model context,

  2. raw explanation text and text summaries, and

  3. extracted semantic claims.

Usage

buildWmfmRunRecord(
  runId,
  exampleName,
  package,
  modelType,
  formula,
  equationsText,
  explanationText,
  researchQuestion = "",
  errorMessage = NA_character_,
  interactionTerms = character(0),
  interactionMinPValue = NA_real_,
  interactionAlpha = 0.05,
  hasFactorPredictors = FALSE,
  adjustmentVariables = character(0),
  primaryVariables = character(0),
  followupScoringContext = NULL
)

Arguments

runId

Integer run identifier.

exampleName

Character example identifier.

package

Character package name.

modelType

Character model class.

formula

Character model formula.

equationsText

Character fitted-equation text.

explanationText

Character explanation text.

researchQuestion

Character research question associated with the model.

errorMessage

Character error message, or NA.

interactionTerms

Character vector of interaction-term names from the fitted model.

interactionMinPValue

Numeric minimum p-value across fitted interaction terms, or NA if no interaction terms are present or no p-value could be extracted.

interactionAlpha

Numeric interaction threshold metadata stored with the run record.

hasFactorPredictors

Logical. Whether the fitted model includes at least one factor or character predictor. Used by downstream scoring gates to distinguish genuinely applicable factor criteria from numeric-only models.

adjustmentVariables

Character vector of adjustment-variable names to carry into explanation scoring. These variables are treated as controls rather than primary narrative targets.

primaryVariables

Character vector of variables of scientific interest to carry into explanation scoring.

followupScoringContext

Optional named list of deterministic follow-up prediction metadata to carry into scoring prompts and extracted evidence.

Details

This function is intentionally limited to describing what happened during a run and what the explanation appeared to say. It does not create any judged scoring fields or aggregate score placeholders. Scoring is handled later by downstream functions such as score() and scoreWmfmRepeatedRuns(), which should operate on the raw run record rather than being partially embedded in it.

Output schema

The returned named list contains the following groups of fields.

Metadata and model context
runId

Integer run identifier.

timestamp

Character timestamp created at record build time.

exampleName

Example identifier.

package

Package name.

modelType

High-level model class.

modelFamily

Optional model family. Initialised to NA.

linkFunction

Optional link function. Initialised to NA.

formula

Model formula as character.

equationsText

Fitted-equation text.

interactionTerms

Pipe-separated interaction-term names.

hasInteractionTerms

Logical. Whether the fitted model includes interactions.

nInteractionTerms

Integer count of interaction terms.

interactionMinPValue

Minimum interaction-term p-value, or NA.

interactionAlpha

Stored interaction threshold metadata from the run.

hasError

Logical. Whether an error was recorded for the run.

errorMessage

Run error message, or NA.

Raw explanation text and summaries
explanationText

Raw explanation text.

normalizedExplanation

Normalised explanation used for duplicate detection.

explanationPresent

Logical. Whether a non-empty explanation is present.

wordCount

Approximate word count.

sentenceCount

Approximate sentence count.

Extracted claim variables
ciMention

Logical. Whether a confidence or credible interval is mentioned.

percentLanguageMention

Logical. Whether percent language is used.

referenceGroupMention

Logical. Whether reference/baseline framing is mentioned.

interactionMention

Logical. Whether interaction or differential-pattern language is mentioned.

uncertaintyMention

Logical. Whether uncertainty or evidential caution is mentioned.

usesInferentialLanguage

Logical. Whether inferential wording is present.

usesDescriptiveOnlyLanguage

Logical. Whether wording is descriptive only.

overclaimDetected

Logical. Whether overstrong language is detected.

underclaimDetected

Logical. Whether unusually weak language is detected.

conditionalLanguageMention

Logical. Whether conditional wording such as "depends on" or subgroup-conditioned interpretation is present.

comparisonLanguageMention

Logical. Whether explicit or implicit comparison wording is present.

outcomeMention

Logical. Placeholder for whether the response is clearly named. Initialised conservatively.

predictorMention

Logical. Placeholder for whether the focal predictor is clearly named. Initialised conservatively.

effectDirectionClaim

Character. One of increase, decrease, mixed_or_both, not_stated.

effectScaleClaim

Character. One of additive, multiplicative, probability_or_odds, mixed_or_unclear, not_stated.

interactionSubstantiveClaim

Character. One of difference_claimed_strongly, difference_claimed_cautiously, no_clear_difference, not_mentioned, unclear, not_applicable.

inferentialRegister

Character. One of inferential, descriptive_only, overclaiming, unclear.

uncertaintyTypeClaim

Character. One of none, generic_uncertainty, confidence_interval, mixed, unclear.

Value

Named list containing one structured raw run record.


Build a wmfmScoreComparison object

Description

Internal helper that constructs agreement summaries and run-level paired data for two score data frames.

Usage

buildWmfmScoreComparison(
  leftDf,
  rightDf,
  leftMethod,
  rightMethod,
  sourceLabel,
  registry = getWmfmMetricRegistry()
)

Arguments

leftDf

Long-form score data for the left method.

rightDf

Long-form score data for the right method.

leftMethod

Name of the left method.

rightMethod

Name of the right method.

sourceLabel

Character label describing the comparison source.

registry

Metric registry.

Value

An object of class wmfmScoreComparison.


Choose deterministic explanation anchors for numeric predictors

Description

Builds auditable anchor metadata for student-facing explanations. These anchors are intended for explanation and prompt inputs, not for changing the fitted model. The raw anchor value is kept separately from the displayed value so explanations can use readable numbers while calculations remain traceable.

Usage

chooseExplanationAnchor(
  model = NULL,
  mf = NULL,
  predictorNames = NULL,
  userAnchors = NULL,
  meaningfulAnchors = NULL,
  defaultSource = c("median", "mean")
)

Arguments

model

Optional fitted model object. Used only when mf is not supplied.

mf

Optional model frame. If omitted, it is computed from model.

predictorNames

Optional character vector of predictor names. If omitted, all non-response columns in mf are considered.

userAnchors

Optional named numeric vector or list of user-specified anchors. These take priority over all other anchor sources.

meaningfulAnchors

Optional named numeric vector or list of pedagogically meaningful anchors. These are used after userAnchors.

defaultSource

Character scalar. Either "median" or "mean".

Value

A named list containing anchor metadata, prompt text, and a cache key.


Choose fitted-means table layout for 1–3 factor predictors

Description

Implements the layout rules for displaying fitted means when all predictors are factors:

Usage

chooseFactorLayout(mf, predictors)

Arguments

mf

A model frame (as returned by model.frame(m)).

predictors

Character vector of predictor names (columns in mf).

Value

A list describing the layout:

type

One of "oneWay", "twoWay", "threeWay", or "other".

rowVar

Row factor name (for "oneWay" and "twoWay" and "threeWay").

colVar

Column factor name (for "twoWay" and "threeWay").

splitVar

Split factor name (for "threeWay" only).

Examples

df = data.frame(
  y = rnorm(24),
  A = factor(rep(c("a1","a2"), each = 12)),
  B = factor(rep(paste0("b", 1:4), times = 6)),
  C = factor(rep(paste0("c", 1:6), times = 4))
)
mod = lm(y ~ A * B * C, data = df)
mf = model.frame(mod)
chooseFactorLayout(mf, c("A","B","C"))


Choose the numeric reference used for teaching summaries

Description

Selects whether numeric predictors should be anchored at 0 or at their sample means when building teaching-oriented summaries such as fitted-value confidence-interval rows. The current rule is intentionally simple: if every numeric predictor has an observed range that includes 0, use 0; otherwise use the sample mean.

Usage

chooseModelNumericReference(model = NULL, mf = NULL, predictorNames = NULL)

Arguments

model

Optional fitted model object. Used only when mf is not supplied.

mf

Optional model frame. If omitted, it is computed from model.

predictorNames

Optional character vector of predictor names.

Value

A single string, either "zero" or "mean".


Choose a point alpha for model plots

Description

Choose a point alpha for model plots

Usage

chooseModelPlotPointAlpha(observationCount)

Arguments

observationCount

Number of plotted observations.

Value

A numeric alpha value between 0 and 1.


Classify the effect scale described in a WMFM explanation

Description

Uses simple text heuristics to classify the scale on which the explanation describes the main effect. The intent is to identify the dominant scale used for coefficient interpretation, rather than unrelated numeric summaries such as model-fit percentages.

Usage

classifyEffectScaleClaim(text)

Arguments

text

Character scalar explanation text.

Details

The classifier is deliberately conservative about assigning "mixed_or_unclear". In particular, generic percentage language such as an R^2 statement should not by itself force a multiplicative label when the coefficient interpretation is otherwise clearly additive.

Value

One of "additive", "multiplicative", "probability_or_odds", "mixed_or_unclear", or "not_stated".


Classify a sentence-level explanation claim for legacy compatibility

Description

This helper now derives the legacy single-label claimType value from the multi-tag detector output used by the claim-mapping pipeline. New code should prefer detectExplanationClaimTags() and treat claimType as a compatibility field only.

Usage

classifyExplanationClaimType(
  claimText,
  audit,
  teachingSummary = NULL,
  model = NULL,
  sentenceIndex = NA_integer_,
  totalClaims = NA_integer_,
  claimTags = NULL
)

Arguments

claimText

Character scalar.

audit

A wmfmExplanationAudit object.

teachingSummary

Optional teaching summary object.

model

Optional fitted model object.

sentenceIndex

Integer-like sentence index.

totalClaims

Integer-like total number of claims.

claimTags

Optional character vector of detected claim tags.

Value

A single character string.


Classify likely source of metric disagreement

Description

Internal heuristic classifier for diagnose().

Usage

classifyMetricDisagreement(summaryDf)

Arguments

summaryDf

One-row summary data frame produced by buildMetricDiagnosisSummary().

Value

A single character string describing the likely disagreement class.


Classify CI output mode for a fitted model

Description

Classify CI output mode for a fitted model

Usage

classifyModelConfidenceIntervalPlan(model, mf)

Arguments

model

A fitted model object.

mf

Model frame for the fitted model.

Value

A list describing the chosen mode.


Classify the fitted model for model plots

Description

Classify the fitted model for model plots

Usage

classifyModelPlotFamily(model)

Arguments

model

A fitted model object or a wmfmModel object.

Value

A single character string describing the supported plot family.


Classify run-level score disagreement for heatmap plotting

Description

Converts paired run-level values from buildWmfmComparisonPairs() into a categorical disagreement label that can be used for a heatmap.

Usage

classifyWmfmScoreDisagreement(
  x,
  includeContinuous = FALSE,
  continuousBreaks = c(0.1, 0.35, 0.75)
)

Arguments

x

A wmfmScoreComparison object.

includeContinuous

Logical. Should continuous metrics be classified?

continuousBreaks

Numeric vector of length 3 giving cut points for the absolute difference bins used for continuous metrics.

Details

Classification rules are:

For ordinal metrics, ordered levels are taken from the registry stored on the comparison object.

Value

A data frame like x$pairData with an added disagreementClass column.


Clean generated explanation text before deterministic processing

Description

Removes simple LLM formatting artifacts that can leak into the visible explanation, such as leading Answer, ⁠Answer:⁠, or ⁠Answer -⁠ tokens. This is a deterministic surface cleanup step. It does not rewrite the statistical content of the explanation.

Usage

cleanExplanationText(text)

Arguments

text

Character vector of explanation text.

Value

A character vector with formatting artifacts removed.


Finish a WMFM progress tracker

Description

Internal helper that closes the text progress bar and returns timing summaries.

Usage

closeWmfmProgressTracker(tracker)

Arguments

tracker

Tracker environment created by newWmfmProgressTracker().

Value

A list with elapsed, average, and iteration timing summaries.


Build a natural language list from names

Description

Build a natural language list from names

Usage

collapseTeachingNames(x)

Arguments

x

Character vector.

Value

A single character string.


Compare WMFM objects

Description

Generic for comparing WMFM objects.

Usage

compare(x, y = NULL, ...)

Arguments

x

An object to compare.

y

Optional second object to compare.

...

Additional arguments passed to methods.

Value

Method specific comparison object.


Compare grading results for wmfmGrade objects

Description

Compares deterministic and llm grading either within a single wmfmGrade object that contains both methods, or across two separate wmfmGrade objects.

Usage

## S3 method for class 'wmfmGrade'
compare(x, y = NULL, methods = c("deterministic", "llm"), ...)

Arguments

x

A scored wmfmGrade object.

y

Optional second scored wmfmGrade object.

methods

Character vector of length 2 naming the methods to compare when comparing within a single object. Defaults to c("deterministic", "llm").

...

Unused. Included for S3 compatibility.

Value

An object of class wmfmGradeComparison.


Compare WMFM score results

Description

Compares score results either:

Usage

## S3 method for class 'wmfmScores'
compare(
  x,
  y = NULL,
  xMethod = NULL,
  yMethod = NULL,
  registry = getWmfmMetricRegistry(),
  ...
)

Arguments

x

A wmfmScores object.

y

Optional second wmfmScores object.

xMethod

Optional character string naming the method to use from x.

yMethod

Optional character string naming the method to use from y.

registry

Optional WMFM metric registry. Defaults to getWmfmMetricRegistry().

...

Unused. Included for S3 compatibility.

Details

The comparison summarizes agreement separately for binary, ordinal, and continuous score fields using the WMFM metric registry.

Value

An object of class wmfmScoreComparison.


Complete one-row newdata for CI predictions

Description

Ensures that all predictors referenced by the fitted model are present in the one-row newData passed to predict(), filling any omitted columns from simple base settings taken from the model frame. This keeps the CI builder robust when a row constructor only changes the focal predictors for a teaching quantity.

Usage

completeConfidenceIntervalNewData(
  model,
  newData,
  numericReference = NULL,
  mf = NULL,
  predictorNames = NULL
)

Arguments

model

A fitted model object.

newData

One-row new-data frame that may omit some predictors.

numericReference

Optional numeric reference choice. If omitted, it is chosen with chooseModelNumericReference().

mf

Optional model frame.

predictorNames

Optional predictor names.

Value

A completed one-row data frame.


Assemble a WMFM prompt from common pieces

Description

Assemble a WMFM prompt from common pieces

Usage

composeWmfmPrompt(
  context = c("summary", "contrast"),
  contextPayload,
  scaleRules = NULL
)

Arguments

context

"summary" or "contrast".

contextPayload

Character scalar giving the context-specific data block (model summary payload or contrast payload).

scaleRules

Optional character scalar with additional scale-specific rules (e.g., additive vs multiplicative vs odds multipliers).

Value

A character scalar prompt.


Compute a priority score for metric diagnosis

Description

Internal helper that ranks metrics for follow-up. Higher values indicate more systematic and potentially more important disagreement.

Usage

computeDiagnosisPriorityScore(summaryTable)

Arguments

summaryTable

A data frame of per-metric diagnosis summaries.

Value

A numeric vector of priority scores.


Compute a single contrast for factor-only models

Description

Computes an estimate and 95% confidence interval for a user-specified contrast in a factor-only model, optionally using robust (sandwich) variance estimators.

Usage

computeFactorOnlyContrast(
  model,
  newData,
  weights,
  ciType = c("standard", "sandwich"),
  hcType = c("HC0", "HC3"),
  level = 0.95
)

Arguments

model

A fitted model object, typically an lm or glm.

newData

A data frame whose rows define the conditions being contrasted.

weights

Numeric vector of contrast weights, one per row of newData.

ciType

One of "standard" or "sandwich".

hcType

Sandwich type passed to sandwich::vcovHC() (e.g. "HC0", "HC3").

level

Confidence level (default 0.95).

Details

The contrast is defined through a set of weights applied to the rows of newData. For example, a pairwise contrast between level A and level B can be represented with weights c(1, -1, 0, ..., 0).

For GLMs, inference is carried out on the linear predictor (link) scale and then back-transformed for interpretation when possible:

Value

A list with estimates and confidence intervals on the link scale and (when applicable) an interpreted scale.


Compute confidence intervals for fitted mean responses

Description

Computes pointwise confidence intervals for the fitted mean response evaluated at newData. These are confidence intervals for the conditional mean (i.e., the fitted line), not prediction intervals.

Usage

computeMeanCi(
  model,
  newData,
  ciType = "standard",
  hcType = "HC0",
  level = 0.95
)

Arguments

model

A fitted lm or glm object.

newData

A data frame of covariate values at which to evaluate the fitted mean.

ciType

Character string: "standard" or "sandwich".

hcType

Character string specifying the HC estimator (e.g. "HC0", "HC3"). Used only when ciType = "sandwich".

level

Confidence level for the intervals.

Details

For generalized linear models, intervals are computed on the link scale and transformed back to the response scale.

Robust (sandwich) confidence intervals are supported via vcovHC().

Value

A data frame containing newData plus columns fit, lower, and upper.


Compute quadratic weighted kappa for ordinal values

Description

Computes quadratic weighted kappa for two ordinal vectors that have already been converted to integer scores.

Usage

computeWeightedKappa(leftVec, rightVec)

Arguments

leftVec

Integer-like vector of left-side ordinal values.

rightVec

Integer-like vector of right-side ordinal values.

Value

A numeric scalar, or NA_real_ if it cannot be computed.


Compute the number of WMFM LLM grading jobs

Description

Internal helper for estimating how many LLM grading calls a request would make.

Usage

computeWmfmLlmJobCount(nExplanations, method, nLlm = 1L)

Arguments

nExplanations

Integer. Number of explanations.

method

Character. One of "deterministic", "llm", or "both".

nLlm

Integer. Number of repeated LLM gradings per explanation.

Value

Integer scalar.


Convert a model response to a plotting response

Description

Convert a model response to a plotting response

Usage

convertModelPlotResponse(response, plotFamily)

Arguments

response

Model response vector.

plotFamily

Model-plot family from classifyModelPlotFamily().

Value

A list with values, breaks, and labels.


Count sentences in text

Description

Count sentences in text

Usage

countWmfmSentences(x)

Arguments

x

Character text.

Value

Integer.


Count words in text

Description

Count words in text

Usage

countWmfmWords(x)

Arguments

x

Character text.

Value

Integer.


Create app server observer dependencies

Description

Create app server observer dependencies

Usage

createAppServerObserverDependencies(input, session, rv, modelFit)

Arguments

input

Shiny input object.

session

Shiny session object.

rv

App reactive values object.

modelFit

Reactive value containing the fitted model.

Value

A list of helper functions used by observer registration code.


Create app server reactive state

Description

Create app server reactive state

Usage

createAppServerReactiveState()

Value

A list containing the app server reactive values and reactive holders.


Create derived-variable transformation metadata

Description

Records the expression used to create a derived variable without changing how the expression is evaluated. The metadata is intentionally conservative: it preserves the original expression and only labels transformations that WMFM can recognise safely for later explanation and back-transformation work.

Usage

createVariableTransformationRecord(
  variable,
  rhs,
  data = NULL,
  expressionText = NULL,
  sourceVariables = NULL,
  transformationType = NULL,
  inverseType = NULL,
  transformationParameters = NULL,
  createdFrom = "addDerivedVariable"
)

Arguments

variable

Character name of the derived variable.

rhs

Parsed right-hand-side expression used to create the variable.

data

Data frame available when the variable was created.

expressionText

Optional original assignment text entered by the user.

sourceVariables

Optional character vector of source variable names.

transformationType

Optional recognised transformation label.

inverseType

Optional inverse transformation label.

transformationParameters

Optional list of transformation parameters.

createdFrom

Character label for the source workflow.

Value

A list with class wmfmVariableTransformation.


Deparse an expression to one line

Description

Deparse an expression to one line

Usage

deparseOneLine(expr)

Arguments

expr

Expression to deparse.

Value

Character scalar.


Derive paired metric comparison data directly from wmfmScores

Description

Internal helper that reconstructs run-level paired deterministic and LLM scores for a single metric from a wmfmScores object.

Usage

deriveMetricComparisonDataFromScores(scores, metric)

Arguments

scores

A wmfmScores object.

metric

A single metric name.

Value

A data frame with columns runId, detValue, and llmValue.


Describe a field for a WMFM object

Description

S3 generic for describing fields stored in WMFM objects.

Usage

describeField(x, field, ...)

Arguments

x

A WMFM object.

field

Character scalar naming the field to describe. This may be a canonical field name, a recognised alias, or a pretty plot label if the underlying field registry supports it.

...

Additional arguments passed to methods.

Value

Method-specific description output.


Describe a field for a WMFM runs object

Description

Describes a field that is present in a wmfmRuns object. The method accepts canonical field names, recognised aliases, and supported pretty plot labels. It validates that the resolved canonical field is actually stored in the raw run records before delegating to describeWmfmField().

Usage

## S3 method for class 'wmfmRuns'
describeField(
  x,
  field,
  format = c("text", "list", "data.frame"),
  includeExamples = TRUE,
  includeAliases = TRUE,
  ...
)

Arguments

x

A wmfmRuns object.

field

Character scalar naming the field to describe.

format

Character. One of "text", "list", or "data.frame".

includeExamples

Logical. Should examples be included?

includeAliases

Logical. Should recognised aliases be included?

...

Unused. Included for S3 compatibility.

Value

The result of describeWmfmField() in the requested format. This is a character scalar for format = "text", a named list for format = "list", or a one-row data.frame for format = "data.frame".


Describe a field for a WMFM scores object

Description

Describes a field that is present in a wmfmScores object. The method accepts canonical field names, recognised aliases, and supported pretty plot labels. It validates that the resolved canonical field is actually stored in the scored records before delegating to describeWmfmField().

Usage

## S3 method for class 'wmfmScores'
describeField(
  x,
  field,
  format = c("text", "list", "data.frame"),
  includeExamples = TRUE,
  includeAliases = TRUE,
  ...
)

Arguments

x

A wmfmScores object.

field

Character scalar naming the field to describe.

format

Character. One of "text", "list", or "data.frame".

includeExamples

Logical. Should examples be included?

includeAliases

Logical. Should recognised aliases be included?

...

Unused. Included for S3 compatibility.

Value

The result of describeWmfmField() in the requested format. This is a character scalar for format = "text", a named list for format = "list", or a one-row data.frame for format = "data.frame".


Describe WMFM config location status

Description

Returns path and accessibility metadata for the local WMFM non-secret configuration file.

Usage

describeWmfmConfigLocation()

Value

Named list containing config file location details.


Describe a WMFM field

Description

Prints a human-readable description of a field used in the WMFM workflow. This is intended to help interpret the raw run fields, judged fields, and aggregate score fields that appear in WMFM objects and related plots.

Usage

describeWmfmField(
  field,
  format = c("text", "list", "data.frame"),
  includeExamples = TRUE,
  includeAliases = TRUE
)

Arguments

field

Character scalar naming the field to describe. This may be a canonical field name, a recognised alias, or one of the pretty labels shown on the heatmap x-axis.

format

Character. One of "text", "list", or "data.frame". The default "text" prints a formatted character vector with cat() and returns that vector invisibly. "list" returns the underlying structured description. "data.frame" returns a one-row data frame.

includeExamples

Logical. Should examples be included in the returned output?

includeAliases

Logical. Should recognised aliases be included in the returned output?

Details

The function accepts:

By default the function prints a formatted explanation to the console using cat() and returns the underlying character vector invisibly. This makes it convenient for interactive use while still allowing the text to be captured programmatically when needed.

For judged fields scored on a 0/1/2 scale, the usual interpretation is:

0

Poor, missing, inappropriate, or clearly problematic.

1

Partly adequate, weak, borderline, or unclear.

2

Appropriate, clear, or well handled.

Value

If format = "text", a formatted character vector returned invisibly after being printed to the console. Otherwise a named list or a one-row data frame describing the requested field.

Examples

describeWmfmField("interactionEvidenceAppropriate")
describeWmfmField("Direction claim")
describeWmfmField("CI mention")
describeWmfmField("overallScore", format = "list")

Describe WMFM provider status

Description

Returns deterministic, printable provider metadata and credential status without including secret values.

Usage

describeWmfmProviderStatus()

Value

Named list with providers and configuredProviders entries.


Detect the teaching framework for CI display metadata

Description

Detect the teaching framework for CI display metadata

Usage

detectConfidenceIntervalModelFramework(model)

Arguments

model

A fitted model object.

Value

A character scalar.


Detect whether a model contains factor predictors

Description

Detect whether a model contains factor predictors

Usage

detectDeveloperScoringFactorPredictors(model)

Arguments

model

A fitted model object.

Value

Logical scalar.


Detect whether a developer scoring model has interaction terms

Description

Detect whether a developer scoring model has interaction terms

Usage

detectDeveloperScoringInteractionTerms(model)

Arguments

model

A fitted model object.

Value

Logical scalar.


Detect implicit comparison language in WMFM explanations

Description

Detects comparison structure that may not use explicit phrases such as "compared with" or "relative to", but still clearly expresses a contrast between groups or conditions.

Usage

detectImplicitComparison(text)

Arguments

text

Character scalar explanation text.

Details

This helper is intended to support extraction in buildWmfmRunRecord(), especially for explanations that use constructions such as:

The function looks for comparative wording together with at least one structural cue indicating contrast or grouping.

Value

Logical scalar. TRUE if implicit comparison language is detected, otherwise FALSE.


Detect numeric range expressions (implicit uncertainty)

Description

Detects expressions like "from 3.0 to 4.0" or "between 3.8 and 12.2", which indicate uncertainty without explicitly mentioning confidence intervals.

Usage

detectRangeExpression(text)

Arguments

text

Character string

Value

Logical


Detect a response transformation from an expression string

Description

Attempts to detect a common response transformation from a text expression. This is intended for lightweight UI labeling (e.g., "log", "sqrt") rather than for full parsing of arbitrary R code.

Usage

detectRespTransform(expr)

Arguments

expr

A character string containing an expression.

Details

Recognised transformations (returned values):

If no recognised transformation is detected, returns NULL.

Value

A single character string naming the detected transformation, or NULL if none is detected.


Detect pattern in text

Description

Detect pattern in text

Usage

detectWmfmPattern(x, pattern)

Arguments

x

Character text.

pattern

Regex pattern.

Value

Logical.


Diagnose scoring disagreement

Description

S3 generic for diagnosing disagreement between deterministic and LLM scoring outputs.

Usage

diagnose(x, ...)

Arguments

x

An object to diagnose.

...

Additional arguments passed to methods.

Value

Method-specific diagnosis output.


Diagnose disagreement for a WMFM scores object

Description

Diagnoses disagreement between deterministic and LLM scoring for either a single metric or all available metrics.

Usage

## S3 method for class 'wmfmScores'
diagnose(x, metric = NULL, runs = NULL, cmp = NULL, maxExamples = 5, ...)

Arguments

x

A wmfmScores object.

metric

Optional single metric name. If NULL, diagnose all comparable metrics.

runs

Optional wmfmRuns object or compatible run container used to provide explanation text and claim-level context.

cmp

Optional wmfmScoreComparison object.

maxExamples

Maximum number of flagged disagreement examples to retain for each metric diagnosis.

...

Reserved for future method-specific arguments.

Details

When metric is supplied, the function returns a wmfmMetricDiagnosis object. When metric = NULL, it returns a wmfmScoresDiagnosis object summarising all metrics that can be compared.

Value

A wmfmMetricDiagnosis or wmfmScoresDiagnosis object.


Diagnose deterministic explanation surface processing

Description

Runs the deterministic explanation surface processor in debug mode and records surface-language issues before and after processing. This helper is intended for developer review and tests. It does not change the explanation pipeline and it does not make statistical claims.

Usage

diagnoseExplanationSurfaceProcessing(text, audit = NULL)

Arguments

text

Character vector of explanation text.

audit

Optional explanation audit object passed to postProcessExplanationText().

Value

A list with original text, processed text, applied rule names, detected issues before processing, detected issues after processing, and the number of unresolved issues.

Examples

diagnoseExplanationSurfaceProcessing(
  "A one-unit rise multiplies the expected count by 0.21."
)

Draw the fitted-model plot (data + fitted line / fitted means)

Description

Extracts the plotting logic from the Shiny renderPlot() block and returns either:

Usage

drawModelPlot(
  model,
  ciType = "standard",
  hcType = "HC0",
  showCi = FALSE,
  level = 0.95
)

Arguments

model

A fitted lm or glm object.

ciType

Confidence interval type. Typically "standard" or "sandwich". For factor-only models, this is passed through to makeFactorOnlyPlot().

hcType

Robust (sandwich) type used when ciType = "sandwich". Common values include "HC0" and "HC3".

showCi

Logical; if TRUE, draw confidence bands around fitted line(s) when a numeric-predictor plot is available.

level

Confidence level for intervals. Default is 0.95.

Details

This function expects the helper functions isFactorOnlyModel() and makeFactorOnlyPlot() to exist in your app codebase (as they do in your current server implementation).

If the model contains exactly one numeric predictor, the function draws the raw data and a fitted line. Optionally, it can add confidence bands around the fitted line(s). Bands can be computed using either the model-based standard errors or sandwich/robust standard errors.

Value

A ggplot object when a numeric-predictor plot is available, or whatever makeFactorOnlyPlot() returns for factor-only models. In cases where plotting is not applicable, the function draws an informative message using base graphics and returns invisible().


Edit the WMFM local configuration file

Description

Opens the WMFM user configuration file in the default R editor. If the configuration directory or file does not yet exist, they are created first.

Usage

editWmfmConfig(editor = utils::file.edit)

Arguments

editor

Function used to open the configuration file. Defaults to utils::file.edit(). This argument is mainly provided so tests can avoid opening an editor.

Value

Invisibly returns the path to the configuration file.


Build an empty response back-transformation payload

Description

Build an empty response back-transformation payload

Usage

emptyResponseBackTransformationPayload(
  mode,
  status,
  responseVariable = "",
  originalVariable = "",
  transformationType = "",
  inverseType = "",
  note = ""
)

Arguments

mode

Response-transformation handling mode.

status

Availability status.

responseVariable

Derived response variable name.

originalVariable

Original response variable name.

transformationType

Transformation type label.

inverseType

Inverse type label.

note

Human-readable availability note.

Value

A named list.


Build an empty response back-transformation table

Description

Build an empty response back-transformation table

Usage

emptyResponseBackTransformationTable()

Value

A zero-row data frame with stable columns.


Build an empty variable-transformation audit table

Description

Build an empty variable-transformation audit table

Usage

emptyVariableTransformationAuditTable()

Value

A zero-row data frame with the stable audit columns.


Enforce the WMFM LLM grading job guard

Description

Internal helper that prevents unexpectedly large LLM grading requests unless the user explicitly opts in.

Usage

enforceWmfmLlmJobGuard(
  totalLlmCalls,
  nExplanations,
  nLlm,
  confirmLargeLlmJob = FALSE,
  maxLlmJobsWithoutConfirmation = 20L
)

Arguments

totalLlmCalls

Integer. Total planned LLM calls.

nExplanations

Integer. Number of explanations.

nLlm

Integer. Number of repeated LLM gradings per explanation.

confirmLargeLlmJob

Logical. Whether to allow large requests.

maxLlmJobsWithoutConfirmation

Integer. Maximum number of LLM calls allowed without explicit confirmation.

Value

Invisibly returns TRUE when the request is allowed.


Enrich a CI table with framework-aware display metadata

Description

Adds internal columns that the app can use to filter and present confidence-interval rows by model framework, teaching role, and display scale. This keeps the calculation layer stable while making the returned table easier to drive from UI controls.

Usage

enrichConfidenceIntervalDisplayTable(model, ciTable)

Arguments

model

A fitted model object.

ciTable

A confidence-interval display table.

Value

A data frame with additional metadata columns.


Ensure anchored factor comparisons appear in explanation text

Description

Adds a deterministic anchored factor-comparison sentence when a fitted linear model contains both a factor predictor and a numeric predictor, but the LLM explanation omitted the anchored fitted values needed for a student-facing interpretation.

Usage

ensureAnchoredFactorComparisonText(text, model)

Arguments

text

Character scalar explanation text.

model

A fitted model object.

Value

A character scalar.


Ensure that the s20x package is installed

Description

Confirms that the teaching-data dependency s20x is installed before app features that rely on package datasets continue.

Usage

ensureS20xInstalled()

Value

Invisibly returns TRUE when s20x is installed.


Explain why a WMFM field received its score for a specific run

Description

Provides a human-readable explanation of how a particular field (claim, judged field, or score) was derived for a given run.

Usage

explainWmfmFieldScore(field, x, runIndex = 1L)

Arguments

field

Character. Field name or plotted label (e.g. "Overclaim", "Interaction evidence", "overallScore").

x

A wmfmRuns object, typically returned by runExample(), or a data.frame containing run records.

runIndex

Integer. Which run to explain.

Details

This function works directly with a repeated-runs object and will internally call scoreWmfmRepeatedRuns() if needed.

Value

Invisibly returns a character vector explanation. Also prints to console using cat().


Extract the outcome level named in a CI quantity label

Description

Extract the outcome level named in a CI quantity label

Usage

extractConfidenceIntervalOutcomeLevel(quantity)

Arguments

quantity

A quantity label.

Value

A character scalar.


Extract developer scoring interaction metadata

Description

Extract developer scoring interaction metadata

Usage

extractDeveloperScoringInteractionInfo(model)

Arguments

model

A fitted model object.

Value

A list with interaction term metadata.


Extract contextual run-level information for metric diagnosis

Description

Internal helper for diagnose() that attempts to recover explanation text and diagnostic context. Preference is given to the original runs object, because wmfmScores retains score fields but not the full raw explanation record.

Usage

extractMetricDiagnosisContext(scores, metric, runs = NULL)

Arguments

scores

A wmfmScores object.

metric

A single metric name.

runs

Optional wmfmRuns object or compatible list/data.frame.

Value

A data frame keyed by runId, or NULL.


Extract a noun phrase for the response variable from dataset documentation

Description

Attempts to infer a short human-friendly description of the response variable (e.g. "exam score", "weekly income", "probability of success") from a plain-text dataset help/documentation string.

Usage

extractResponseNounPhraseFromDoc(dsDoc, responseVar)

Arguments

dsDoc

Character scalar. Plain-text dataset documentation.

responseVar

Character scalar. Name of the response variable.

Details

The extraction is heuristic: it looks for common patterns such as:

If nothing reliable is found, it returns NULL.

Value

Character scalar noun phrase, or NULL if not found.


Extract source variables from a derived-variable expression

Description

Extract source variables from a derived-variable expression

Usage

extractSourceVariables(rhs, data)

Arguments

rhs

Parsed right-hand-side expression.

data

Data frame available when the expression was created.

Value

Character vector of data-column names used by rhs.


Extract text from WMFM output objects

Description

Converts model explanation or equation objects into plain text.

Usage

extractWmfmText(x)

Arguments

x

Object returned by WMFM functions.

Value

Character string.


Fill missing predictor columns in new data using the model's training frame

Description

Fill missing predictor columns in new data using the model's training frame

Usage

fillMissingPredictors(model, newData)

Arguments

model

A fitted model object with a model frame (e.g., lm/glm).

newData

A data frame intended for prediction/design-matrix construction.

Value

newData with any missing predictor columns added, using values from the first row of the model frame and preserving factor levels.


Filter ANOVA/deviance rows for display

Description

Filter ANOVA/deviance rows for display

Usage

filterAnovaTermRows(
  anovaTable,
  adjustmentVariables,
  showAdjustmentTerms = FALSE
)

Arguments

anovaTable

ANOVA table object.

adjustmentVariables

Character vector of adjustment-variable names.

showAdjustmentTerms

Logical; when TRUE no rows are filtered.

Value

Filtered ANOVA table.


Filter confidence-interval rows for adjustment-safe display

Description

Filter confidence-interval rows for adjustment-safe display

Usage

filterConfidenceIntervalRows(ciTable, adjustmentVariables)

Arguments

ciTable

Confidence-interval table with a quantity column.

adjustmentVariables

Character vector of adjustment-variable names.

Value

Confidence-interval table with adjustment-related rows removed.


Filter explanation quantity payload by adjustment-variable policy

Description

Filter explanation quantity payload by adjustment-variable policy

Usage

filterExplanationCoefficientPayloadByAdjustmentPolicy(quantityTable, model)

Arguments

quantityTable

Quantity table prepared for explanation prompting.

model

A fitted model object.

Value

Filtered quantity table.


Filter explanation payload rows for adjustment-variable narrative safety

Description

Filter explanation payload rows for adjustment-variable narrative safety

Usage

filterExplanationPayloadForAdjustmentVariables(
  payloadTable,
  model,
  labelColumns = c("quantity", "label", "term", "comparison", "group")
)

Arguments

payloadTable

Data frame payload intended for LLM interpretation.

model

A fitted model object.

labelColumns

Character vector of payload columns to inspect.

Value

A filtered data frame that excludes adjustment-related narrative axes.


Filter coefficient matrix rows for summary display

Description

Filter coefficient matrix rows for summary display

Usage

filterSummaryCoefficientRows(
  coefficientsMatrix,
  adjustmentVariables,
  showAdjustmentCoefficients = FALSE
)

Arguments

coefficientsMatrix

Matrix from summary(model)$coefficients.

adjustmentVariables

Character vector of adjustment-variable names.

showAdjustmentCoefficients

Logical; when TRUE no rows are filtered.

Value

Coefficient matrix filtered for display.


Detect remaining non-JSON-safe developer scoring values

Description

Detect remaining non-JSON-safe developer scoring values

Usage

findDeveloperScoringJsonUnsafePaths(
  x,
  path = "payload",
  depth = 0L,
  maxDepth = 12L
)

Arguments

x

Object to inspect.

path

Character path used in diagnostics.

depth

Current recursion depth.

maxDepth

Maximum recursion depth.

Value

Character vector of problematic paths.


Find remaining surface-language issues in explanation text

Description

Scans explanation text for recurring surface-language issues that the deterministic post-processing layer is intended to control. This helper is diagnostic only: it does not rewrite the text and it does not make any statistical claims.

Usage

findExplanationSurfaceIssues(
  text,
  issueTypes = c("modelMechanismLanguage", "unitChangePhrasing", "verbalFractions",
    "confidenceIntervalTerminology", "longSentencePatterns")
)

Arguments

text

Character vector of explanation text.

issueTypes

Character vector naming issue groups to scan for. Defaults to all supported issue groups.

Value

A data frame with one row per detected issue and columns element, issueType, pattern, and matchedText.


Find a selected confidence-interval detail record

Description

Find a selected confidence-interval detail record

Usage

findModelConfidenceIntervalDetail(ciData, selectedLabel)

Arguments

ciData

Output from buildModelConfidenceIntervalData().

selectedLabel

Selected row label from the UI.

Value

A single detail record or NULL.


Finish a simple command-line stage tracker

Description

Finish a simple command-line stage tracker

Usage

finishWmfmCliStageTracker(cliTracker)

Arguments

cliTracker

A tracker created by newWmfmCliStageTracker().

Value

Invisibly returns a list with total timing information.


Return the first source variable in a transformation record

Description

Return the first source variable in a transformation record

Usage

firstSourceVariable(record)

Arguments

record

A transformation record.

Value

Character scalar.


Format a numeric value to three significant figures

Description

Formats numeric values for user-facing display using approximately three significant figures, suppressing scientific notation where possible.

Usage

fmt3(x)

Arguments

x

A numeric vector.

Value

A character vector of the same length as x.


Format bad explanation output for user-facing return

Description

Format bad explanation output for user-facing return

Usage

formatBadExplanationOutput(parsed, labelErrors = FALSE)

Arguments

parsed

A validated parsed response.

labelErrors

Logical. Should metadata be returned?

Value

A character scalar, a named character vector, or a named list.


Format a base setting for display

Description

Format a base setting for display

Usage

formatBaseSettingForConfidenceIntervals(mf, baseRow, varName, numericReference)

Arguments

mf

Model frame.

baseRow

One-row base data frame.

varName

Variable name.

numericReference

Numeric reference choice.

Value

A character scalar.


Format an odds label for a binomial model

Description

Format an odds label for a binomial model

Usage

formatBinomialOddsLabel(
  model,
  outcome = c("success", "failure"),
  indexed = FALSE
)

Arguments

model

A fitted binomial model.

outcome

Either "success" or "failure".

indexed

Logical. If TRUE, append ⁠_i⁠ to the response name.

Value

A character scalar such as "Odds(response = success)".


Format a probability label for a binomial model

Description

Format a probability label for a binomial model

Usage

formatBinomialProbabilityLabel(
  model,
  outcome = c("success", "failure"),
  indexed = FALSE
)

Arguments

model

A fitted binomial model.

outcome

Either "success" or "failure".

indexed

Logical. If TRUE, append ⁠_i⁠ to the response name.

Value

A character scalar such as "Pr(response = success)".


Format a number for CI display text

Description

Format a number for CI display text

Usage

formatConfidenceIntervalNumber(x)

Arguments

x

A numeric value.

Value

A character scalar.


Format developer scoring duration

Description

Format developer scoring duration

Usage

formatDeveloperScoringDuration(seconds)

Arguments

seconds

Numeric scalar giving a duration in seconds.

Value

A compact character scalar.


Format a numeric value for deterministic equation output

Description

Formats a numeric coefficient for student-facing deterministic equation rendering using fixed decimal places and ordinary decimal notation.

Usage

formatEquationNumber(x, digits = 2)

Arguments

x

A numeric scalar.

digits

Integer number of decimal places. Defaults to 2.

Value

A character scalar.


Format an anchor value for student-facing explanation text

Description

Format an anchor value for student-facing explanation text

Usage

formatExplanationAnchor(anchor, sigDigits = 3)

Arguments

anchor

Numeric vector.

sigDigits

Number of significant figures to keep. Defaults to 3.

Value

A character vector.


Format explanation-anchor metadata for display

Description

Format explanation-anchor metadata for display

Usage

formatExplanationAnchorInfo(anchorInfo)

Arguments

anchorInfo

Anchor metadata from chooseExplanationAnchor().

Value

A data frame with raw and displayed anchor values.


Format a confidence interval for student-facing explanation text

Description

Applies the same significant-figures rule to an estimate and its confidence interval bounds so that all three values are visually consistent.

Usage

formatExplanationConfidenceInterval(
  estimate,
  lower,
  upper,
  confidenceLevel = 0.95,
  sigDigits = 2
)

Arguments

estimate

Numeric scalar estimate.

lower

Numeric scalar lower interval bound.

upper

Numeric scalar upper interval bound.

confidenceLevel

Numeric scalar confidence level. Defaults to 0.95.

sigDigits

Number of significant figures to keep. Defaults to 2.

Value

A named list with formatted estimate, lower, upper, level, and text.


Format a multiplicative change for student-facing explanation text

Description

Format a multiplicative change for student-facing explanation text

Usage

formatExplanationMultiplier(multiplier, sigDigits = 2)

Arguments

multiplier

Numeric vector.

sigDigits

Number of significant figures to keep. Defaults to 2.

Value

A character vector.


Format a number for student-facing explanation text

Description

Formats numeric values using a small significant-figures rule for prose and prompt inputs. This helper is intended for explanation quantities rather than developer-facing coefficient tables.

Usage

formatExplanationNumber(x, sigDigits = 2)

Arguments

x

Numeric vector.

sigDigits

Number of significant figures to keep. Defaults to 2.

Value

A character vector with one formatted value per input value.


Format odds for student-facing explanation text

Description

Formats odds as odds rather than plain decimals. Ordinary odds are displayed as odds:1; very small odds are displayed as 1:N.

Usage

formatExplanationOdds(odds, sigDigits = 2, smallThreshold = 0.1)

Arguments

odds

Numeric vector of non-negative odds.

sigDigits

Number of significant figures to keep for ordinary odds. Defaults to 2.

smallThreshold

Positive numeric threshold below which odds are shown as 1:N. Defaults to 0.1.

Value

A character vector.


Format a probability for student-facing explanation text

Description

Formats probabilities as percentages by default, using whole percentages for ordinary values and simple boundary text for very small or very large non-zero probabilities.

Usage

formatExplanationProbability(probability, asPercent = TRUE, sigDigits = 2)

Arguments

probability

Numeric vector of probabilities on the 0 to 1 scale.

asPercent

Logical scalar. If TRUE, return percentages. If FALSE, return probabilities using formatExplanationNumber().

sigDigits

Number of significant figures to keep when asPercent is FALSE.

Value

A character vector.


Format a named explanation quantity

Description

Routes common explanation quantities through the deterministic formatting helper that matches their interpretation scale.

Usage

formatExplanationQuantity(
  value,
  quantityType = c("number", "probability", "odds", "multiplier", "anchor"),
  sigDigits = 2
)

Arguments

value

Numeric vector.

quantityType

Character scalar. One of number, probability, odds, multiplier, or anchor.

sigDigits

Number of significant figures to keep where applicable.

Value

A character vector.


Format an estimate and confidence interval with enough displayed precision

Description

Starts with the usual explanation-quantity formatter, then increases the number of significant figures when rounding would make the estimate equal to an interval bound, or make both interval bounds display identically. This keeps narrow intervals informative without making ordinary intervals unnecessarily precise.

Usage

formatExplanationQuantityInterval(
  estimate,
  lower,
  upper,
  quantityType = c("number", "probability", "odds", "multiplier", "anchor"),
  sigDigits = 2,
  maxSigDigits = 4
)

Arguments

estimate

Numeric scalar estimate.

lower

Numeric scalar lower interval bound.

upper

Numeric scalar upper interval bound.

quantityType

Character scalar passed to formatExplanationQuantity().

sigDigits

Starting number of significant figures. Defaults to 2.

maxSigDigits

Maximum number of significant figures to try. Defaults to 4.

Value

A named list with formatted estimate, lower, and upper values.


Format a numeric summary value for display

Description

Format a single numeric value for display in a summary table using a significant-digits rule that aims to keep only the digits that carry useful information. Integer values are shown without decimal places. Non-integer values are rounded to a chosen number of significant digits.

Usage

formatSummaryValue(x, sigDigits = 3)

Arguments

x

A numeric scalar to format.

sigDigits

Integer. The number of significant digits to keep for non-integer values. Defaults to 3.

Details

This is useful for compact summary tables where fixed decimal places can produce distracting trailing zeros, for example showing 11 rather than 11.000.

Value

A character scalar. Returns NA_character_ when x has length 0 or is NA.

Examples

formatSummaryValue(11)
formatSummaryValue(52.8767)
formatSummaryValue(68.5)
formatSummaryValue(0.012345, sigDigits = 2)


Format variable-transformation parameters for audit display

Description

Format variable-transformation parameters for audit display

Usage

formatVariableTransformationParameters(parameters = list())

Arguments

parameters

A named list of transformation parameters.

Value

Character scalar.


Format elapsed time for WMFM progress messages

Description

Converts elapsed time in seconds to a compact human-readable string for console progress reporting.

Usage

formatWmfmElapsedTime(seconds)

Arguments

seconds

Numeric. Elapsed time in seconds.

Value

Character string such as "12s", "3m 08s", or "1h 02m 15s".


Format a deterministic equation table for display

Description

Converts a wmfmEquationTable into a stable plain-text representation for console output, text extraction, and downstream grading records.

Usage

formatWmfmEquationTableLines(x, includeCondition = TRUE)

Arguments

x

A wmfmEquationTable object.

includeCondition

Logical. Should condition labels be included? Defaults to TRUE.

Value

Character vector of formatted display lines.


WMFM progress and timing helpers

Description

Internal helpers for tracking elapsed time, average iteration time, and estimated time remaining while repeated WMFM tasks are running.

Usage

formatWmfmSeconds(seconds)

Arguments

seconds

Numeric scalar giving elapsed seconds.

Value

For formatWmfmSeconds(), a length-one character string.


Test whether two formula expressions are textually equivalent

Description

Test whether two formula expressions are textually equivalent

Usage

formulaExpressionsMatch(first, second)

Arguments

first

Character scalar expression text.

second

Character scalar expression text.

Value

Logical scalar.


Generate one or more deliberately bad model explanations

Description

Generic for generating plausible but intentionally flawed explanations from a fitted model.

Usage

generateBadExplanation(x, ...)

## S3 method for class 'wmfmModel'
generateBadExplanation(
  x,
  explanation = NULL,
  type = "auto",
  severity = c("subtle", "moderate", "severe"),
  n = 1,
  mixTypes = FALSE,
  labelErrors = FALSE,
  provider = NULL,
  showProgress = interactive(),
  showTiming = interactive(),
  ...
)

Arguments

x

An object.

...

Additional arguments reserved for future use.

explanation

Optional character scalar giving the base good explanation. If NULL, x$explanation is used.

type

Character vector of bad explanation types, or "auto".

severity

Character scalar. One of "subtle", "moderate", or "severe".

n

Integer. Number of bad explanations to generate.

mixTypes

Logical. Should individual explanations combine multiple bad types?

labelErrors

Logical. Should the return value include error labels and severity metadata?

provider

Optional chat provider. If NULL, uses getChatProvider().

showProgress

Logical. Should command-line progress messages be shown? Defaults to interactive().

showTiming

Logical. Should command-line timing summaries be shown? Defaults to interactive().

Value

Method-dependent output.

If n = 1 and labelErrors = FALSE, a character scalar.

If n > 1 and labelErrors = FALSE, a named character vector.

If labelErrors = TRUE, a named list containing explanations, error type labels, and severity labels.

Methods (by class)


Generate bad explanations with an LLM

Description

Generate bad explanations with an LLM

Usage

generateBadExplanationWithLlm(
  x,
  baseExplanation,
  plan,
  chat,
  showProgress = FALSE
)

Arguments

x

A wmfmModel object.

baseExplanation

Character scalar giving the good explanation.

plan

A plan object produced by buildBadExplanationPlan().

chat

A chat provider object with a callable ⁠$chat()⁠ method.

showProgress

Logical. Should a command-line status message be shown before awaiting the LLM response?

Value

Raw character response from the LLM.


Build deterministic explanation scaffold for adjustment workflows

Description

Build deterministic explanation scaffold for adjustment workflows

Usage

getAdjustedPrimaryEffectSummary(model, mf = NULL)

Arguments

model

A fitted model object.

mf

Optional model frame.

Value

A character scalar containing a deterministic adjusted-effect summary for primary variables, or an empty string when a safe summary cannot be constructed.


Build onchange JavaScript for inline adjustment checkboxes

Description

Build onchange JavaScript for inline adjustment checkboxes

Usage

getAdjustmentCheckboxOnChangeScript()

Value

Character scalar JavaScript snippet.


Get adjustment-related terms for explanation-policy omission metadata

Description

Get adjustment-related terms for explanation-policy omission metadata

Usage

getAdjustmentRelatedTermsForExplanation(model, mf = NULL)

Arguments

model

A fitted model object.

mf

Optional model frame.

Value

Character vector of model terms involving adjustment variables.


Get explanation-role metadata for primary and adjustment predictors

Description

Uses fitted-model predictor names plus Stage 20 adjustment metadata to build a consistent role split for explanation and prompt helpers.

Usage

getAdjustmentRoleMetadataForExplanation(model, mf = NULL)

Arguments

model

A fitted model object.

mf

Optional model frame.

Value

A list with primaryPredictors, adjustmentPredictors, and hasAdjustments fields.


Get explanation findings that remain narratively interpretable

Description

Get explanation findings that remain narratively interpretable

Usage

getAllowedExplanationFindings(model, mf = NULL)

Arguments

model

A fitted model object.

mf

Optional model frame.

Value

Character vector of allowed finding variables.


Get bad explanation types compatible with a WMFM model

Description

Get bad explanation types compatible with a WMFM model

Usage

getAvailableBadExplanationTypes(x)

Arguments

x

A wmfmModel object.

Value

A character vector of compatible bad explanation types.


Get success and failure labels for a binomial response

Description

For a two-level factor response, R's binomial GLM parameterisation targets the second factor level as the fitted probability. This helper extracts readable labels for the success and failure outcomes so the app can write labels using the fitted response name and outcome levels rather than a generic p.

Usage

getBinomialOutcomeLabels(model)

Arguments

model

A fitted model object.

Value

A list with successLabel, failureLabel, and responseName.


Create a safe chat provider for WMFM

Description

Constructs a chat provider used by WMFM, choosing between an Ollama-based provider and an Anthropic Claude-based provider.

Usage

getChatProvider(backend = NULL, model = NULL, ollamaThinkLow = NULL)

Arguments

backend

Character scalar giving the backend to use. Supported values are "ollama" and "claude".

model

Optional Ollama model name to use when backend = "ollama".

ollamaThinkLow

Logical; when TRUE, request low thinking effort from Ollama models that support the think parameter.

Details

The backend is selected via the backend argument, or if omitted, from the wmfm.chat_backend option. When backend = "ollama", the Ollama model can be supplied explicitly via model; otherwise getOption("wmfm.ollama_model") is used, with a default of "gpt-oss".

Value

A chat provider object created by ellmer::chat_ollama() or ellmer::chat_anthropic(), or a dummy provider object (class "wmfm_dummy_chat_provider") that throws a user-friendly error on use.


Get the CI critical value for a fitted model

Description

Get the CI critical value for a fitted model

Usage

getConfidenceIntervalCriticalValue(model, level)

Arguments

model

A fitted model object.

level

Confidence level.

Value

A numeric scalar.


Build explanation narrative policy metadata for adjustment workflows

Description

Build explanation narrative policy metadata for adjustment workflows

Usage

getExplanationNarrativePolicy(model, mf = NULL)

Arguments

model

A fitted model object.

mf

Optional model frame.

Value

A list describing allowed and forbidden narrative axes.


Extract a teaching-summary confidence level percent

Description

Extract a teaching-summary confidence level percent

Usage

getExplanationTeachingConfidenceLevelPercent(audit, defaultLevel = 0.95)

Arguments

audit

A wmfmExplanationAudit object.

defaultLevel

Default confidence level when audit metadata is missing or invalid.

Value

A single numeric confidence percent.


Extract a teaching-summary confidence note

Description

Extract a teaching-summary confidence note

Usage

getExplanationTeachingConfidenceNote(audit)

Arguments

audit

A wmfmExplanationAudit object.

Value

A single character string.


Identify factor-only predictors in a fitted model

Description

Extracts the predictor variables from a fitted model that are factors, excluding the response variable. Predictor names are determined from the model terms and matched against the columns in the supplied model frame.

Usage

getFactorOnlyPredictors(m, mf)

Arguments

m

A fitted model object (e.g., from lm() or glm()).

mf

A model frame corresponding to m, typically obtained via model.frame(m).

Details

This helper is primarily used to identify categorical predictors that are eligible for factor-only contrasts.

Value

A character vector of predictor names that are factors in mf. Returns an empty character vector if no such predictors exist.


Extract factor predictors from a fitted model

Description

Returns the names of predictor variables in a fitted model that are factors in the supplied data set.

Usage

getFactorPredictors(model, data)

Arguments

model

A fitted model object (e.g. lm, glm).

data

A data frame containing the variables used to fit the model.

Value

A character vector of factor predictor names. May be empty.

Examples

df = data.frame(
  y = rpois(10, 3),
  site = factor(rep(c("A", "B"), each = 5)),
  depth = rnorm(10)
)
mod = glm(y ~ site + depth, family = poisson, data = df)
getFactorPredictors(mod, df)


Get forbidden narrative axes for explanation payload filtering

Description

Get forbidden narrative axes for explanation payload filtering

Usage

getForbiddenNarrativeAxes(model, mf = NULL)

Arguments

model

A fitted model object.

mf

Optional model frame.

Value

Character vector of forbidden axis labels and levels.


Select transformation records used by a model formula

Description

Select transformation records used by a model formula

Usage

getFormulaVariableTransformations(formula, variableTransformations = NULL)

Arguments

formula

A model formula.

variableTransformations

A list of transformation records, or NULL.

Value

A named list of transformation records referenced by the formula.


Get an Rd object for a topic from an installed package

Description

Looks up an Rd help topic in an installed package using tools::Rd_db() and returns the matching Rd object when found.

Usage

getInstalledPackageRd(topic, package)

Arguments

topic

Character scalar. Topic or alias to look up.

package

Character scalar. Installed package name.

Value

An Rd object, or NULL if no matching help topic is found.


List installed packages that appear to contain datasets

Description

Returns the names of installed packages whose installed metadata indicates that they contain datasets. This avoids calling utils::data(package = ...) for every installed package during app startup, which can be slow on shared systems and on Shiny Server.

Usage

getInstalledPackagesWithData()

Details

The result is sorted alphabetically and is useful for populating a package selector in the app's Load Data tab. Dataset names are still resolved lazily for the selected package via getPackageDatasetNames().

Value

A character vector of installed package names that appear to contain one or more datasets.


Detect log-log metadata for a fitted linear model

Description

Detects the common teaching model form log(y) ~ log(x), optionally with additional additive adjustment terms. The returned metadata is intentionally conservative and only records a log-log structure when the response is a natural-log transform and at least one predictor term is also a natural-log transform.

Usage

getLogLogModelMetadata(model, modelFrame = NULL)

Arguments

model

A fitted model object.

modelFrame

Optional model frame recovered from the fitted model.

Value

A named list containing log-log metadata.


Match a transformed log predictor name to its original variable name

Description

Match a transformed log predictor name to its original variable name

Usage

getLogLogOriginalPredictorName(spec, transformedName)

Arguments

spec

A deterministic equation specification.

transformedName

Character name used in the model matrix or model frame.

Value

Original variable name when available, otherwise NULL.


Extract run-level comparison data for a metric

Description

Returns run-level paired scores for a given metric from a wmfmScoreComparison object.

Usage

getMetricComparisonData(x, metric)

Arguments

x

A wmfmScoreComparison object.

metric

Character name of the metric. Must be one of the metric names stored in x$registry$metricName.

Details

This accessor uses the metric registry stored on the comparison object as the source of truth for valid metric names. Because the choices are dynamic, match.arg() is used for validation and partial matching, but IDE tab completion will not show the possible values automatically.

Value

An object of class metricComparisonData with one row per run. When one of the compared methods is deterministic, the returned data frame includes a detValue column and a method-specific value column such as llmValue. When the comparison is between deterministic and LLM scoring, the output also includes llmMinusDet and detMinusLlm.


Return adjustment variables stored on a fitted model

Description

Return adjustment variables stored on a fitted model

Usage

getModelAdjustmentVariables(model)

Arguments

model

A fitted model object.

Value

Character vector of adjustment-variable names.


Get fitted-model equations using the selected equation engine

Description

Provides a single entry point for equation generation. Deterministic equations are now the default. The older LLM equation path remains available as an opt-in compatibility route during the transition.

Usage

getModelEquations(
  model,
  method = c("deterministic", "llm"),
  chat = NULL,
  digits = 2
)

Arguments

model

A fitted model object, typically of class lm or glm.

method

Character string giving the equation engine. Must be one of "deterministic" or "llm".

chat

Optional chat provider object. Required when method = "llm".

digits

Integer number of decimal places for displayed coefficients in the deterministic path. Defaults to 2.

Value

Either a deterministic equation table or the existing language-model equation object.


Get response-transformation handling metadata from a fitted model

Description

Get response-transformation handling metadata from a fitted model

Usage

getModelResponseTransformationMode(model)

Arguments

model

A fitted model object.

Value

One of "both", "model", or "original".


Get the fitted-model response transformation record

Description

Get the fitted-model response transformation record

Usage

getModelResponseTransformationRecord(model)

Arguments

model

A fitted model object.

Value

A transformation record or NULL.


Get transformation roles for fitted model variables

Description

Get transformation roles for fitted model variables

Usage

getModelVariableTransformationRoles(model)

Arguments

model

A fitted model object.

Value

A named character vector with values response, predictor, or unused.


Get derived-variable transformation metadata from a fitted model

Description

Get derived-variable transformation metadata from a fitted model

Usage

getModelVariableTransformations(model)

Arguments

model

A fitted model object.

Value

A named list of transformation records.


List datasets available in an installed package

Description

Looks up the datasets reported by utils::data(package = pkg) for a single installed package.

Usage

getPackageDatasetNames(pkg)

Arguments

pkg

A package name.

Value

A sorted character vector of dataset names. Returns character(0) if the package name is empty, the package is not installed, or no datasets are found.


Get a package name from an installed package DESCRIPTION file

Description

Get a package name from an installed package DESCRIPTION file

Usage

getPackageNameFromDescription(packageDir)

Arguments

packageDir

Path to an installed package directory.

Value

A character scalar package name, or an empty string if the name cannot be read.


Extract aliases from an Rd object

Description

Extract aliases from an Rd object

Usage

getRdAliases(rd)

Arguments

rd

An Rd object.

Value

Character vector of aliases found in the Rd object.


Get s20x dataset documentation as HTML

Description

Get s20x dataset documentation as HTML

Usage

getS20xDocHtml(dataset)

Arguments

dataset

Character string, name of a data set in the s20x package.

Value

A single character string containing HTML for the help page, or NULL if not found.


Get s20x dataset documentation as plain text

Description

Get s20x dataset documentation as plain text

Usage

getS20xDocText(dataset)

Arguments

dataset

Character string, name of a data set in the s20x package.

Value

A single character string with the Rd help text, or NULL if not found.


Build a variance-covariance matrix while muffling known perfect-fit warnings

Description

Build a variance-covariance matrix while muffling known perfect-fit warnings

Usage

getSafeModelVcov(model)

Arguments

model

A fitted model object.

Value

A variance-covariance matrix.


Get the default WMFM claim colour map

Description

Returns a named character vector of colours for semantic values used in WMFM raw repeated-run claim-profile heatmaps.

Usage

getWmfmClaimColorMap()

Details

The palette is designed for raw extracted claim fields and aims to keep semantically different values visually distinct.

Value

A named character vector of hexadecimal colours.

Examples

getWmfmClaimColorMap()

Get the WMFM local configuration directory

Description

Returns the directory that WMFM uses for user-specific local configuration. The path respects options(wmfm.config_dir = ...) when that option has been set.

Usage

getWmfmConfigDir()

Value

Character scalar path to the WMFM configuration directory.


Get the WMFM local configuration file path

Description

Returns the full path to the WMFM user configuration file. This is useful when checking or backing up a local configuration during setup and testing.

Usage

getWmfmConfigPath()

Value

Character scalar path to config.json.


Get a WMFM dummy chat provider message

Description

Get a WMFM dummy chat provider message

Usage

getWmfmDummyChatProviderMessage(x)

Arguments

x

Chat provider object.

Value

Character scalar with the stored message, or NULL.


Return required top-level fields for a WMFM explanation audit

Description

Return required top-level fields for a WMFM explanation audit

Usage

getWmfmExplanationAuditRequiredFields()

Value

A character vector of required top-level field names.


Return the WMFM metric registry

Description

Defines metric metadata used by WMFM score comparison, stability summaries, and plotting. The registry is intended to be the single source of truth for which metrics are available and how they should be treated.

Usage

getWmfmMetricRegistry()

Value

A data frame containing metric metadata.


Get WMFM provider adapter metadata

Description

Get WMFM provider adapter metadata

Usage

getWmfmProviderAdapter(provider)

Arguments

provider

Character scalar provider id.

Value

Named list with provider adapter metadata.


Build claim-profile heatmap data for a WMFM runs object

Description

Extracts selected raw claim fields from a wmfmRuns object and reshapes them into long format for heatmap plotting.

Usage

getWmfmRunsClaimProfileData(
  x,
  fieldColumns = NULL,
  naLabel = "(missing)",
  prettyFieldLabels = TRUE,
  fieldOrder = c("semantic", "purity")
)

Arguments

x

A wmfmRuns object.

fieldColumns

Optional character vector of raw claim fields to include. If NULL, a default raw-only claim profile is used.

naLabel

Character label used for missing values.

prettyFieldLabels

Logical. Should field names be converted to more readable display labels?

fieldOrder

Character. One of "semantic" or "purity".

Details

Runs are intended to be shown on rows and claim fields on columns. Runs are ordered by run purity. Fields can be ordered semantically or by field purity.

Value

A data frame with columns runId, field, fieldLabel, value, modalValue, fieldPurity, and runPurity.


Build extracted-claim frequency data for a WMFM runs object

Description

Build extracted-claim frequency data for a WMFM runs object

Usage

getWmfmRunsClaimsData(x)

Arguments

x

A wmfmRuns object.

Value

A data frame summarising claim frequencies.


Build per-run text and timing metric data for a WMFM runs object

Description

Extracts selected per-run descriptive metrics from a wmfmRuns object for plotting and inspection.

Usage

getWmfmRunsTextMetricsData(x)

Arguments

x

A wmfmRuns object.

Value

A data frame with one row per run.


Grade WMFM objects

Description

Generic for grading user-written explanations against a prepared WMFM model context.

Usage

grade(x, ...)

Arguments

x

An object to grade against.

...

Additional arguments passed to methods.

Value

A method-specific graded output.


Grade one or more explanations against a WMFM model

Description

Creates either a wmfmGrade object for a single explanation or a wmfmGradeListObj when multiple explanations are supplied. By default the returned object is immediately scored using either the deterministic or LLM WMFM grading rubric.

Usage

## S3 method for class 'wmfmModel'
grade(
  x,
  explanation,
  modelAnswer = NULL,
  method = c("deterministic", "llm", "both"),
  autoScore = TRUE,
  score = NULL,
  scoreScale = 10,
  nLlm = 1L,
  confirmLargeLlmJob = FALSE,
  maxLlmJobsWithoutConfirmation = 20L,
  ...
)

Arguments

x

A wmfmModel object, typically created by runModel().

explanation

Character vector, character scalar, or list of character scalars giving the explanation(s) to grade.

modelAnswer

Optional character scalar giving a reference answer.

method

Character. One of "deterministic", "llm", or "both".

autoScore

Logical. Should the returned object be scored immediately? Defaults to TRUE.

score

Deprecated logical alias for autoScore, retained for backward compatibility. When supplied, its logical value is used for autoScore.

scoreScale

Numeric scalar giving the displayed mark scale. Defaults to 10.

nLlm

Integer. Number of repeated LLM gradings per explanation when method includes "llm".

confirmLargeLlmJob

Logical. Set to TRUE to allow large LLM grading requests.

maxLlmJobsWithoutConfirmation

Integer. Maximum number of LLM grading calls allowed without explicit confirmation.

...

Additional arguments passed to score() when autoScore = TRUE.

Value

An object of class wmfmGrade or wmfmGradeListObj.


Test whether Claude credentials are configured

Description

Test whether Claude credentials are configured

Usage

hasClaudeApiKey()

Value

Logical scalar; TRUE when ANTHROPIC_API_KEY is set.


Test whether a local provider setting was explicitly supplied

Description

Test whether a local provider setting was explicitly supplied

Usage

hasExplicitWmfmProviderConfig()

Value

Logical scalar.


Determine whether a package data set has built-in context.

Description

Determine whether a package data set has built-in context.

Usage

hasPackageDatasetContext(dataSource, packageName, datasetName)

Arguments

dataSource

Character scalar identifying the active data source.

packageName

Character scalar package name.

datasetName

Character scalar data set name.

Value

TRUE when WMFM can use package documentation as data context.


Test whether WMFM provider credentials are available

Description

Test whether WMFM provider credentials are available

Usage

hasWmfmProviderCredentials(provider)

Arguments

provider

Character scalar provider id.

Value

Logical scalar indicating whether required credentials are available.


Infer a simple arithmetic transformation label

Description

Infer a simple arithmetic transformation label

Usage

inferArithmeticTransformation(rhs, funName)

Arguments

rhs

Parsed right-hand-side expression.

funName

Character arithmetic operator.

Value

Transformation information or NULL.


Infer a conservative transformation label

Description

Infer a conservative transformation label

Usage

inferTransformationType(rhs)

Arguments

rhs

Parsed right-hand-side expression.

Value

A list containing transformationType, inverseType, and parameters.


Insert pedagogical section-break rows into a CI display table

Description

This helper is retained for backward compatibility, but the Stage 4 display redesign no longer inserts visible separator rows into the returned table.

Usage

insertCiSectionBreakRows(ciTable)

Arguments

ciTable

A confidence-interval display table.

Value

The input data frame, unchanged apart from row names.


Get inverse label for a recognised transformation function

Description

Get inverse label for a recognised transformation function

Usage

inverseTypeForFunction(funName)

Arguments

funName

Character function name.

Value

Character inverse label.


Determine whether a model-output row is adjustment-related

Description

A row is adjustment-related when its term label includes at least one selected adjustment variable.

Usage

isAdjustmentRelatedOutputRow(rowLabel, adjustmentVariables)

Arguments

rowLabel

Character scalar row label from summary/anova output.

adjustmentVariables

Character vector of adjustment-variable names.

Value

Logical scalar.


Test whether the developer-mode UI should be exposed

Description

Developer mode is intended for maintainers and local debugging. It is hidden unless the local environment explicitly opts in with WMFM_SHOW_DEVELOPER_MODE=1.

Usage

isDeveloperModeUiEnabled()

Value

Logical scalar.


Check whether a fitted model has only factor predictors

Description

Determines whether all predictors in a fitted linear or generalised linear model are factors in the supplied data set.

Usage

isFactorOnlyModel(model, data)

Arguments

model

A fitted model object (e.g. lm, glm).

data

A data frame containing the variables used to fit the model.

Details

Intercept-only models are not considered factor-only.

Value

Logical scalar. Returns TRUE if all predictors are factors, otherwise FALSE.

Examples

df = data.frame(
  y = rpois(20, 5),
  site = factor(rep(c("A", "B"), each = 10))
)
mod = glm(y ~ site, family = poisson, data = df)
isFactorOnlyModel(mod, df)


Detect factor-only predictor models

Description

Determines whether a fitted model has only factor predictors in its model frame (i.e., every predictor column is a factor). This is used to switch the "Fitted equations" view into an ANOVA-style "Fitted means" view.

Usage

isFactorOnlyPredictorModel(m)

Arguments

m

A fitted model object, typically an lm or glm.

Details

The response is not checked for being a factor; in typical "fitted means" usage the response is numeric and predictors are factors. Intercept-only models (no predictors) return FALSE.

Value

A logical scalar. TRUE if all predictors in model.frame(m) are factors; otherwise FALSE.

Examples

df = data.frame(y = rnorm(12), A = factor(rep(letters[1:3], each = 4)))
mod = lm(y ~ A, data = df)
isFactorOnlyPredictorModel(mod)


Check whether a model is a linear identity-scale model

Description

Check whether a model is a linear identity-scale model

Usage

isLmIdentityModel(model)

Arguments

model

A fitted model object.

Value

A logical scalar.


Check whether differences can become original-scale multipliers

Description

Check whether differences can become original-scale multipliers

Usage

isResponseDifferenceInverseSupported(inverseType)

Arguments

inverseType

Character inverse label.

Value

Logical scalar.


Test whether a model is a supported logistic GLM

Description

Test whether a model is a supported logistic GLM

Usage

isSupportedLogisticModel(model)

Arguments

model

A fitted model object.

Value

A logical scalar.


Test whether a model is a supported Poisson GLM

Description

Test whether a model is a supported Poisson GLM

Usage

isSupportedPoissonModel(model)

Arguments

model

A fitted model object.

Value

A logical scalar.


Check whether an inverse type can be used for response back-transformation

Description

Check whether an inverse type can be used for response back-transformation

Usage

isUsableResponseInverseType(inverseType)

Arguments

inverseType

Character inverse label.

Value

Logical scalar.


Test whether local WMFM credential storage is allowed

Description

Local credential storage is available only for single-user desktop sessions. Deployed and administrator-managed apps must use environment variables or deployment secrets instead.

Usage

isWmfmConfigCredentialStorageAllowed()

Value

Logical scalar.


Test whether end users may enter provider credentials

Description

Credential entry is local-desktop only by default. Deployed apps must receive credentials from the installer through environment variables or deployment secrets rather than from ordinary browser users.

Usage

isWmfmCredentialEntryAllowed()

Value

Logical scalar.


Test whether WMFM is running in a deployed app context

Description

Uses conservative environment and option checks to distinguish local desktop use from administrator-managed Shiny or CI-style deployments.

Usage

isWmfmDeployedApp()

Value

Logical scalar.


Test whether a chat provider is a WMFM dummy provider

Description

Test whether a chat provider is a WMFM dummy provider

Usage

isWmfmDummyChatProvider(x)

Arguments

x

Object to test.

Value

Logical scalar.


Test whether end users may edit provider configuration

Description

In local desktop use, provider configuration is editable by default. In a deployed app, configuration is administrator-managed unless an explicit WMFM option or environment flag allows end-user provider selection.

Usage

isWmfmProviderConfigurationEditable()

Value

Logical scalar.


Test whether a provider is configured well enough for startup

Description

Test whether a provider is configured well enough for startup

Usage

isWmfmProviderReadyForStartup(providerConfig = resolveWmfmProviderConfig())

Arguments

providerConfig

Optional resolved provider configuration.

Value

Logical scalar.


Test whether a provider is in the WMFM registry

Description

Test whether a provider is in the WMFM registry

Usage

isWmfmProviderSupported(provider)

Arguments

provider

Character scalar provider id.

Value

Logical scalar.


Join signed deterministic algebra terms into one right-hand side

Description

Joins pre-signed algebra fragments into one plain-text expression while preserving ordinary sign formatting.

Usage

joinEquationPieces(pieces)

Arguments

pieces

Character vector of algebra fragments.

Value

A character scalar.


List supported bad explanation types

Description

Returns the currently supported error types that can be requested when generating deliberately flawed model explanations.

Usage

listBadExplanationTypes()

Value

A character vector of supported bad explanation types.


List metrics that can be diagnosed from a wmfmScores object

Description

Internal helper for diagnose().

Usage

listDiagnosableMetrics(scores)

Arguments

scores

A wmfmScores object.

Value

A character vector of metric names present in both deterministic and LLM score records and having at least one non-missing numeric value on each side.


List metrics that can be compared in wmfmScores objects

Description

Internal helper used by comparison and diagnosis workflows.

Usage

listMetricComparisonMetrics(scores)

Arguments

scores

A wmfmScores object.

Value

A character vector of metric names present in both deterministic and LLM score records and having at least one non-missing numeric value on each side.


List packages with installed dataset metadata in library paths

Description

Scans library directories for package metadata created at installation time. This avoids a full installed-package matrix scan while preserving the app behaviour of listing installed packages that appear to contain datasets.

Usage

listPackagesWithDatasetMetadata(libPaths)

Arguments

libPaths

Character vector of library paths to scan.

Value

A sorted character vector of package names with dataset metadata.


List packaged WMFM example details

Description

Returns metadata-backed details for packaged examples stored under inst/extdata/examples. This is intended for release-mode and developer-mode example-library displays that need more than the example names alone.

Usage

listWMFMExampleDetails(package = "WMFM", includeTestExamples = FALSE)

Arguments

package

A character string giving the package name containing the packaged examples.

includeTestExamples

Logical. Should developer-only examples marked as developer or test in the example metadata be included? Defaults to FALSE.

Value

A data frame with one row per available example and columns for example name, path, audience, model family, difficulty, teaching topic, and developer purpose.

Examples

if (interactive()) {
  listWMFMExampleDetails(package = "WMFM")
}


List packaged WMFM examples

Description

Lists packaged examples stored in the package's inst/extdata/examples directory by looking for specification files ending in .spec.yml.

Usage

listWMFMExamples(package = "WMFM", includeTestExamples = FALSE)

Arguments

package

A character string giving the package name containing the packaged examples.

includeTestExamples

Logical. Should developer-only examples marked as developer or test in the example metadata be included? Defaults to FALSE.

Details

Each example is expected to live in its own subdirectory under ⁠extdata/examples/<name>/⁠ and to contain a specification file named ⁠<name>.spec.yml⁠. Example visibility is controlled by the optional extdata/examples/example-metadata.yml manifest.

Value

A character vector of available example names. If no examples are found, an empty character vector is returned.

Examples

if (interactive()) {
  listWMFMExamples(package = "WMFM")
}


List WMFM provider adapters

Description

List WMFM provider adapters

Usage

listWmfmProviderAdapters()

Value

Character vector of registry provider ids.


Internal helpers and imports for LLM-based model output

Description

This file collects shared imports for the internal helper functions that talk to the language model, build prompts, and cache results.


Get fitted-model equations using either the deterministic engine or the language model

Description

Uses the legacy language-model path by default for backward compatibility. Higher-level entry points such as getModelEquations() and runModel() now explicitly request deterministic equations by default.

Usage

lmEquations(model, chat = NULL, method = c("llm", "deterministic"), digits = 2)

Arguments

model

A fitted model object, typically of class "lm" or "glm".

chat

Optional chat provider object as returned by getChatProvider(). Required when method = "llm".

method

Character string giving the equation engine. Must be one of "llm" or "deterministic".

digits

Integer number of decimal places for displayed coefficients in the deterministic path. Defaults to 2.

Value

Either a deterministic equation table or the existing language-model equation object.


Get a plain-language explanation via the language model

Description

Calls the chat provider with a prompt constructed from a fitted model and returns a narrative explanation of the model.

Usage

lmExplanation(model, chat, useCache = TRUE)

Arguments

model

A fitted model object, typically of class "lm" or "glm".

chat

A chat provider object as returned by getChatProvider().

useCache

Logical. Should explanation results be cached and reused for identical fitted models? Defaults to TRUE.

Details

By default, results are cached based on the model formula and coefficients so that repeated requests for the same fitted model do not repeatedly query the language model. This behaviour can be disabled by setting useCache = FALSE, which is useful when deliberately testing variation across repeated language model calls.

Value

A character scalar containing the explanation text returned by the language model.


Build a prompt asking for a plain-language model explanation

Description

Given a fitted linear or generalised linear model, construct a prompt that asks a language model to explain the results in clear, non-technical language. The prompt includes basic model information, an R-squared or pseudo R-squared, and the coefficient table.

Usage

lmToExplanationPrompt(model)

Arguments

model

A fitted model object, typically of class \"lm\" or \"glm\".

Value

A character scalar containing the prompt text to send to the language model for a narrative explanation.


Build an L prompt for fitted-model equations

Description

Build an L prompt for fitted-model equations

Usage

lmToPrompt(model)

Arguments

model

A fitted lm or glm object.

Value

A single character string to be sent to the chat model.


Create a developer-mode password hash

Description

Creates a salted password hash suitable for storing in the WMFM_DEVELOPER_MODE_PASSWORD_HASH environment variable.

Usage

makeDeveloperModePasswordHash(password)

Arguments

password

Character scalar giving the plain-text password.

Value

A salted password hash string.


Plot response by factor predictors for factor-only models

Description

Produces a grouped plot for models with only factor predictors.

Usage

makeFactorOnlyPlot(
  model,
  data,
  ciType = c("standard", "sandwich"),
  hcType = c("HC0", "HC3")
)

Arguments

model

A fitted model object (e.g. lm, glm).

data

A data frame containing the variables used to fit the model.

ciType

Confidence-interval type. One of "standard" (model-based) or "sandwich" (robust).

hcType

Heteroskedasticity-consistent estimator type for robust CIs. One of "HC0" or "HC3". Only used when ciType="sandwich".

Details

For multiple factor predictors, groups are defined by their interaction.

Robust confidence intervals are computed on the linear predictor scale using X V X^T, where V is either vcov(model) or sandwich::vcovHC(model, type = ...). For GLMs, intervals are then transformed back to the response scale using the inverse link function.

Value

A ggplot object.


Build fitted means for factor-only predictor models

Description

Creates a full grid of factor-level combinations for all predictors in the fitted model frame and computes fitted values for each combination.

Usage

makeFittedMeansData(m)

Arguments

m

A fitted model object, typically an lm or glm.

Details

For glm models, fitted values are returned on the response scale via predict(type = "response"). For lm models, fitted values are returned from predict().

Value

A list with components:

response

The response variable name.

predictors

Character vector of predictor names (in model frame order).

grid

A data frame of predictor level combinations with an added numeric column .fit.

mf

The model frame used for extracting factor levels.

Examples

df = data.frame(
  y = rnorm(12),
  A = factor(rep(c("a","b"), each = 6)),
  B = factor(rep(c("u","v","w"), times = 4))
)
mod = lm(y ~ A * B, data = df)
out = makeFittedMeansData(mod)
head(out$grid)


Construct a fitted-mean equation from model coefficients

Description

Builds an explicit equation for a single fitted mean using the model's coefficient vector and the corresponding design row from model.matrix(). This is designed to show how each fitted mean is constructed from the regression table coefficients.

Usage

makeMeanEquation(m, oneRowDf, label)

Arguments

m

A fitted model object, typically an lm or glm.

oneRowDf

A one-row data frame containing predictor values for which to construct the equation. Column names must match the model terms.

label

A character label to place on the left-hand side of the equation.

Details

For GLMs, the regression coefficients combine to form the linear predictor (often written \eta). This function shows that linear predictor and then shows the back-transformation to the mean on the response scale.

Value

A length-1 character string containing the equation (may include newline characters for multi-step GLM working).

Examples

df = data.frame(y = rnorm(8), A = factor(rep(c("a","b"), each = 4)))
mod = lm(y ~ A, data = df)
oneRow = data.frame(A = factor("b", levels = levels(df$A)))
makeMeanEquation(mod, oneRow, "Mean(A=b)")


Build a response back-transformation data-frame row

Description

Build a response back-transformation data-frame row

Usage

makeResponseBackTransformationRow(
  row,
  originalVariable,
  estimate,
  lower,
  upper,
  meaning
)

Arguments

row

Original CI table row.

originalVariable

Original response variable name.

estimate

Back-transformed estimate.

lower

Back-transformed lower endpoint.

upper

Back-transformed upper endpoint.

meaning

Meaning label.

Value

One-row data frame.


Create a safe evaluation environment for derived-variable expressions

Description

Builds an environment that contains the columns of data and a small allowlist of safe base functions. This is intended for evaluating the right-hand side (RHS) of user-entered derived-variable assignments in a Shiny app without exposing powerful functions like file I/O or system calls.

Usage

makeSafeEvalEnv(data)

Arguments

data

A data frame.

Details

The returned environment contains:

Value

An environment suitable for eval(rhs, envir = env).

Examples

df = data.frame(x = 1:5)
env = makeSafeEvalEnv(df)
eval(parse(text = "log(x)"), envir = env)
eval(parse(text = "factor(rep(1:2, length.out = nrow(data)))"), envir = env)


Make deterministic category colours for WMFM heatmaps

Description

Generates a stable, perceptually stronger mapping from category values to colours using only base R / grDevices. The same category value always maps to the same colour, regardless of the order in which values appear.

Usage

makeWmfmDeterministicCategoryColors(values, naLabel = "(missing)")

Arguments

values

A vector of category values.

naLabel

Character label used for missing values after coercion.

Details

Colours are generated in HCL space using a simple deterministic string hash. This gives better separation than short fixed palettes, especially when many distinct values are present.

Value

A named character vector of colours, where names are category values.

Examples

makeWmfmDeterministicCategoryColors(c("yes", "no", "mixed", "(missing)"))

Make readable WMFM legend labels

Description

Converts raw semantic claim values into nicer display labels for plot legends.

Usage

makeWmfmLegendLabels(values)

Arguments

values

Character vector of raw legend values.

Value

A character vector of display labels.

Examples

makeWmfmLegendLabels(c("TRUE", "mixed_or_unclear", "(missing)", ""))

Map a raw CI row scale to a display-scale identifier

Description

Map a raw CI row scale to a display-scale identifier

Usage

mapConfidenceIntervalDisplayScale(scale, modelFramework)

Arguments

scale

A raw row scale label.

modelFramework

Teaching framework identifier.

Value

A character scalar.


Map a raw CI row scale to a primary teaching scale label

Description

Map a raw CI row scale to a primary teaching scale label

Usage

mapConfidenceIntervalPrimaryScale(scale, modelFramework)

Arguments

scale

A raw row scale label.

modelFramework

Teaching framework identifier.

Value

A character scalar.


Map a raw CI row scale to a secondary teaching scale label

Description

Map a raw CI row scale to a secondary teaching scale label

Usage

mapConfidenceIntervalSecondaryScale(scale, modelFramework)

Arguments

scale

A raw row scale label.

modelFramework

Teaching framework identifier.

Value

A character scalar.


Map explanation zoom selection to CSS font size

Description

Map explanation zoom selection to CSS font size

Usage

mapExplanationZoomToFontSize(zoomLevel)

Arguments

zoomLevel

Character scalar zoom level from the UI control.

Value

A character scalar containing a CSS font-size value.


Map one explanation sentence back to evidence

Description

Map one explanation sentence back to evidence

Usage

mapSingleExplanationClaim(
  claimId,
  sentenceIndex,
  claimText,
  audit,
  teachingSummary,
  model,
  evidenceInventory,
  totalClaims = NA_integer_,
  priorClaimTexts = character(0)
)

Arguments

claimId

Character scalar.

sentenceIndex

Integer sentence index.

claimText

Character scalar.

audit

A wmfmExplanationAudit object.

teachingSummary

Optional teaching summary object.

model

Optional fitted model object.

evidenceInventory

Evidence inventory data frame.

Value

A single-row data frame.


Create a simple command-line stage tracker

Description

Create a simple command-line stage tracker

Usage

newWmfmCliStageTracker(
  showProgress = TRUE,
  showTiming = TRUE,
  taskLabel = "Task"
)

Arguments

showProgress

Logical. Should progress messages be shown?

showTiming

Logical. Should timing summaries be shown?

taskLabel

Character scalar naming the task.

Value

A list used internally for command-line progress and timing.


Create a WMFM grade object

Description

Creates a classed wmfmGrade object that stores a candidate explanation, an optional reference answer, and the model context needed for scoring.

Usage

newWmfmGrade(
  x,
  explanation,
  modelAnswer = NULL,
  scoreScale = 10,
  records = list(),
  scores = list(),
  feedback = list(),
  meta = list()
)

Arguments

x

A wmfmModel object.

explanation

Character scalar. The explanation being graded.

modelAnswer

Optional character scalar giving a reference answer.

scoreScale

Numeric scalar giving the displayed mark scale. Defaults to 10.

records

Optional named list of run records.

scores

Optional named list of scored data frames.

feedback

Optional named list of feedback components.

meta

Optional named list of metadata.

Value

An object of class wmfmGrade.


Create a WMFM grade list object

Description

Creates a classed wmfmGradeListObj object that stores multiple wmfmGrade objects together with batch-level metadata.

Usage

newWmfmGradeListObj(grades, model, inputs, meta = list())

Arguments

grades

Named list of wmfmGrade objects.

model

A wmfmModel object.

inputs

Named list describing the supplied explanations.

meta

Optional named list of metadata.

Value

An object of class wmfmGradeListObj.


Create a WMFM model object

Description

Creates a classed wmfmModel object that stores a fitted model together with the additional context and generated outputs used by the WMFM command-line workflow.

Usage

newWmfmModel(
  model,
  formula,
  modelType,
  data,
  dataContext = NULL,
  researchQuestion = NULL,
  equations = NULL,
  explanation = NULL,
  explanationAudit = NULL,
  explanationClaimEvidenceMap = NULL,
  modelProfile = NULL,
  variableTransformations = list(),
  responseTransformationMode = "both",
  interactionTerms = character(0),
  interactionMinPValue = NA_real_,
  meta = list()
)

Arguments

model

A fitted model object.

formula

A model formula.

modelType

Character string giving the model family.

data

A data.frame used to fit the model.

dataContext

Optional character string giving dataset context.

researchQuestion

Optional character string giving the research question associated with the fitted model.

equations

Generated equations object, or NULL.

explanation

Generated explanation text, or NULL.

explanationAudit

Deterministic explanation-audit object, or NULL. When present, this should inherit from wmfmExplanationAudit and follow the same top-level contract produced by buildModelExplanationAudit().

explanationClaimEvidenceMap

Deterministic claim-to-evidence map, or NULL.

modelProfile

Deterministic explanation model-profile metadata, or NULL.

variableTransformations

Named list of derived-variable transformation records used by this fitted model.

responseTransformationMode

Character scalar describing how later response-scale interpretation should handle recognised response transformations. One of "both", "model", or "original".

interactionTerms

Character vector of fitted interaction-term names.

interactionMinPValue

Minimum p-value across fitted interaction terms, or NA_real_.

meta

Optional named list of metadata.

Value

An object of class wmfmModel.


Create a WMFM progress tracker

Description

Internal helper that initialises progress-bar and timing state for repeated WMFM work.

Usage

newWmfmProgressTracker(nSteps, showProgress = TRUE, label = "Progress")

Arguments

nSteps

Integer. Total number of iterations.

showProgress

Logical. Should a text progress bar be shown?

label

Character. Short label used in timing messages.

Value

An environment storing tracker state.


Create an empty WMFM scores object

Description

Creates a wmfmScores object aligned to a wmfmRuns object but containing no scoring results yet. This is a constructor/helper for the scoring workflow. Actual score values are added later by score().

Usage

newWmfmScores(x, methods = character(0))

Arguments

x

A wmfmRuns object.

methods

Character vector of scoring methods to reserve. Allowed values are "deterministic" and "llm".

Value

An object of class wmfmScores.


Normalise a numeric value for simple text matching

Description

Normalise a numeric value for simple text matching

Usage

normaliseExplanationNumericString(x)

Arguments

x

Numeric-like scalar.

Value

Character scalar.


Normalise common worded numeric expressions in WMFM text

Description

Applies a lightweight set of rule-based replacements to common language-model failures where decimals or percentages are written in words rather than numerals. The helper is intentionally narrow and targets the specific forms that WMFM most needs to control, such as "six and a half" or "sixty-two percent".

Usage

normaliseNumericExpressions(text)

Arguments

text

A character vector.

Value

A character vector with common worded numeric expressions rewritten in numeral form.


Normalise response-transformation handling mode

Description

Normalise response-transformation handling mode

Usage

normaliseResponseTransformationMode(responseTransformationMode = "both")

Arguments

responseTransformationMode

Character scalar requested mode.

Value

One of "both", "model", or "original".


Normalise derived-variable transformation records

Description

Normalise derived-variable transformation records

Usage

normaliseVariableTransformations(variableTransformations = NULL)

Arguments

variableTransformations

A list of transformation records, or NULL.

Value

A named list of transformation records.


Normalise a WMFM provider credential environment variable name

Description

Normalise a WMFM provider credential environment variable name

Usage

normaliseWmfmCredentialEnvVar(provider)

Arguments

provider

Character scalar provider id.

Value

Character scalar environment variable name, or an empty string.


Normalise one or more WMFM explanations

Description

Internal helper that accepts a character vector or a list of character scalars and returns a named character vector suitable for batch grading.

Usage

normaliseWmfmExplanations(explanation)

Arguments

explanation

Character vector or list of character scalars.

Value

A named character vector.


Normalise a WMFM provider profile

Description

Normalise a WMFM provider profile

Usage

normaliseWmfmProviderProfile(profile = list())

Arguments

profile

Named list describing a configured provider profile.

Value

Named list with normalised provider profile metadata.


Normalize scoring role variables

Description

Normalize scoring role variables

Usage

normaliseWmfmScoringRoleVariables(x)

Arguments

x

Character vector, list, or scalar of role-variable names.

Value

Character vector of unique non-empty role-variable names.


Normalise text for comparison

Description

Lowercases and removes extra whitespace.

Usage

normaliseWmfmText(x)

Arguments

x

Character text.

Value

Character string.


Null-coalescing operator

Description

Returns y when x is NULL; otherwise returns x. This is useful for providing defaults when optional values may be missing.

Usage

x %||% y

Arguments

x

A value that may be NULL.

y

A default value to use when x is NULL.

Value

If x is NULL, returns y; otherwise returns x.


Order WMFM agreement metrics for plotting

Description

Computes an ordering for ordinal agreement metrics so that the least agreeable metrics can be shown first in plots. The default ordering combines weighted kappa, exact agreement, adjacent agreement, and mean absolute difference into a simple composite disagreement score.

Usage

orderWmfmAgreementMetrics(agreementDf, orderBy = c("worst", "registry"))

Arguments

agreementDf

A data frame like x$ordinalAgreement from a wmfmScoreComparison object.

orderBy

Character. One of "worst" or "registry".

Value

A character vector of metric labels in plotting order.


Order WMFM legend values

Description

Returns legend values in a semantic order rather than alphabetical order. This makes the legend easier to read by grouping related claim values together.

Usage

orderWmfmLegendValues(values, includeBreaks = TRUE)

Arguments

values

Character vector of legend values to order.

includeBreaks

Logical. Should blank spacer rows be inserted between semantic groups?

Details

If includeBreaks = TRUE, blank entries are inserted between groups so the legend displays with visual spacing.

Value

A character vector of ordered legend values. If includeBreaks = TRUE, the returned vector may contain empty strings used as spacer rows.

Examples

orderWmfmLegendValues(c("unclear", "TRUE", "appropriate", "(missing)"))
orderWmfmLegendValues(
  c("unclear", "TRUE", "appropriate", "(missing)"),
  includeBreaks = TRUE
)

Parse JSON returned for bad explanation generation

Description

Parses the raw text returned by a language model generation call. The parser is tolerant of fenced code blocks and leading or trailing non-JSON text, but it expects either a single JSON object or a JSON array of objects.

Usage

parseBadExplanationResponse(rawResponse)

Arguments

rawResponse

Character scalar raw LLM response.

Value

A parsed list.


Parse a natural-log call expression

Description

Parse a natural-log call expression

Usage

parseNaturalLogCall(expr)

Arguments

expr

Character expression such as log(x).

Value

The variable inside the log call, or NULL if the expression is not a simple natural-log call.


Parse a single assignment statement from text

Description

Parses user input and verifies it is exactly one assignment statement of the form name = expr or name <- expr. This is designed for validating a derived-variable input box in a Shiny app.

Usage

parseSingleAssignment(txt)

Arguments

txt

A length-1 character string containing R code.

Value

A list with elements:

Examples

parseSingleAssignment("t = 1:10")$ok
parseSingleAssignment("1:10")$ok
parseSingleAssignment("x = log(y)")$name


Parse a weight entered as text

Description

Parses a user-entered weight string into a numeric value. Supports:

Usage

parseWeightText(x)

Arguments

x

A character string containing a weight specification.

Details

If parsing fails, the function returns NA_real_.

Value

A numeric scalar if parsing succeeds; otherwise NA_real_.


Parse JSON returned by the LLM scorer

Description

Parses the raw text returned by a language model scoring call. The parser is tolerant of fenced code blocks and leading or trailing non-JSON text, but it expects exactly one JSON object to be present.

Usage

parseWmfmScoringJson(rawResponse)

Arguments

rawResponse

Character scalar containing the model response.

Value

A named list parsed from JSON.


Plot a metric comparison data object

Description

Provides quick diagnostic plots for the run-level output returned by getMetricComparisonData().

Usage

## S3 method for class 'metricComparisonData'
plot(x, type = c("confusion", "runs"), ...)

Arguments

x

A metricComparisonData object.

type

Plot type. One of "confusion" or "runs".

...

Unused. Included for S3 compatibility.

Value

A ggplot2 object.


Plot a metric comparison summary

Description

Plots the relationship between disagreement and deterministic ease for a metricComparisonSummary object.

Usage

## S3 method for class 'metricComparisonSummary'
plot(
  x,
  type = c("scatter", "lollipop", "diagnostic"),
  metricType = NULL,
  labelPoints = TRUE,
  orderBy = c("disagreement", "ease"),
  disagreementThreshold = 0.5,
  easeThreshold = 0.8,
  ...
)

Arguments

x

A metricComparisonSummary object created by summariseMetricComparison().

type

Plot type. One of "scatter", "lollipop", or "diagnostic".

metricType

Optional metric type filter. One of NULL, "ordinal", "binary", or "continuous".

labelPoints

Logical. Should points be labelled in the scatter-style plots?

orderBy

Ordering for the lollipop plot. One of "disagreement" or "ease".

disagreementThreshold

Numeric threshold used by type = "diagnostic" to decide which metrics to label and highlight.

easeThreshold

Numeric threshold used by type = "diagnostic" to decide which metrics to label and highlight.

...

Unused. Included for S3 compatibility.

Value

A ggplot2 object.


Plot a WMFM runs object

Description

Produces plots for a raw wmfmRuns object. These plots are descriptive and focus on run-to-run variation in generated outputs, extracted claims, and run metrics. Judged fields and score summaries are intentionally excluded and belong to wmfmScores objects instead.

Usage

## S3 method for class 'wmfmRuns'
plot(x, type = c("claims", "textMetrics", "claimProfile"), ...)

Arguments

x

A wmfmRuns object.

type

Character. Plot type. One of "claims", "textMetrics", or "claimProfile".

...

Passed through to lower-level plotting helpers.

Details

Supported plot types are:

"claims"

Bar plot of extracted binary claim frequencies across runs.

"textMetrics"

Bar plot of per-run text and timing metrics.

"claimProfile"

Heatmap of raw extracted claim fields across runs.

Value

A ggplot2 object.


Plot a WMFM score comparison object

Description

Provides plotting modes for a wmfmScoreComparison object.

Usage

## S3 method for class 'wmfmScoreComparison'
plot(x, type = c("agreement", "overall", "heatmap"), ...)

Arguments

x

A wmfmScoreComparison object.

type

Character. One of "agreement", "overall", or "heatmap".

...

Additional arguments passed to the underlying helper.

Details

type = "overall"

A Bland-Altman plot for paired overall scores.

type = "agreement"

An ordinal-agreement summary plot showing exact agreement, adjacent agreement, weighted kappa, and mean absolute difference.

type = "heatmap"

A run-by-metric disagreement heatmap based on run-level comparison pairs.

Value

A ggplot object.


Plot a WMFM score stability object

Description

Creates a visual summary of within-method score stability.

Usage

## S3 method for class 'wmfmScoreStability'
plot(
  x,
  type = c("continuous", "ordinal", "binary"),
  metric = NULL,
  value = NULL,
  ...
)

Arguments

x

A wmfmScoreStability object.

type

Character. One of "continuous", "ordinal", or "binary".

metric

Character or NULL. Optional metric filter.

value

Character. Quantity to plot. Allowed values depend on type.

...

Unused. Included for S3 compatibility.

Value

A ggplot2 object.


Plot a WMFM scores object

Description

Provides plotting methods for a wmfmScores object returned by score(). Score heatmaps use a continuous colour scale and, by default, include only the 0 to 2 dimension scores to avoid distortion from the 0 to 100 overall score.

Usage

## S3 method for class 'wmfmScores'
plot(
  x,
  method = NULL,
  type = c("scores", "overall", "summary"),
  fieldColumns = NULL,
  ...
)

Arguments

x

A wmfmScores object.

method

Optional character. Scoring method to plot. One of "deterministic" or "llm". If omitted, an available method is chosen automatically.

type

Character. One of "scores", "overall", or "summary".

fieldColumns

Optional character vector of score columns to plot when type = "scores" or type = "summary".

...

Additional arguments for future extensibility.

Value

A ggplot2 object.


Plot CI controls for the Plot tab

Description

UI controls for confidence intervals. The UI adapts to the plot type:

Usage

plotCiControlsUi(
  mode = c("factorOnly", "continuous"),
  showCiInputId = "plotShowCi",
  ciLevelInputId = "plotCiLevel",
  ciTypeInputId = "plotCiType",
  hcTypeInputId = "plotHcType"
)

Arguments

mode

Either "factorOnly" or "continuous".

showCiInputId

Input id for the "show confidence intervals" checkbox.

ciLevelInputId

Input id for the confidence level slider.

ciTypeInputId

Input id for CI type radio buttons.

hcTypeInputId

Input id for HC type dropdown.

Details

Designed to be placed in the Plot tab sidebar / controls area.

Value

A Shiny tag list.


Draw a student-facing model plot

Description

Draw a student-facing model plot

Usage

plotModelPlot(
  model,
  plotType = c("observedFitted", "residualFitted"),
  showSmoothTrend = TRUE
)

Arguments

model

A fitted model object or wmfmModel object.

plotType

Plot type.

showSmoothTrend

Logical; if TRUE, add an automatic blue smoother for supported linear-model plots.

Value

A ggplot object, or NULL for unsupported models.


Plot a raw-claim heatmap for WMFM runs

Description

Draws a run-by-field heatmap for a wmfmRuns object using raw extracted claim fields only. Rows represent runs and columns represent claim fields.

Usage

plotWmfmExplanationClaimHeatmap(
  x,
  fieldColumns = NULL,
  naLabel = "(missing)",
  main = "Claim profile across repeated runs",
  xlab = NULL,
  ylab = "Run ID",
  prettyFieldLabels = TRUE,
  fieldOrder = c("semantic", "purity"),
  xLabelAngle = 45,
  includeLegendBreaks = FALSE
)

Arguments

x

A wmfmRuns object.

fieldColumns

Optional character vector of raw claim fields to plot.

naLabel

Character label used for missing values.

main

Character plot title.

xlab

Character x-axis label.

ylab

Character y-axis label.

prettyFieldLabels

Logical. Should field names be prettified for display?

fieldOrder

Character. One of "semantic" or "purity".

xLabelAngle

Numeric rotation angle for x-axis tick labels.

includeLegendBreaks

Logical. Passed to orderWmfmLegendValues().

Value

A ggplot2 object.


Plot ordinal agreement summary for WMFM score comparison

Description

Plot ordinal agreement summary for WMFM score comparison

Usage

plotWmfmScoreAgreementSummary(x, orderBy = c("worst", "registry"))

Arguments

x

A wmfmScoreComparison object

orderBy

"worst" or "registry"

Value

ggplot object


Plot a run-level disagreement heatmap for WMFM score comparisons

Description

Visualises run-level disagreement between two scoring methods stored in a wmfmScoreComparison object. The heatmap is built from pairData and is intended primarily for ordinal and binary metrics.

Usage

plotWmfmScoreHeatmap(
  x,
  includeMetricTypes = c("ordinal", "binary"),
  orderBy = c("worst", "registry", "alphabetical"),
  facetBy = c("group", "metricType"),
  prettyLabels = TRUE,
  showRunEvery = 1L,
  ...
)

Arguments

x

A wmfmScoreComparison object.

includeMetricTypes

Character vector of metric types to include. Defaults to c("ordinal", "binary").

orderBy

Character. One of "worst", "registry", or "alphabetical".

facetBy

Character. One of "group" or "metricType".

prettyLabels

Logical. Should metric labels be prettified using the stored labels in pairData?

showRunEvery

Integer. Show every kth run label on the x-axis.

...

Unused. Included for future compatibility.

Details

Ordinal metrics are classified into disagreement classes using the absolute difference between the paired scores:

Binary metrics are classified as either exact or different.

Metrics can be ordered by mean disagreement severity so that the worst-agreeing metrics appear first.

Value

A ggplot object.


Apply a post-processing rule and record whether it changed text

Description

Apply a post-processing rule and record whether it changed text

Usage

postProcessApplyRule(
  text,
  ruleName,
  ruleFunction,
  rulesApplied,
  previous = text,
  preserveNumericTokens = TRUE
)

Arguments

text

Character vector.

ruleName

Character scalar naming the rule.

ruleFunction

Function that accepts and returns a character vector.

rulesApplied

Character vector of rule names already applied.

previous

Optional previous text to compare against instead of text.

Value

A list with text and rulesApplied.


Standardise recurring confidence interval terminology

Description

Standardise recurring confidence interval terminology

Usage

postProcessConfidenceIntervalTerminology(text)

Arguments

text

Character vector.

Value

A character vector with safer confidence interval terminology.


Remove escaped dollar-sign artefacts from explanation text

Description

Language-model responses can sometimes contain Markdown-escaped dollar signs such as ⁠\$2400⁠. In ordinary student-facing prose those backslashes are visible artefacts, so this helper removes only the escape character and leaves the currency symbol and number unchanged.

Usage

postProcessEscapedDollarSigns(text)

Arguments

text

Character vector of explanation text.

Value

A character vector with literal ⁠\$⁠ changed to $.


Post-process generated explanation text before display

Description

Applies deterministic surface-level cleanup to generated explanation text. This step is deliberately conservative: it removes known formatting artifacts, standardises a small set of recurring pedagogical phrasing problems, and avoids changing numeric values or statistical meaning.

Usage

postProcessExplanationText(text, audit = NULL, debug = FALSE)

Arguments

text

Character vector of explanation text.

audit

Optional explanation audit object. Reserved for future audit-aware cleanup rules.

debug

Logical. If TRUE, return the original text, processed text, and the names of deterministic rules that changed the text.

Value

A character vector with deterministic surface cleanup applied, or a list with original, processed, and rulesApplied when debug = TRUE.


Extract numeric tokens from explanation text

Description

Extract numeric tokens from explanation text

Usage

postProcessExtractNumericTokens(text)

Arguments

text

Character scalar.

Value

A character vector of numeric tokens.


Clean small grammar artefacts created by deterministic rewrites

Description

Clean small grammar artefacts created by deterministic rewrites

Usage

postProcessGrammarCleanup(text)

Arguments

text

Character vector.

Value

A character vector with small grammar artefacts cleaned up.


Create an empty surface issue data frame

Description

Create an empty surface issue data frame

Usage

postProcessIssueDataFrame()

Value

An empty data frame using the surface issue schema.


Replace raw log-log interpretation wording with percentage-change language

Description

Replace raw log-log interpretation wording with percentage-change language

Usage

postProcessLogLogPercentageLanguage(text)

Arguments

text

Character vector.

Value

A character vector with common student-facing log-log wording rewritten on the percentage-change scale.


Split recurring long sentence patterns without changing values

Description

Split recurring long sentence patterns without changing values

Usage

postProcessLongSentencePatterns(text)

Arguments

text

Character vector.

Value

A character vector with a few long sentence patterns split.


Remove a small set of model-mechanism phrasings

Description

Remove a small set of model-mechanism phrasings

Usage

postProcessModelMechanismLanguage(text)

Arguments

text

Character vector.

Value

A character vector with recurring technical leakage reduced.


Check whether numeric tokens are preserved by a rewrite

Description

Check whether numeric tokens are preserved by a rewrite

Usage

postProcessPreservesNumericTokens(before, after)

Arguments

before

Character vector before a deterministic rewrite.

after

Character vector after a deterministic rewrite.

Value

TRUE when every numeric token in before is still present in the matching element of after; otherwise FALSE.


Improve recurring sentence openings that foreground model mechanics

Description

Improve recurring sentence openings that foreground model mechanics

Usage

postProcessSentenceOpenings(text)

Arguments

text

Character vector.

Value

A character vector with student-facing sentence openings.


Polish recurring student-facing explanation wording

Description

Applies conservative surface cleanup for common explanation wording artefacts that do not change numeric values or statistical meaning.

Usage

postProcessStudentFacingPolish(text)

Arguments

text

Character vector of explanation text.

Value

A character vector with recurring wording artefacts cleaned up.


Surface issue scan rules

Description

Surface issue scan rules

Usage

postProcessSurfaceIssueRules()

Value

A list of diagnostic surface issue rules.


Standardise recurring unit-change phrasing

Description

Standardise recurring unit-change phrasing

Usage

postProcessUnitChangePhrasing(text)

Arguments

text

Character vector.

Value

A character vector with safer unit-change phrasing.


Replace verbal fractions in numeric contexts

Description

Replace verbal fractions in numeric contexts

Usage

postProcessVerbalFractions(text)

Arguments

text

Character vector.

Value

A character vector with verbal fractions replaced by percentages.


Normalise whitespace after deterministic post-processing

Description

Normalise whitespace after deterministic post-processing

Usage

postProcessWhitespace(text)

Arguments

text

Character vector.

Value

A character vector with repeated whitespace cleaned up.


Prepare non-secret provider config from settings input

Description

Prepare non-secret provider config from settings input

Usage

prepareNonSecretProviderConfig(
  backend,
  ollamaBaseUrl,
  ollamaModel,
  ollamaThinkLow,
  activeProviderProfileId = NULL
)

Arguments

backend

Character scalar requested backend/provider.

ollamaBaseUrl

Character scalar requested Ollama base URL.

ollamaModel

Character scalar requested Ollama model.

ollamaThinkLow

Logical scalar low-thinking preference for Ollama.

Value

Named list containing only the non-secret config fields WMFM stores.


Print a metric comparison summary

Description

Print a metric comparison summary

Usage

## S3 method for class 'metricComparisonSummary'
print(x, ...)

Arguments

x

A metricComparisonSummary object.

...

Unused. Included for S3 compatibility.

Value

The input object, invisibly.


Print a WMFM grade summary

Description

Print a WMFM grade summary

Usage

## S3 method for class 'summary.wmfmGrade'
print(x, digits = 2, ...)

Arguments

x

A summary.wmfmGrade object.

digits

Number of digits for numeric output.

...

Unused.

Value

Invisibly returns x.


Print a WMFM grade list summary

Description

Print a WMFM grade list summary

Usage

## S3 method for class 'summary.wmfmGradeListObj'
print(x, digits = 2, ...)

Arguments

x

A summary.wmfmGradeListObj object.

digits

Number of digits for numeric output.

...

Unused.

Value

Invisibly returns x.


Print a summary.wmfmRuns object

Description

Print a summary.wmfmRuns object

Usage

## S3 method for class 'summary.wmfmRuns'
print(x, ...)

Arguments

x

A summary.wmfmRuns object.

...

Reserved for future extensions.

Value

x, invisibly.


Print a bad explanation grading audit

Description

Print a bad explanation grading audit

Usage

## S3 method for class 'wmfmBadExplanationAudit'
print(x, digits = 2, maxExamples = 10, ...)

Arguments

x

A wmfmBadExplanationAudit object.

digits

Number of digits for numeric output.

maxExamples

Maximum number of flagged examples to print in detail.

...

Unused.

Value

Invisibly returns x.


Print a deterministic equation table

Description

Prints one teaching case at a time, preserving separate scale-specific lines where available.

Usage

## S3 method for class 'wmfmEquationTable'
print(x, ...)

Arguments

x

A wmfmEquationTable object.

...

Unused.

Value

Invisibly returns x.


Print a WMFM explanation audit

Description

Print a WMFM explanation audit

Usage

## S3 method for class 'wmfmExplanationAudit'
print(x, ...)

Arguments

x

A wmfmExplanationAudit object.

...

Unused.

Value

Invisibly returns x.


Print an explanation surface diagnosis

Description

Print an explanation surface diagnosis

Usage

## S3 method for class 'wmfmExplanationSurfaceDiagnosis'
print(x, ...)

Arguments

x

A wmfmExplanationSurfaceDiagnosis object.

...

Additional arguments, currently unused.

Value

The input object, invisibly.


Print a WMFM grade object

Description

Print a WMFM grade object

Usage

## S3 method for class 'wmfmGrade'
print(
  x,
  method = NULL,
  format = c("plaintext", "html"),
  digits = 2,
  maxRows = 6,
  ...
)

Arguments

x

A wmfmGrade object.

method

Optional character. One of "deterministic" or "llm".

format

Character. One of "plaintext" or "html".

digits

Number of digits for numeric output.

maxRows

Maximum rows per section.

...

Unused.

Value

Invisibly returns x for plaintext and an HTML document for html.


Print a wmfmGradeComparison object

Description

Print a wmfmGradeComparison object

Usage

## S3 method for class 'wmfmGradeComparison'
print(x, digits = 2, maxRows = 6, ...)

Arguments

x

A wmfmGradeComparison object.

digits

Number of digits for numeric output.

maxRows

Maximum number of rows to print in each section.

...

Unused. Included for S3 compatibility.

Value

Invisibly returns x.


Print a WMFM grade list object

Description

Print a WMFM grade list object

Usage

## S3 method for class 'wmfmGradeListObj'
print(x, digits = 2, maxExamples = 6, ...)

Arguments

x

A wmfmGradeListObj object.

digits

Number of digits for numeric output.

maxExamples

Maximum number of explanation marks to print.

...

Unused.

Value

Invisibly returns x.


Print a metric diagnosis object

Description

Print a metric diagnosis object

Usage

## S3 method for class 'wmfmMetricDiagnosis'
print(x, ...)

Arguments

x

A wmfmMetricDiagnosis object.

...

Unused.

Value

The input object, invisibly.


Print a WMFM score comparison object

Description

Provides a concise console summary of agreement between two WMFM scoring result sets.

Usage

## S3 method for class 'wmfmScoreComparison'
print(x, digits = 2, ...)

Arguments

x

A wmfmScoreComparison object.

digits

Integer. Number of digits to display.

...

Unused. Included for S3 compatibility.

Value

Invisibly returns x.


Print a WMFM score stability object

Description

Provides a concise console summary of within-method score stability.

Usage

## S3 method for class 'wmfmScoreStability'
print(x, digits = 2, ...)

Arguments

x

A wmfmScoreStability object.

digits

Integer. Number of digits to display.

...

Unused. Included for S3 compatibility.

Value

Invisibly returns x.


Print a scores diagnosis object

Description

Print a scores diagnosis object

Usage

## S3 method for class 'wmfmScoresDiagnosis'
print(x, ...)

Arguments

x

A wmfmScoresDiagnosis object.

...

Unused.

Value

The input object, invisibly.


Read WMFM local configuration

Description

Reads persisted local defaults for provider settings. Credential values are deliberately excluded from this ordinary settings view.

Usage

readWmfmConfig()

Value

Named list with recognized non-secret fields when present.


Read a locally stored WMFM provider credential

Description

Read a locally stored WMFM provider credential

Usage

readWmfmConfigCredential(provider)

Arguments

provider

Character scalar provider id.

Value

Character scalar credential value, or an empty string.


Read the WMFM local configuration file path

Description

Alias for getWmfmConfigPath().

Usage

readWmfmConfigPath()

Value

Character scalar path to config.json.


Read raw WMFM local configuration

Description

Reads the complete local WMFM configuration file. This helper is internal and may include locally stored credential metadata, so user-facing code should prefer readWmfmConfig() unless it is explicitly managing secrets.

Usage

readWmfmRawConfig()

Value

Named list containing all parsed configuration fields.


Rebuild raw WMFM run records without rerunning the LLM

Description

Recomputes raw extracted fields for an existing wmfmRuns object by re-running buildWmfmRunRecord() on the stored run metadata and generated text. This is useful when extraction rules change and you want to refresh the raw run records without generating new LLM outputs.

Usage

rebuildWmfmRunRecords(x, preserveClass = TRUE)

Arguments

x

A wmfmRuns object.

preserveClass

Logical. Should the class of x be preserved on the returned object? Defaults to TRUE.

Details

This function is intentionally limited to rebuilding raw run records. It does not rescore runs and does not compute summaries. If scoring is needed after rebuilding, call score() on the returned object.

Value

A rebuilt wmfmRuns object with refreshed runs records.


Register chat provider observers for the app server.

Description

Keeps Ollama model discovery and chat-provider selection wiring out of the main app server orchestration function.

Usage

registerChatProviderObservers(input, output, session, rv)

Arguments

input

Shiny input object.

output

Shiny output object.

session

Shiny session object.

rv

App-level reactive values object.

Value

Invisibly returns NULL; called for its side effects.


Register contrast observers for the app server

Description

Registers the Shiny outputs and observers that build and compute factor-only model contrasts. This keeps the top-level app server focused on orchestration while preserving the existing contrast behaviour.

Usage

registerContrastObservers(
  input,
  output,
  session,
  rv,
  modelFit,
  contrastPairs,
  contrastResultText,
  setBucketState
)

Arguments

input

Shiny input object.

output

Shiny output object.

session

Shiny session object.

rv

Main app reactive values object.

modelFit

Reactive value containing the current fitted model.

contrastPairs

Reactive value containing selected pairwise contrasts.

contrastResultText

Reactive value containing rendered contrast output text.

setBucketState

Function for synchronising factor and continuous bucket state.

Value

Invisibly returns NULL.


Register data loading observers for the app server

Description

Register data loading observers for the app server

Usage

registerDataLoadObservers(
  input,
  session,
  rv,
  exampleLoadStatus,
  resetModelPage,
  applyLoadedExampleToInputs
)

Arguments

input

Shiny input object.

session

Shiny session object.

rv

App reactive values object.

exampleLoadStatus

Reactive value used to display example load status.

resetModelPage

Function that clears model-page state after a data change.

applyLoadedExampleToInputs

Function that applies loaded example input state.

Value

No return value; called for observer side effects.


Register developer scoring and grading observers

Description

Adds a developer-mode diagnostics panel for deterministic scoring of the currently generated model explanation. The command-line scoring functions remain canonical; the UI only displays their output.

Usage

registerDeveloperScoringGradingObservers(
  input,
  output,
  session,
  rv,
  modelFit,
  developerModeUnlocked
)

Arguments

input

Shiny input object.

output

Shiny output object.

session

Shiny session object.

rv

App reactive values object.

modelFit

Reactive value containing the fitted model.

developerModeUnlocked

Reactive value indicating developer mode status.

Value

A list containing the current developer grade reactive value.


Register fit model observers

Description

Wires formula validation, model fitting, output generation, and reset behaviour for the app server.

Usage

registerFitModelObservers(input, output, session, rv, modelFit, resetModelPage)

Arguments

input

Shiny input object.

output

Shiny output object.

session

Shiny session object.

rv

App reactive values object.

modelFit

Reactive value containing the fitted model.

resetModelPage

Function that clears model-page state.

Value

No return value; called for observer side effects.


Register fitted equation observers

Description

Wires the fitted equation, fitted means header, and fitted means table outputs for the fitted model tab.

Usage

registerFittedEquationObservers(output, rv, modelFit)

Arguments

output

Shiny output object.

rv

App server reactive values object.

modelFit

Reactive value containing the fitted model.

Value

Invisibly returns NULL.


Register model explanation observers for the app server

Description

Register model explanation observers for the app server

Usage

registerModelExplanationObservers(
  input,
  output,
  rv,
  modelFit,
  developerModeUnlocked
)

Arguments

input

Shiny input object.

output

Shiny output object.

rv

App reactive values object.

modelFit

Reactive value containing the fitted model.

developerModeUnlocked

Reactive value indicating developer mode status.

Value

A list of model-explanation reactive helpers.


Register symbolic model formula observers

Description

Wires the symbolic model formula output for the fitted model tab.

Usage

registerModelFormulaObservers(output, modelFit)

Arguments

output

Shiny output object.

modelFit

Reactive value containing the fitted model.

Value

Invisibly returns NULL.


Register model help and data context observers

Description

Wires the model-help button, package data description modal, uploaded-data context modal, and research-question state synchronisation.

Usage

registerModelHelpObservers(input, output, session, rv)

Arguments

input

Shiny input object.

output

Shiny output object.

session

Shiny session object.

rv

App reactive values object.

Value

No return value; called for observer side effects.


Register model output tabs (ANOVA + confidence intervals)

Description

Defines Shiny outputs used in the Fitted Model tab:

Usage

registerModelOutputTabs(output, input, modelFit)

Arguments

output

Shiny output object.

input

Shiny input object.

modelFit

reactiveVal holding fitted model.

Value

None (called for side effects).


Register model plot observers

Description

Wires the original fitted-model plot and the student-facing Model plots tab.

Usage

registerModelPlotObservers(input, output, modelFit)

Arguments

input

Shiny input object.

output

Shiny output object.

modelFit

Reactive value containing the fitted model.

Value

No return value; called for its side effects.


Register model setup observers

Description

Wires variable buckets, interaction selection, response selection, derived-variable creation, and automatic formula updates for the app server.

Usage

registerModelSetupObservers(input, output, session, rv, setBucketState)

Arguments

input

Shiny input object.

output

Shiny output object.

session

Shiny session object.

rv

App reactive values object.

setBucketState

Function used to synchronise factor and continuous buckets.

Value

No return value; called for observer side effects.


Register model output observers for the app server

Description

Register model output observers for the app server

Usage

registerModelSummaryObservers(input, output, modelFit)

Arguments

input

Shiny input object.

output

Shiny output object.

modelFit

Reactive value containing the fitted model.

Value

No return value; called for output side effects.


Register startup data choice observers for the app server

Description

Keeps the startup package scan, example-list loading, and package-dataset choice observers out of the top-level app server so that appServer() can act more like an orchestration layer.

Usage

registerStartupDataChoiceObservers(input, output, session)

Arguments

input

Shiny input object.

output

Shiny output object.

session

Shiny session object.

Value

A list containing startup-related reactive values needed by later server sections.


Remove whitespace from expression text for conservative comparison

Description

Remove whitespace from expression text for conservative comparison

Usage

removeExpressionWhitespace(expressionText)

Arguments

expressionText

Character scalar expression text.

Value

Character scalar.


Remove a locally stored WMFM provider credential

Description

Remove a locally stored WMFM provider credential

Usage

removeWmfmConfigCredential(provider)

Arguments

provider

Character scalar provider id.

Value

Invisibly returns the config file path written.


Render adjustment-variable selection UI

Description

Builds the Stage B adjustment-variable checkbox input from current bucket assignments and keeps stored selections synchronized to eligible choices.

Usage

renderAdjustmentVariablesUi(
  rv,
  responseVariable,
  factorVariables = NULL,
  continuousVariables = NULL,
  selectedAdjustmentVariables = NULL
)

Arguments

rv

App reactive values object.

responseVariable

Name of the current response variable.

Value

A Shiny tag object or NULL when no choices are available.


Render adjustment-variable selection UI from explicit inputs

Description

Pure helper that builds the hidden compatibility checkbox input without reading from reactive values directly.

Usage

renderAdjustmentVariablesUiFromInputs(
  responseVariable,
  factorVariables,
  continuousVariables,
  selectedAdjustmentVariables
)

Arguments

responseVariable

Name of the current response variable.

factorVariables

Character vector of variables in the factor bucket.

continuousVariables

Character vector of variables in the continuous bucket.

selectedAdjustmentVariables

Character vector currently selected as adjustment variables.

Value

A list with ui, eligibleVariables, and selectedVariables.


Build a variable-card label with inline adjustment checkbox

Description

Build a variable-card label with inline adjustment checkbox

Usage

renderBucketVariableLabel(variableName, selectedAdjustmentVariables)

Arguments

variableName

Character scalar variable name to render.

selectedAdjustmentVariables

Character vector of currently selected adjustment variables.

Value

A Shiny tag object suitable for bucket list labels.


Render one deterministic equation case

Description

Converts one deterministic equation specification and one teaching case into rendered equation strings. The output separates the linear predictor from any transformed scales so later stages can decide how to present them.

Usage

renderEquationCase(spec, case, digits = 2)

Arguments

spec

A deterministic equation specification from buildEquationSpec().

case

One equation case from buildEquationCases().

digits

Integer number of decimal places for displayed coefficients. Defaults to 2.

Details

Supported first-pass families are Gaussian identity, binomial logit, and Poisson log models under the package's usual treatment-coding assumptions.

Value

A list of class "wmfmEquationRenderCase".


Render a set of deterministic equation cases

Description

Applies renderEquationCase() to a whole set of deterministic teaching cases.

Usage

renderEquationCases(spec, cases = NULL, digits = 2)

Arguments

spec

A deterministic equation specification from buildEquationSpec().

cases

Optional equation cases from buildEquationCases(). When omitted, the cases are built automatically from spec.

digits

Integer number of decimal places for displayed coefficients. Defaults to 2.

Value

A list of class "wmfmEquationRender".


Render the claim-to-evidence map for the app

Description

Creates a student-facing display that shows each explanation sentence beside a plain-language note about the deterministic evidence that supports it.

Usage

renderExplanationClaimEvidenceUi(claimMap, developerMode = FALSE)

Arguments

claimMap

A wmfmExplanationClaimEvidenceMap object, or NULL.

Value

A Shiny UI object.


Render the explanation teaching summary for the app

Description

Creates a student-facing accordion that explains, in plain language, how the explanation was constructed from the deterministic audit.

Usage

renderExplanationTeachingSummaryUi(summary)

Arguments

summary

A wmfmExplanationTeachingSummary object, or NULL.

Value

A Shiny UI object.


Render the optional tutor-style explanation UI

Description

Render the optional tutor-style explanation UI

Usage

renderExplanationTutorUi(
  text = NULL,
  available = TRUE,
  researchQuestion = NULL,
  dataDescription = NULL
)

Arguments

text

Optional character scalar returned by the chat provider.

available

Logical; whether a chat provider is available.

researchQuestion

Optional character scalar.

dataDescription

Optional character scalar.

Value

A Shiny UI object.


Render a calm labelled confidence-interval explanation panel

Description

Render a calm labelled confidence-interval explanation panel

Usage

renderModelConfidenceIntervalDetailUi(detail)

Arguments

detail

A single detail record.

Value

A Shiny tag list.


Render confidence-interval derivation details as UI

Description

Converts the derivation records produced by buildModelConfidenceIntervalData() into a compact accordion so that students can inspect how a displayed confidence interval is constructed without overwhelming the main table.

Usage

renderModelConfidenceIntervalDetailsUi(details)

Arguments

details

A list of derivation records.

Value

A Shiny UI object.


Render the explanation-audit panel for the app

Description

Creates a student-facing note explaining that the app now shows a teaching summary rather than the raw audit structure directly.

Usage

renderModelExplanationAuditUi(audit)

Arguments

audit

A wmfmExplanationAudit object, or NULL.

Value

A Shiny UI object.


Render a one-way fitted-means table as HTML tags

Description

Creates a simple HTML table (as Shiny tag objects) for a one-factor fitted means display.

Usage

renderOneWayTable(df, rowVar, valueName)

Arguments

df

A data frame containing the factor column and a fitted mean column.

rowVar

The name of the factor column used for rows.

valueName

The name of the numeric fitted-mean column (e.g. ".fit").

Value

A Shiny tag object representing an HTML table.

Examples

if (requireNamespace("shiny", quietly = TRUE)) {
  df = data.frame(A = c("a","b"), .fit = c(1.2, 2.3))
  renderOneWayTable(df, "A", ".fit")
}


Render explanation text as safe paragraph HTML

Description

Render explanation text as safe paragraph HTML

Usage

renderSafeExplanationHtml(text, zoomLevel = "normal")

Arguments

text

Character scalar explanation text.

zoomLevel

Character scalar zoom level from the UI control.

Value

A shiny tag object containing safe paragraph HTML.


Convert backticked names into code-style chips for UI display

Description

Convert backticked names into code-style chips for UI display

Usage

renderTeachingSummaryText(text)

Arguments

text

A single character string.

Value

A Shiny UI paragraph tag.


Render a two-way fitted-means table as HTML tags

Description

Creates a simple HTML two-way table (as Shiny tag objects) where one factor defines the rows and another defines the columns. Cells are filled from df[[valueName]] for each rowVar-colVar combination.

Usage

renderTwoWayTable(df, rowVar, colVar, valueName)

Arguments

df

A data frame containing rowVar, colVar, and valueName.

rowVar

Name of the factor used for table rows.

colVar

Name of the factor used for table columns.

valueName

Name of the numeric fitted-mean column (e.g. ".fit").

Value

A Shiny tag object representing an HTML table.

Examples

if (requireNamespace("shiny", quietly = TRUE)) {
  df = data.frame(
    A = rep(c("a","b"), each = 2),
    B = rep(c("u","v"), times = 2),
    .fit = c(1, 2, 3, 4)
  )
  renderTwoWayTable(df, "A", "B", ".fit")
}


Render a variable summary table as Shiny UI

Description

Converts a variable-summary data frame (as produced by buildVarSummary()) into a simple HTML table for display in a Shiny UI.

Usage

renderVarSummaryUi(summaryDf)

Arguments

summaryDf

A data frame with (at minimum) columns var, class, missing, and details.

Value

A Shiny tag object (a shiny.tag.list) containing a table.


Reset non-secret provider settings to package defaults

Description

Reset non-secret provider settings to package defaults

Usage

resetNonSecretProviderConfig()

Value

Invisibly returns the config file path written by writeWmfmConfig().


Resolve the source explanation for bad explanation generation

Description

Resolve the source explanation for bad explanation generation

Usage

resolveBadExplanationSource(x, explanation = NULL)

Arguments

x

A wmfmModel object.

explanation

Optional user-supplied explanation.

Value

A character scalar giving the base explanation.


Resolve developer-mode startup state

Description

Developer mode is visible only when WMFM_SHOW_DEVELOPER_MODE=1 is set locally. When the UI is visible, the enabled/disabled state is restored from the non-secret WMFM config file so development sessions can resume with the same controls enabled.

Usage

resolveDeveloperModePreference()

Value

Logical scalar.


Resolve the developer scoring model type

Description

Resolve the developer scoring model type

Usage

resolveDeveloperScoringModelType(model, modelType = NULL)

Arguments

model

A fitted model object.

modelType

Optional UI model type.

Value

A character scalar.


Resolve run-level data for metric diagnosis

Description

Internal helper for diagnose().

Usage

resolveMetricDiagnosisData(scores, metric, cmp = NULL, runs = NULL)

Arguments

scores

A wmfmScores object.

metric

A single metric name.

cmp

Optional wmfmScoreComparison object.

runs

Optional wmfmRuns object or compatible run container.

Value

A data frame with one row per run.


Resolve a fitted model object for model-plot helpers

Description

Resolve a fitted model object for model-plot helpers

Usage

resolveModelPlotModel(model)

Arguments

model

A fitted model object or a wmfmModel object.

Value

A fitted model object.


Resolve the response noun phrase for a fitted model

Description

Resolve the response noun phrase for a fitted model

Usage

resolveResponseNounPhrase(model, responseVar)

Arguments

model

Fitted model object.

responseVar

Character scalar response variable name.

Value

Character scalar noun phrase.


Resolve the active WMFM provider profile

Description

Resolve the active WMFM provider profile

Usage

resolveWmfmActiveProviderProfile(profileId = NULL, backend = NULL)

Arguments

profileId

Optional provider profile identifier.

backend

Optional provider type fallback for legacy configuration.

Value

A normalised provider profile.


Resolve effective WMFM provider configuration

Description

Computes the effective provider configuration from explicit values and options while preserving WMFM defaults.

Usage

resolveWmfmProviderConfig(
  backend = NULL,
  ollamaBaseUrl = NULL,
  ollamaModel = NULL,
  ollamaThinkLow = NULL
)

Arguments

backend

Optional backend override.

ollamaBaseUrl

Optional Ollama base URL override.

ollamaModel

Optional Ollama model override.

ollamaThinkLow

Optional low-thinking override.

Value

Named list with normalized provider config.


Resolve WMFM provider credential availability

Description

Environment variables have priority over local config credentials so deployed and scripted use can override desktop settings predictably.

Usage

resolveWmfmProviderCredential(provider)

Arguments

provider

Character scalar provider id.

Value

Named list with non-secret credential availability metadata.


Resolve WMFM provider credentials

Description

Resolves non-secret credential metadata for supported chat providers without exposing secret values.

Usage

resolveWmfmProviderCredentials()

Value

Named list keyed by provider id. Each provider entry contains provider, requiresCredentials, credentialsAvailable, credentialSource, and localOnly fields.


Resolve a provider profile by identifier

Description

Resolve a provider profile by identifier

Usage

resolveWmfmProviderProfileById(
  profileId,
  profiles = readWmfmProviderProfiles()
)

Arguments

profileId

Character scalar provider profile identifier.

profiles

Optional list of provider profiles.

Value

A normalised provider profile when available, otherwise NULL.


Check whether original response scale should drive interpretation

Description

Check whether original response scale should drive interpretation

Usage

responseBackTransformationUsesOriginalScale(payload)

Arguments

payload

Response back-transformation payload.

Value

Logical scalar.


Run a packaged WMFM example one or more times

Description

Loads a packaged example, fits the specified model, generates equations and a plain-language explanation, and stores each run as a separate raw run record.

Usage

runExample(
  name,
  package = "WMFM",
  nRuns = 1,
  printOutput = FALSE,
  pauseSeconds = 0,
  showProgress = TRUE,
  useExplanationCache = FALSE,
  interactionAlpha = 0.05,
  ...
)

Arguments

name

Character. Name of the packaged example.

package

Character. Package containing the example. Defaults to "WMFM".

nRuns

Integer. Number of runs to perform. Defaults to 1.

printOutput

Logical. Passed to runModel().

pauseSeconds

Numeric. Optional delay between runs.

showProgress

Logical. Should a console progress bar and timing summary be shown when work is repeated?

useExplanationCache

Logical. Passed to runModel(). Defaults to FALSE so repeated runs will usually query the LLM afresh.

interactionAlpha

Numeric. Threshold used when judging whether interaction evidence wording is appropriate in buildWmfmRunRecord().

...

Additional arguments passed to runModel().

Details

This function is a unified replacement for separate single-run and repeated-run entry points. Use nRuns = 1 for a single run.

No scoring is performed here. Scoring should be done later using score() on the returned object.

Value

An object of class wmfmRuns with elements:

exampleName

Example name.

package

Package name.

spec

Parsed example specification.

dataContext

Optional example context text.

researchQuestion

Optional example research question text.

runs

List of raw run records.

meta

Metadata about the run set, including elapsed time, average per-run time, and per-run timing details.

Examples

if (interactive()) {
  x = runExample("Course")
  y = runExample("Course", nRuns = 20)
}


Fit a WMFM model and generate command-line outputs

Description

Fits a model using a supplied dataset and formula, optionally attaches dataset context, and then attempts to generate fitted equations and a model explanation using the same helper functions used by the app.

Usage

runModel(
  data,
  formula,
  modelType = c("lm", "logistic", "poisson"),
  dataContext = NULL,
  researchQuestion = NULL,
  variableTransformations = NULL,
  responseTransformationMode = "both",
  ollamaBaseUrl = NULL,
  generateExplanation = TRUE,
  printOutput = TRUE,
  useExplanationCache = TRUE,
  equationMethod = c("deterministic", "llm")
)

Arguments

data

A data.frame containing the variables used in the model.

formula

A model formula, either as a formula object or a character string that can be converted to a formula.

modelType

A character string giving the model family. Must be one of "lm", "logistic", or "poisson".

dataContext

Optional character string giving additional context about the dataset, study, variables, coding, or research aim.

researchQuestion

Optional character string giving the research question the user wants the fitted model to help answer.

variableTransformations

Optional named list of derived-variable transformation records to preserve when the fitted formula uses derived variables.

responseTransformationMode

Character scalar describing how later response-scale interpretation should handle recognised response transformations. One of "both", "model", or "original".

ollamaBaseUrl

Optional character string giving the base URL for the language model service.

generateExplanation

Logical. If TRUE, attempt to contact the configured chat provider and generate model-explanation text. Set to FALSE in deterministic tests or offline workflows that only need the fitted model, equations, audit, and metadata.

printOutput

Logical. If TRUE, prints the model summary, fitted equations, and explanation to the console.

useExplanationCache

Logical. Should cached explanation text be reused when the same fitted model is encountered? Defaults to TRUE.

equationMethod

Character string giving the equation engine. Must be one of "deterministic" or "llm". Defaults to "deterministic".

Details

Supported model types are linear regression, logistic regression, and Poisson regression.

Explanation caching can be controlled via useExplanationCache. For normal usage this can remain TRUE, but when repeatedly querying the language model for the same fitted model it is often useful to set it to FALSE so that each run makes a fresh explanation request.

The returned object also includes interaction-term names and the minimum interaction-term p-value, which can be used later when evaluating whether the explanation interpreted interaction evidence appropriately.

Value

Invisibly returns an object of class wmfmModel.


Run the Model Builder app

Description

Launches the WMFM Shiny application. The Ollama base URL used for language-model calls can be configured here.

Usage

runWMFMApp(ollamaBaseUrl = NULL)

Arguments

ollamaBaseUrl

Optional character string giving the base URL of the Ollama server, for example "http://localhost:11434". If NULL, the function uses the current value of the option "wmfm.ollama_base_url" if set, otherwise a built-in default.

Value

A shiny.appobj, invisibly.


Run one tracked command-line stage

Description

Run one tracked command-line stage

Usage

runWmfmCliStage(cliTracker, stageLabel, code)

Arguments

cliTracker

A tracker created by newWmfmCliStageTracker().

stageLabel

Character scalar describing the stage.

code

Function with no arguments to execute.

Value

The return value of code().


Safely convert a scalar-like object to character text

Description

Converts a scalar-like object to a single character value suitable for prompt construction. This helper handles common edge cases such as NULL, empty vectors, factors, date-time objects, and single-element lists.

Usage

safeWmfmScalar(x, naString = "NA", trim = TRUE, singleLine = FALSE)

Arguments

x

Object to convert.

naString

Character string to return for missing or empty values. Defaults to "NA".

trim

Logical. Should surrounding whitespace be removed? Defaults to TRUE.

singleLine

Logical. Should internal whitespace be collapsed to a single space? Defaults to FALSE.

Value

A character scalar.


Sanitise developer scoring export values for JSON

Description

Converts provider objects, grade internals, and classed values into plain JSON-safe lists, data frames, vectors, and scalars before serialisation.

Usage

sanitiseDeveloperScoringJsonValue(x, depth = 0L, maxDepth = 10L)

Arguments

x

Object to sanitise.

depth

Current recursion depth.

maxDepth

Maximum recursion depth.

Value

A plain JSON-safe object.


Sanitize user-selected adjustment variables

Description

Restricts user-selected adjustment variables to currently eligible variables, removes duplicates, and drops empty values.

Usage

sanitizeAdjustmentVariables(selectedVariables, eligibleVariables)

Arguments

selectedVariables

Character vector selected in the UI.

eligibleVariables

Character vector of eligible adjustment variables.

Value

Character vector of sanitized adjustment variables.


Persist developer-mode state locally

Description

Persist developer-mode state locally

Usage

saveDeveloperModePreference(enabled)

Arguments

enabled

Logical scalar.

Value

Invisibly returns the config file path written by writeWmfmConfig().


Persist settings-side non-secret provider config

Description

Persist settings-side non-secret provider config

Usage

saveNonSecretProviderConfig(providerConfig)

Arguments

providerConfig

Named list with non-secret provider configuration.

Value

Invisibly returns the config file path written by writeWmfmConfig().


Score WMFM objects

Description

Generic for scoring WMFM objects.

Usage

score(x, ...)

Arguments

x

An object to score.

...

Additional arguments passed to methods.

Value

Method-specific scored output.


Score a WMFM grade object

Description

Scores a wmfmGrade object using either the deterministic WMFM rubric or an LLM-based scoring rubric. The candidate explanation is always scored. If a reference answer is present, it is scored separately and used to enrich feedback.

Usage

## S3 method for class 'wmfmGrade'
score(
  x,
  method = c("deterministic", "llm"),
  preferredMinWords = 80L,
  preferredMaxWords = 220L,
  fatalFlawCap = 40,
  passThreshold = 65,
  chat = NULL,
  useCache = FALSE,
  showProgress = TRUE,
  verbose = FALSE,
  nLlm = 1L,
  ...
)

Arguments

x

A wmfmGrade object.

method

Character. One of "deterministic" or "llm".

preferredMinWords

Integer. Passed to deterministic scoring.

preferredMaxWords

Integer. Passed to deterministic scoring.

fatalFlawCap

Numeric. Passed to deterministic scoring.

passThreshold

Numeric. Passed to deterministic scoring.

chat

Optional chat provider object. Used for LLM scoring.

useCache

Logical. Passed to LLM scoring.

showProgress

Logical. Should progress messages be shown for LLM scoring?

verbose

Logical. Passed to LLM scoring.

nLlm

Integer. Number of repeated LLM gradings for the student explanation.

...

Additional arguments passed to the relevant scoring helper.

Value

A scored wmfmGrade object.


Score a WMFM grade list object

Description

Scores each contained wmfmGrade object and records batch-level timing.

Usage

## S3 method for class 'wmfmGradeListObj'
score(
  x,
  method = c("deterministic", "llm", "both"),
  nLlm = 1L,
  confirmLargeLlmJob = FALSE,
  maxLlmJobsWithoutConfirmation = 20L,
  showProgress = TRUE,
  ...
)

Arguments

x

A wmfmGradeListObj object.

method

Character. One of "deterministic", "llm", or "both".

nLlm

Integer. Number of repeated LLM gradings per explanation.

confirmLargeLlmJob

Logical. Whether to allow large requests.

maxLlmJobsWithoutConfirmation

Integer. Maximum number of LLM calls allowed without explicit confirmation.

showProgress

Logical. Should progress messages be shown?

...

Additional arguments passed to score.wmfmGrade().

Value

A scored wmfmGradeListObj object.


Score a WMFM runs object

Description

Scores a wmfmRuns object using deterministic scoring, LLM scoring, or both, and returns a separate wmfmScores object.

Usage

## S3 method for class 'wmfmRuns'
score(
  x,
  method = c("deterministic", "llm", "both"),
  chat = NULL,
  useCache = FALSE,
  showProgress = TRUE,
  verbose = FALSE,
  ...
)

Arguments

x

A wmfmRuns object created by runExample().

method

Character. One of "deterministic", "llm", or "both".

chat

Optional chat provider object. If omitted and LLM scoring is requested, a provider is obtained via getChatProvider().

useCache

Logical. Passed to LLM scoring helpers.

showProgress

Logical. Should progress and timing be shown for LLM scoring?

verbose

Logical. Passed to LLM scoring helpers.

...

Reserved for future method-specific arguments.

Details

This method assumes that x is a raw runs object produced by runExample(). Judged fields and aggregate scores are created during the scoring step and are stored only in the returned wmfmScores object.

Value

An object of class wmfmScores.


Grade the current app explanation for developer scoring

Description

Grade the current app explanation for developer scoring

Usage

scoreDeveloperExplanation(
  model,
  rv,
  input,
  explanationText,
  method = "deterministic"
)

Arguments

model

A fitted model object from the app.

rv

App reactive values object.

input

Shiny input object.

explanationText

Character scalar explanation text.

method

Character scalar naming the scoring method.

Value

A scored wmfmGrade object.


Score repeated WMFM explanation runs using a multidimensional rubric

Description

Applies a rubric-based scoring framework to repeated WMFM explanation runs. The scoring structure is designed to align with the revised buildWmfmRunRecord() schema by separating:

Usage

scoreWmfmRepeatedRuns(
  runsDf,
  preferredMinWords = 80L,
  preferredMaxWords = 220L,
  penaliseDuplicates = TRUE,
  duplicatePenalty = 5,
  fatalFlawCap = 40,
  passThreshold = 65,
  factualWeight = 0.3,
  inferenceWeight = 0.25,
  completenessWeight = 0.2,
  clarityWeight = 0.15,
  calibrationWeight = 0.1
)

Arguments

runsDf

A data.frame of repeated-run outputs, or a list containing a runsDf element.

preferredMinWords

Integer. Lower bound for a preferred explanation length band.

preferredMaxWords

Integer. Upper bound for a preferred explanation length band.

penaliseDuplicates

Logical. Should exact duplicate explanations be penalised?

duplicatePenalty

Numeric penalty subtracted from the final overallScore for exact duplicates.

fatalFlawCap

Numeric in 0 to 100. Maximum allowed overall score when fatalFlawDetected is TRUE.

passThreshold

Numeric in 0 to 100. Threshold used to create overallPass.

factualWeight

Numeric weight for the factual dimension.

inferenceWeight

Numeric weight for the inference dimension.

completenessWeight

Numeric weight for the completeness dimension.

clarityWeight

Numeric weight for the clarity dimension.

calibrationWeight

Numeric weight for the calibration dimension.

Details

  1. descriptive metadata about the run,

  2. extracted claim variables describing what the explanation said,

  3. judged quality variables describing whether those claims were appropriate, and

  4. aggregate dimension scores.

The function accepts either:

Rubric dimensions

The function scores explanations across five dimensions:

Factual score

How well the explanation states the main effect, effect scale, reference-group structure, and interaction substance.

Inference score

How appropriate the explanation's inferential language is, especially for uncertainty and interaction evidence.

Completeness score

Whether the explanation covers the important ingredients that the model structure suggests should be present.

Clarity score

Whether the explanation is reasonably clear, sensibly expressed, and not excessively short or long.

Calibration score

Whether the explanation avoids overclaiming and severe underclaiming.

Judged fields created here

This function fills or overwrites the following judged fields when they are missing or NA:

effectDirectionCorrect

Integer in 0, 1, 2.

effectScaleAppropriate

Integer in 0, 1, 2.

referenceGroupHandledCorrectly

Integer in 0, 1, 2.

interactionCoverageAdequate

Integer in 0, 1, 2.

interactionSubstantiveCorrect

Integer in 0, 1, 2.

uncertaintyHandlingAppropriate

Integer in 0, 1, 2.

inferentialRegisterAppropriate

Integer in 0, 1, 2.

mainEffectCoverageAdequate

Integer in 0, 1, 2.

referenceGroupCoverageAdequate

Integer in 0, 1, 2.

clarityAdequate

Integer in 0, 1, 2.

numericExpressionAdequate

Integer in 0, 1, 2.

comparisonStructureClear

Integer in 0, 1, 2.

fatalFlawDetected

Logical.

Aggregate fields created here

factualScore

Numeric score on a 0 to 2 scale.

inferenceScore

Numeric score on a 0 to 2 scale.

completenessScore

Numeric score on a 0 to 2 scale.

clarityScore

Numeric score on a 0 to 2 scale.

calibrationScore

Numeric score on a 0 to 2 scale.

overallScore

Numeric weighted score on a 0 to 100 scale.

overallPass

Logical.

Duplicate detection is based on normalizedExplanation when available, otherwise on trimmed explanation text.

Fatal flaws do not force the score to zero, but they cap the final overall score using fatalFlawCap.

Value

A data.frame with judged quality columns and dimension scores added.


Score a single WMFM run record using a language model

Description

Sends a scoring request to the supplied chat provider and returns a pure score record containing judged fields and score summaries. The input run record is not modified.

Usage

scoreWmfmRunWithLlm(runRecord, chat, useCache = FALSE, verbose = FALSE)

Arguments

runRecord

Named list produced by buildWmfmRunRecord().

chat

A chat provider object as returned by getChatProvider().

useCache

Logical. Should scoring results be cached and reused for identical run records? Defaults to FALSE.

verbose

Logical. Should the raw scoring response be printed? Defaults to FALSE.

Details

This function expects a chat provider object returned by getChatProvider() and uses chat$chat(prompt).

Value

Named list containing only scored fields and LLM scoring metadata.


Score multiple WMFM runs using an LLM

Description

Scores each raw run record in a wmfmRuns object using an LLM-based scorer. The returned value is a list of score records containing only judged fields and score summaries. The input run records are not modified.

Usage

scoreWmfmRunsWithLlm(
  runRecords,
  chat,
  useCache = FALSE,
  showProgress = TRUE,
  verbose = FALSE
)

Arguments

runRecords

List of raw WMFM run records.

chat

Chat provider object used for LLM scoring.

useCache

Logical. Whether to allow cached LLM responses.

showProgress

Logical. Whether to display progress and timing information during scoring.

verbose

Logical. Whether to print additional diagnostic information.

Details

Timing metadata is attached to the returned list as an attribute named "timing".

Value

A list of score records. Each element corresponds to one input run record and contains only judged fields and score summaries. A "timing" attribute is attached to the returned list.


Select evidence rows for a sentence-level claim

Description

Select evidence rows for a sentence-level claim

Usage

selectExplanationEvidenceForClaim(
  claimTags = NULL,
  claimType = NULL,
  claimText,
  audit,
  teachingSummary,
  evidenceInventory
)

Arguments

claimTags

Optional character vector of detected tags.

claimType

Optional legacy single-type label kept for compatibility.

claimText

Character scalar.

audit

A wmfmExplanationAudit object.

teachingSummary

Optional teaching summary object.

evidenceInventory

Evidence inventory data frame.

Value

A data frame.


Select flagged runs for metric diagnosis

Description

Internal helper for diagnose() that selects the most informative disagreement cases for inspection.

Usage

selectFlaggedMetricRuns(metricDf, maxExamples = 5)

Arguments

metricDf

Run-level metric diagnosis data.

maxExamples

Maximum number of examples to return.

Value

A data frame.


Determine whether adjustment-output controls should be shown

Description

Determine whether adjustment-output controls should be shown

Usage

shouldShowAdjustmentOutputControls(model)

Arguments

model

Fitted model object or NULL.

Value

TRUE when the fitted model includes at least one adjustment variable; otherwise FALSE.


Convert sentence-opening digits into words when simple

Description

Convert sentence-opening digits into words when simple

Usage

spellOutSentenceStartNumber(text)

Arguments

text

A single character string.

Value

A single character string.


Split an explanation into sentence-level claim units

Description

Split an explanation into sentence-level claim units

Usage

splitExplanationIntoClaimUnits(explanationText)

Arguments

explanationText

Character scalar.

Value

Character vector.


Assess stability of WMFM objects

Description

Generic for assessing stability of WMFM objects.

Usage

stability(x, ...)

Arguments

x

An object to assess.

...

Additional arguments passed to methods.

Value

Method-specific stability output.


Assess stability of WMFM score results

Description

Summarises within-method stability of scores stored in a wmfmScores object. Stability is summarised separately for binary, ordinal, and continuous score fields.

Usage

## S3 method for class 'wmfmScores'
stability(x, ...)

Arguments

x

A wmfmScores object.

...

Unused. Included for S3 compatibility.

Value

An object of class wmfmScoreStability.


Store a developer-mode password hash

Description

Backward-compatible alias for makeDeveloperModePasswordHash().

Usage

storeDeveloperModePasswordHash(password)

Arguments

password

Character scalar giving the plain-text password.

Value

A salted password hash string.


Synchronize a formula response with a recorded derived response

Description

When a user has selected a derived response variable, the selected response variable should be authoritative for the fitted formula. The formula left-hand side is replaced with the selected response variable name while preserving the existing right-hand side. This keeps the fitted model connected to the stored transformation metadata used for back-transformation even when the previous formula left-hand side contains a stale inline expression.

Usage

substituteDerivedResponseInFormula(
  formulaText,
  responseVar,
  variableTransformations = NULL
)

Arguments

formulaText

Character scalar model formula text.

responseVar

Character scalar selected response variable.

variableTransformations

Named list of derived-variable transformation records.

Value

Character scalar formula text, possibly with the left-hand side replaced by responseVar.


Summarise agreement for a binary metric

Description

Summarises agreement between two binary vectors.

Usage

summariseBinaryAgreement(leftVec, rightVec, metricRow)

Arguments

leftVec

Vector of left-side values.

rightVec

Vector of right-side values.

metricRow

Single-row metric registry data frame.

Value

A one-row data frame, or NULL if no complete pairs are available.


Summarise agreement for a continuous metric

Description

Summarises agreement between two continuous vectors using mean differences, absolute differences, correlation, and Bland-Altman limits of agreement.

Usage

summariseContinuousAgreement(leftVec, rightVec, metricRow)

Arguments

leftVec

Vector of left-side values.

rightVec

Vector of right-side values.

metricRow

Single-row metric registry data frame.

Value

A one-row data frame, or NULL if no complete pairs are available.


Summarise repeated developer scoring fixture stability

Description

Builds audit-only summary tables from developer scoring fixtures exported by the developer scoring UI. This helper does not rescore explanations or change any scoring decisions; it only summarises the scores and metric values already present in the supplied fixtures.

Usage

summariseDeveloperScoringAudit(
  fixtures,
  metricLabels = NULL,
  unstableSpreadThreshold = 2,
  lowMarkThreshold = 4,
  metricSpreadThreshold = 1
)

Arguments

fixtures

Named list of developer scoring fixture payloads.

metricLabels

Character vector of metric labels to audit. When NULL, all metric labels found in the fixtures are included.

unstableSpreadThreshold

Numeric mark spread at or above which an example is flagged as unstable.

lowMarkThreshold

Numeric mark at or below which a run is flagged as a low-mark run.

metricSpreadThreshold

Numeric metric-value spread at or above which a metric is flagged as unstable within an example.

Value

A list with runSummary, exampleSummary, metricSummary, and unstableMetrics data frames.


Summarise metric-level comparison and deterministic ease

Description

Builds a metric-level summary combining cross-method disagreement with deterministic stability/ease measures.

Usage

summariseMetricComparison(
  scores,
  comparison,
  deterministicMethod = "deterministic",
  orderBy = NULL
)

Arguments

scores

A wmfmScores object.

comparison

A wmfmScoreComparison object.

deterministicMethod

Name of deterministic method.

orderBy

Optional ordering: NULL, "disagreement", or "ease".

Value

An object of class metricComparisonSummary.


Summarise agreement for an ordinal metric

Description

summarises agreement between two ordinal vectors using exact agreement, adjacent agreement, mean differences, and quadratic weighted kappa.

Usage

summariseOrdinalAgreement(leftVec, rightVec, metricRow)

Arguments

leftVec

Vector of left-side values.

rightVec

Vector of right-side values.

metricRow

Single-row metric registry data frame.

Details

WMFM ordinal judged fields are currently stored as integer-like values 0, 1, and 2. The registry's orderedLevels is used as the source of truth for mapping values onto the ordinal scale.

Value

A one-row data frame, or NULL if no complete pairs are available.


Summarise a WMFM grade object

Description

Produces a compact summary for a wmfmGrade object. When repeated LLM grading has been used, the summary includes run-to-run mark variability and per-dimension ranges.

Usage

## S3 method for class 'wmfmGrade'
summary(object, method = NULL, ...)

Arguments

object

A wmfmGrade object.

method

Optional character. One of "deterministic" or "llm".

...

Unused.

Value

An object of class summary.wmfmGrade.


Summarise a WMFM grade list object

Description

Summarise a WMFM grade list object

Usage

## S3 method for class 'wmfmGradeListObj'
summary(object, ...)

Arguments

object

A wmfmGradeListObj object.

...

Unused.

Value

An object of class summary.wmfmGradeListObj.


Summarise a WMFM runs object

Description

Produces a concise summary of a raw wmfmRuns object. The summary focuses on run-level variability, text metrics, timing, duplication, and extracted claim frequencies. Judged fields and score summaries are intentionally excluded and belong to wmfmScores objects instead.

Usage

## S3 method for class 'wmfmRuns'
summary(object, ...)

Arguments

object

A wmfmRuns object.

...

Reserved for future extensions.

Value

An object of class summary.wmfmRuns.


Sync selected adjustment variables from user input

Description

Sanitizes user checkbox selections against current eligible variables and stores the synchronized values in reactive state.

Usage

syncAdjustmentVariablesSelection(rv, responseVariable, selectedVariables)

Arguments

rv

App reactive values object.

responseVariable

Name of the current response variable.

selectedVariables

Character vector selected by the user.

Value

No return value; updates rv$adjustmentVariables.


Detect whether a model term involves adjustment variables

Description

Checks whether a term label (main effect or interaction) includes at least one variable currently marked as an adjustment variable.

Usage

termInvolvesAdjustmentVariable(termLabel, adjustmentVariables)

Arguments

termLabel

Character scalar term label, such as "x" or "x:z".

adjustmentVariables

Character vector of adjustment-variable names.

Value

Logical scalar indicating whether the term involves an adjustment variable.


Tokenize a claim or question for overlap matching

Description

Tokenize a claim or question for overlap matching

Usage

tokenizeExplanationClaimText(text)

Arguments

text

Character scalar.

Value

Character vector.


Schema for LM equations returned by the LLM

Description

Defines the structured output schema for fitted regression model equations. This is only used with providers that support structured outputs.

Usage

typeLmEquations

Format

An ellmer type object schema with condition and equation fields for each equation.


Update a WMFM progress tracker

Description

Internal helper that records the time for one finished iteration, updates the progress bar, and prints timing summaries.

Usage

updateWmfmProgressTracker(tracker, step, stepSeconds)

Arguments

tracker

Tracker environment created by newWmfmProgressTracker().

step

Integer. Completed step number.

stepSeconds

Numeric. Time taken for the completed step.

Value

The updated tracker environment, invisibly.


List valid response variables for a model type

Description

Returns the names of variables in a data frame that are supported as response variables for the specified model type.

Usage

validResponseVars(data, modelType)

Arguments

data

A data frame.

modelType

Model type passed to validateResponseVar().

Value

A character vector of variable names.


Validate a bad explanation generation request

Description

Validate a bad explanation generation request

Usage

validateBadExplanationRequest(
  x,
  explanation,
  type,
  severity,
  n,
  mixTypes,
  labelErrors
)

Arguments

x

A wmfmModel object.

explanation

Optional character scalar giving the base explanation.

type

Character vector of bad explanation types, or "auto".

severity

Character scalar.

n

Integer scalar.

mixTypes

Logical scalar.

labelErrors

Logical scalar.

Value

Invisibly returns TRUE when validation succeeds.


Validate parsed bad explanation output

Description

Validate parsed bad explanation output

Usage

validateBadExplanationResponse(parsed, plan)

Arguments

parsed

Parsed JSON object.

plan

Plan object produced by buildBadExplanationPlan().

Value

Validated parsed object.


Validate a response variable for a given model type

Description

Determines whether a candidate response variable is compatible with the model-fitting logic implemented in the package.

Usage

validateResponseVar(data, responseVar, modelType)

Arguments

data

A data frame containing the response variable.

responseVar

A character string naming the response variable.

modelType

A character string: "lm", "logistic", or "poisson".

Details

This function exists to prevent unsupported modelling choices such as multi-level categorical responses for logistic regression (multinomial models are not implemented).

Supported response types:

Value

A list with components:

ok

Logical; whether the response is supported.

reason

Character string explaining the decision.


Validate a WMFM explanation audit object

Description

Checks that an object has the expected class and required top-level fields used by the deterministic explanation-audit workflow.

Usage

validateWmfmExplanationAudit(x, allowNull = FALSE)

Arguments

x

Object to validate.

allowNull

Logical. If TRUE, NULL is accepted and returned invisibly. Defaults to FALSE.

Value

Invisibly returns TRUE when validation succeeds.


Validate a WMFM metric registry

Description

Checks that a WMFM metric registry has the required columns and structurally valid values.

Usage

validateWmfmMetricRegistry(registry)

Arguments

registry

A data frame describing WMFM metrics.

Value

Invisibly returns TRUE if the registry is valid.


Validate parsed WMFM LLM scores

Description

Validates the structure and allowable values of a parsed JSON scoring response before it is written back into a run record.

Usage

validateWmfmParsedScores(parsedScores)

Arguments

parsedScores

Named list produced by parseWmfmScoringJson().

Value

The validated and type-normalised score list.


Convert one variable-transformation record to an audit row

Description

Convert one variable-transformation record to an audit row

Usage

variableTransformationAuditRow(record, roleMap = character(0))

Arguments

record

A wmfmVariableTransformation record.

roleMap

Named character vector of model roles.

Value

A one-row data frame.


Verify the developer-mode password

Description

Compares a candidate password against the salted hash stored in the WMFM_DEVELOPER_MODE_PASSWORD_HASH environment variable.

Usage

verifyDeveloperModePassword(password)

Arguments

password

Character scalar giving the candidate password.

Value

Logical scalar. Returns TRUE when the password matches and FALSE otherwise.


WMFM local configuration directory

Description

Returns the directory used for non-secret local WMFM configuration.

Usage

wmfmConfigDir()

Value

Character scalar path.


WMFM local configuration file path

Description

WMFM local configuration file path

Usage

wmfmConfigPath()

Value

Character scalar path to local configuration file.


WMFM default chat provider configuration

Description

Returns the package defaults used when provider-related options or app-state values are missing.

Usage

wmfmProviderDefaults()

Value

Named list with default backend, Ollama base URL, Ollama model, and Ollama low-thinking flag.


WMFM provider adapter registry

Description

Returns deterministic metadata describing supported and future-ready providers, including the adapter construction kind used by WMFM.

Usage

wmfmProviderRegistry()

Value

Named list keyed by provider id.


Write WMFM local configuration

Description

Persists non-secret provider defaults for local reuse while preserving any separately managed local credential block already present in the same WMFM configuration file.

Usage

writeWmfmConfig(config = list())

Arguments

config

Named list with provider defaults to persist.

Value

Invisibly returns the path that was written.


Write a locally stored WMFM provider credential

Description

Write a locally stored WMFM provider credential

Usage

writeWmfmConfigCredential(provider, credential)

Arguments

provider

Character scalar provider id.

credential

Character scalar credential value.

Value

Invisibly returns the config file path written.