Learn R Programming

EnTraineR (version 1.0.0)

trainer_PCA: Trainer: Name a PCA dimension (FactoMineR::PCA) with an LLM-ready prompt

Description

Builds an English-only, audience-tailored prompt to name and justify a principal component (dimension) from a FactoMineR::PCA object. The function never invents numbers: it passes verbatim excerpts from `summary(pca_obj)` (Individuals/Variables) and `FactoMineR::dimdesc()` filtered at a given significance threshold `proba`, and instructs how to read and name the axis.

Usage

trainer_PCA(
  pca_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

pca_obj

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

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: decathlon (FactoMineR)
if (requireNamespace("FactoMineR", quietly = TRUE)) {
data(decathlon, package = "FactoMineR")

res_pca <- FactoMineR::PCA(decathlon,
                quanti.sup = 11:12,
                quali.sup = 13,
                graph = FALSE)

intro <- "A study was conducted on decathlon athletes.
Performances on each event were measured and summarized by PCA."
intro <- gsub("\n", " ", intro); intro <- gsub("\\s+", " ", intro)

prompt <- trainer_PCA(res_pca,
                dimension = 1,
                proba = 0.05,
                introduction = intro,
                audience = "applied",
                generate = FALSE)

cat(prompt)

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

Run the code above in your browser using DataLab