Run a pre-planned analysis from an instrument's analysis plan
Source:R/analysis_plan.R
run_analysis_plan.RdExecutes every analysis block defined in the instrument's analysis_plan
slot against the supplied response data. Each block corresponds to one
research question defined during instrument design in the SurveyBuilder.
Results include APA-formatted statistics, effect sizes, interpretation
prompts, and reporting references.
Usage
run_analysis_plan(
data,
instrument,
scored = TRUE,
plots = FALSE,
plot_palette = c("web", "print"),
seed = 20260828L,
strict = FALSE
)Arguments
- data
A
tibbleordata.frameof responses, typically produced byread_responses()orread_sheet_responses().- instrument
An
sframeobject containing ananalysis_plan.- scored
Logical. Whether to automatically score scales before running the analysis. Defaults to
TRUE.- plots
Logical. When
TRUEand ggplot2 is installed, supported blocks gain a$plotelement holding a brand-styled ggplot object: bar charts for frequency and chi-square blocks, scatter plots with a regression overlay for correlation and linear-regression blocks. Defaults toFALSE.- plot_palette
One of
"web"(brand colours, for on-screen use) or"print"(black, grey, and white, for journal-ready print figures). Applied to every plot attached whenplots = TRUE. Seesframe_brand().- seed
Integer or
NULL. The random seed the analysis runs under. Defaults to a fixed value so the same instrument and the same data give the same answer every time, which is what makes a rendered report usable as an audit artefact. Every bootstrap confidence interval in the plan, and the parallel analysis behind the EFA family, depend on it. PassNULLfor the unseeded behaviour of releases before 0.4.1. The caller's own random stream is restored afterwards, so seeding here does not affect anything that runs later.- strict
Logical. When
TRUE, an error is raised if any block fails or scale scoring fails, listing each failure. WhenFALSE, the default, failures are kept in the results and counted in theirstatus.
Value
An object of class sframe_analysis_results, a list with one
element per analysis block, named by block id. Its status attribute
holds blocks, succeeded, failed, failed_blocks and scoring, the
outcome of scoring scales before analysis. A normal return can hold
failed blocks, so check attr(results, "status")$failed or use
strict = TRUE. Each block element Each element contains the test result,
APA string, interpretation prompt, and reporting-reference metadata.
Inferential blocks also carry a $table data frame suitable for
knitr::kable(). Pass to render_results() to generate a formatted
report.
Examples
instr <- read_sframe(
system.file("extdata", "tourism_services_demo.sframe",
package = "surveyframe")
)
responses <- read_responses(
system.file("extdata", "tourism_services_responses.csv",
package = "surveyframe"),
instr,
respondent_id = "respondent_id",
submitted_at = "submitted_at",
meta_cols = "started_at"
)
# \donttest{
results <- run_analysis_plan(responses, instr)
print(results)
#> Analysis Results: 34 research question(s)
#>
#> RQ 1: Is perceived digital marketing effectiveness associated with tourist satisfaction?
#> Test: correlation_pearson
#> APA: r(118) = 0.54, 95% CI [0.40, 0.65], p < .001
#>
#> RQ 2: Do digital marketing, service quality, and sustainability perceptions predict satisfaction?
#> Test: regression_linear
#> APA: R² = 0.383, F(3, 116) = 23.95, p < .001
#>
#> RQ 3: Do first-time and repeat visitors differ in behavioural intention?
#> Test: mann_whitney
#> APA: U = 1576, z = -0.98, p = .326, r = 0.09, 95% CI [0.00, 0.27], Hodges-Lehmann shift = -0.00, 95% CI [-0.50, 0.00]
#>
#> RQ 4: What is the distribution of first-time and repeat visitors?
#> Test: frequency
#> APA: Frequency distribution for visit_type (N = 120).
#>
#> RQ 5: What are the central tendency and spread of all response items?
#> Test: descriptives
#> APA: Descriptive statistics were computed for 12 variable(s).
#>
#> RQ 6: What is the pattern of missing responses across items?
#> Test: missing_data
#> APA: Missing-data diagnostics were computed for 12 variable(s).
#>
#> RQ 7: Do respondents meet attention check and data quality thresholds?
#> Test: quality
#> APA:
#>
#> RQ 8: What are the mean, SD, and range of each composite scale?
#> Test: descriptives
#> APA: Descriptive statistics were computed for 5 variable(s).
#>
#> RQ 9: What is the Cronbach alpha internal consistency of each scale?
#> Test: reliability_alpha
#> APA:
#>
#> RQ 10: What is the McDonald omega reliability of each scale?
#> Test: reliability_omega
#> APA:
#>
#> RQ 11: Which items show low item-total correlations or reduce alpha on removal?
#> Test: item_diagnostics
#> APA:
#>
#> RQ 12: Does the inter-item correlation matrix support exploratory factor analysis?
#> Test: efa_readiness
#> APA:
#>
#> RQ 13: How many factors emerge from digital marketing and service quality items?
#> Test: efa_solution
#> APA:
#>
#> RQ 14: What is the lavaan CFA syntax for the five-factor measurement model?
#> Test: cfa_lavaan_syntax
#> APA: CFA lavaan syntax generated.
#>
#> RQ 15: What is the CB-SEM lavaan syntax for digital marketing predicting satisfaction and behavioural intention via service quality?
#> Test: sem_lavaan_syntax
#> APA: CB-SEM lavaan syntax generated.
#>
#> RQ 16: What is the PLS-SEM seminr syntax for the full structural model?
#> Test: seminr_syntax
#> APA: PLS-SEM seminr syntax generated.
#>
#> RQ 17: Is visitor type associated with attention check response level?
#> Test: crosstab
#> APA: χ²(1, N = 120) = 4.31, p = .038, φ = 0.19, 95% CI [0.03, 0.33]
#>
#> RQ 18: Is the distribution of satisfaction ratings different across visitor types?
#> Test: crosstab
#> APA: χ²(4, N = 120) = 3.40, p = .494, V = 0.17, 95% CI [0.09, 0.38]
#>
#> RQ 19: Is there an association between visitor type and behavioural intention rating?
#> Test: fisher_exact
#> APA: Fisher's exact test, p = .454, Cramer's V = 0.17
#>
#> RQ 20: Do first-time and repeat visitors differ in mean satisfaction score?
#> Test: t_test_ind
#> APA: t(106.77) = 0.15, p = .878, d = 0.03, 95% CI [0.01, 0.43]
#>
#> RQ 21: Do respondents rate the two satisfaction items differently?
#> Test: t_test_pair
#> APA: t(119) = 0.82, p = .416, d_z = 0.07, 95% CI [-0.11, 0.26]
#>
#> RQ 22: Is there a significant distributional difference between the first two service quality items?
#> Test: wilcoxon_pair
#> APA: V = 967, z = -1.18, p = .239, r = 0.14, 95% CI [0.01, 0.38], pseudomedian = -0.00, 95% CI [-0.00, 0.00]
#>
#> RQ 23: Does satisfaction differ across visitor types?
#> Test: kruskal_wallis
#> APA: H(1) = 0.00, p = .949, η² = 0.000, 95% CI [0.00, 0.03]
#>
#> RQ 24: Does mean behavioural intention differ between visitor types?
#> Test: anova_one
#> APA: F(1, 118) = 0.74, p = .391, η² = 0.006, 95% CI [0.00, 0.07]
#>
#> RQ 25: Do visitor types differ in satisfaction after controlling for service quality?
#> Test: ancova
#> APA: Adjusted for service_quality, the group effect was F(1, 117) = 0.07, p = .791.
#>
#> RQ 26: Do mean ratings differ across the three digital marketing items within respondents?
#> Test: repeated_anova
#> APA: F(2, 238) = 0.40, p = .670, partial η² = 0.003
#>
#> RQ 27: Do ordinal ratings differ across the three service quality items within respondents?
#> Test: friedman
#> APA: Friedman chi-square(2, N = 120) = 1.09, p = .580
#>
#> RQ 28: Are service quality perceptions associated with sustainability perceptions?
#> Test: correlation_spearman
#> APA: r_s(118) = 0.00, 95% CI [-0.19, 0.19], p = .984
#>
#> RQ 29: Is sustainability perception associated with behavioural intention?
#> Test: correlation_kendall
#> APA: tau(118) = 0.05, 95% CI [-0.11, 0.20], p = .519
#>
#> RQ 30: Is digital marketing associated with behavioural intention after controlling for satisfaction?
#> Test: partial_correlation
#> APA: partial r(117) = -0.09, p = .304
#>
#> RQ 31: Do digital marketing and service quality perceptions predict visitor type?
#> Test: regression_logistic_binary
#> APA: χ²(2) = 0.28, p = .869, McFadden R² = 0.002
#>
#> RQ 32: Do digital marketing and sustainability perceptions predict ordered satisfaction?
#> Test: regression_logistic_ordinal
#> APA: Ordinal logistic regression was estimated with 120 complete cases.
#>
#> RQ 33: Does visitor type moderate the relationship between digital marketing and satisfaction?
#> Test: moderation
#> APA: Moderation was tested with a linear interaction model.
#>
#> RQ 34: Does satisfaction mediate the path from digital marketing to behavioural intention?
#> Test: mediation
#> APA: Indirect effect = 0.365, 95% bootstrap CI [0.218, 0.538], from 1000 of 1000 resamples.
#>
# }