Learn R Programming

EnTraineR (version 1.0.0)

trainer_MCA: Trainer: Name an MCA dimension (FactoMineR::MCA) with an LLM-ready prompt

Description

Builds an English-only, audience-tailored prompt to name and justify a Multiple Correspondence Analysis (MCA) dimension from a FactoMineR::MCA object. The function never invents numbers: it passes verbatim excerpts from summary(mca_obj) and FactoMineR::dimdesc() filtered at a given significance threshold proba, and instructs how to read and name the axis.

Usage

trainer_MCA(
  mca_obj,
  dimension = 1L,
  proba = 0.05,
  introduction = NULL,
  audience = c("beginner", "applied", "advanced"),
  summary_only = FALSE,
  llm_model = "llama3",
  generate = FALSE
)

Value

If generate = FALSE, a character prompt string. If generate = TRUE, a list with prompt, response, and model.

Arguments

mca_obj

A MCA object returned by FactoMineR::MCA().

dimension

Integer scalar; the dimension (component) to name (default 1).

proba

Numeric in (0,1]; significance threshold used by FactoMineR::dimdesc() to characterize the dimension (default 0.05).

introduction

Optional character string giving the study context. Defaults to a generic description.

audience

One of c("beginner","applied","advanced").

summary_only

Logical; if TRUE, return a compact 3-bullet executive summary (uses trainer_core_summary_only_block()).

llm_model

Character; model name for your generator backend (default "llama3").

generate

Logical; if TRUE, calls trainer_core_generate_or_return() and returns a list with prompt, response, and model. If FALSE, returns the prompt string.

Examples

Run this code
if (FALSE) {
# Example: tea (FactoMineR)
if (requireNamespace("FactoMineR", quietly = TRUE)) {
  data(tea, package = "FactoMineR")
  res_mca <- FactoMineR::MCA(tea, quanti.sup = 19, quali.sup = 20:36, graph = FALSE)

  intro <- "A survey on tea consumption practices and contexts was summarized by MCA."
  intro <- gsub("\n", " ", intro); intro <- gsub("\\s+", " ", intro)

  # Applied audience
  prompt <- trainer_MCA(res_mca,
                        dimension = 1,
                        proba = 0.01,
                        introduction = intro,
                        audience = "applied",
                        generate = FALSE)
  cat(prompt)

  res <- gemini_generate(prompt, compile_to = "html")
}
}

Run the code above in your browser using DataLab