Returns the statistical call that produced a result, as R code a reader can
copy and run. This is what lets a report show t.test() or cor.test() with
the variables and options resolved, rather than only the
run_analysis_plan() call that dispatched it.
Arguments
- x
An
sframe_analysis_resultsobject fromrun_analysis_plan(), or one block's result from it.- which
Character or NULL. One block id, when
xholds more than 1 block.- data_expr
Character. The expression the code should read its data from. Defaults to
"scored", the scored frame the header sets up.- header
Logical. Whether to include the lines that load the instrument, read the responses and score the scales.
TRUEgives a script that runs on its own.
Value
A character vector of R code lines, or NULL for a method this does
not cover. For more than 1 block, a named list of such vectors.
Details
The code is built from the same resolved specification the runner executed: the variables in the order it resolved them, and the options after defaults were applied. Running it reproduces the statistic, degrees of freedom and p value the package reports, which the package's own tests check by running the generated code and comparing.
What it covers
The 2-group, paired, k-group, correlation, regression and categorical
families, and descriptives. sframe_syntax_methods lists them. A method
outside that list returns NULL: the model families carry their own syntax
already, through sframe_syntax_cfa() and its neighbours, and for the rest the
computation has no single base-R equivalent to show honestly.
See also
run_analysis_plan(), sframe_syntax_cfa(), render_report()
Other Models and syntax functions:
sframe_add_model(),
sframe_construct(),
sframe_covariance(),
sframe_indirect_effect(),
sframe_model_json(),
sframe_model_outline(),
sframe_model_spec(),
sframe_path(),
sframe_syntax_cfa(),
sframe_syntax_efa(),
sframe_syntax_pls(),
sframe_syntax_sem(),
sframe_validate_model()
Examples
instr <- sframe_instrument("Syntax demo", components = list(
sframe_item("score", "Score", type = "numeric"),
sframe_item("arm", "Arm", type = "text")
))
sframe_plan(instr) <- list(list(
id = "RQ1", research_question = "Do the arms differ?",
family = "inferential", method = "t_test_ind",
roles = list(group = "arm", outcome = "score")
))
set.seed(1)
responses <- data.frame(
arm = rep(c("control", "treatment"), each = 15),
score = c(rnorm(15, 10), rnorm(15, 12))
)
results <- run_analysis_plan(responses, instr)
# the call behind the number, with the variables and options resolved
cat(sframe_syntax_result(results, which = "RQ1"), sep = "\n")