bhylu.com

Advertisements

R Statistical Tests

Read an estimate and interval alongside a test statistic.

How it works

A statistical test evaluates data under a null model and its assumptions. A p-value is not the probability that the null hypothesis is true, and a non-significant result is not proof of no effect. This fictional one-sample t-test compares five observed session durations with a reference of ten minutes. It is arithmetic practice, not operational advice.

Run this R example

These examples run locally with R, not PHP, Python or JavaScript. The reviewed baseline is R 4.5.2 on Windows x64/UCRT, using only packages shipped with R. This is a tested version, not a newest-release claim. Install your own R from the official R project; an IDE is optional. Save the complete source as statistical-tests.R in a separate learning folder and run Rscript --vanilla statistical-tests.R. Keep code and fictional fixtures separate from a real project.

Bhylu has no R browser runner. There is no Try in playground link because the existing Python and JavaScript editors do not execute R. No package installation, account, network dataset, Apache, MySQL or PHP setting is needed to run these base-R sources.

The complete download uses a local scope, restores its temporary options and treats unexpected warnings as errors. Examples that handle an expected warning do so narrowly. Random examples change only their R process’s RNG state. File examples own their temporary output; figure examples leave their named PNG in the current learning folder and refuse to overwrite it. Use a new empty folder to rerun a figure.

Download the complete statistical-tests.R · Download all source files with hash checks

For the optional collection downloader, save download-examples.mjs in an empty folder and run node download-examples.mjs. Local preview before publishing uses node download-examples.mjs http://127.0.0.1:8000/examples/r/. It refuses an existing bhylu-r-examples folder and does not install or execute R.

Example

statistical-tests.R

local({
  previous_options <- options(warn = 2, digits = 8, stringsAsFactors = FALSE)
  on.exit(options(previous_options), add = TRUE)
  minutes <- c(9, 10, 11, 12, 13)
  result <- t.test(minutes, mu = 10)
  cat("estimated mean:", unname(result$estimate), "\n")
  cat("t statistic:", sprintf("%.3f", unname(result$statistic)), "\n")
  cat("degrees of freedom:", unname(result$parameter), "\n")
  cat("interval contains reference:", result$conf.int[1] <= 10 && result$conf.int[2] >= 10, "\n")
  invisible(NULL)
})

Focus on the lesson operations

This excerpt omits the complete script’s option/resource setup. Use the full download to execute it.

Operation excerpt

minutes <- c(9, 10, 11, 12, 13)
result <- t.test(minutes, mu = 10)
cat("estimated mean:", unname(result$estimate), "\n")
cat("t statistic:", sprintf("%.3f", unname(result$statistic)), "\n")
cat("degrees of freedom:", unname(result$parameter), "\n")
cat("interval contains reference:", result$conf.int[1] <= 10 && result$conf.int[2] >= 10, "\n")

Expected result

estimated mean: 11
t statistic: 1.414
degrees of freedom: 4
interval contains reference: TRUE

The interval includes ten for this constructed sample. Interpretation depends on the sampling process, independence and model assumptions, not just the printed test result. Repeatedly testing many outcomes and reporting only a favourable one undermines the intended error-rate interpretation.

For API behaviour, consult the official Introduction to R and your installed help pages. These small examples do not establish real-world statistical conclusions or production performance.

Advertisements