myFunction <- function(arg1, arg2) { return(result) }
Create reusable code blocks with parameters and return values
n = z²p(1-p)/E²
Build functions for statistical calculations like sample size
t = (x̄₁-x̄₂)/√(s₁²/n₁ + s₂²/n₂)
Compare means between two independent groups
H₀: μ₁ = μ₂ vs H₁: μ₁ ≠ μ₂
Set up null and alternative hypotheses for comparisons
square <- function(x) {
return(x * x)
}
multiply <- function(a, b) {
return(a * b)
}
sampleSize <- function(p, E, z) {
return(z^2 * p * (1-p) / E^2)
}
You're studying the prevalence of a crop disease. With p=0.50 (worst case), α=0.05 (95% confidence), and E=0.05 (±5% error), you need to sample enough fields to accurately estimate disease prevalence.
Visualization will appear here
Reject H₀. Evidence supports the alternative hypothesis.
Borderline. Consider practical significance and collect more data.
Fail to reject H₀. Insufficient evidence for alternative.