🎯 Week 7 Key Concepts

🔧 Function Syntax

myFunction <- function(arg1, arg2) { return(result) }

Create reusable code blocks with parameters and return values

📊 Sample Size Function

n = z²p(1-p)/E²

Build functions for statistical calculations like sample size

📈 Two-Sample T-Test

t = (x̄₁-x̄₂)/√(s₁²/n₁ + s₂²/n₂)

Compare means between two independent groups

🎯 Hypothesis Testing

H₀: μ₁ = μ₂ vs H₁: μ₁ ≠ μ₂

Set up null and alternative hypotheses for comparisons

🔧 Interactive Function Builder

Build Your Own R Function

⚙️ Function Definition

👁️ Live Preview

🧪 Test Your Function
Enter test values and click Run to see the result

📚 Function Examples

Square Function
square <- function(x) {
  return(x * x)
}
Multiply Function
multiply <- function(a, b) {
  return(a * b)
}
Sample Size
sampleSize <- function(p, E, z) {
  return(z^2 * p * (1-p) / E^2)
}

📊 Sample Size Function Calculator

🌾 Agricultural Study Sample Size

⚙️ Parameters

Proportion of population with characteristic
Significance level (1 - confidence level)
Acceptable error in estimate

📊 Calculation Results

📈 Sample Size Visualization

🌾 Agricultural Example:

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.

📈 Agricultural Treatment Comparison

🚜 Two-Sample T-Test Simulator

🌱 Control Group

🌿 Treatment Group

📊 Two-Sample T-Test Results

Enter sample data to see the analysis!

📈 Visual Comparison

📊

Visualization will appear here

🎯 Hypothesis Formation Tool

🔬 Build Your Hypothesis Test

⚙️ Test Setup

📝 Hypothesis Statements

📊 Rejection Regions

💡 Interpretation Helper

p-value < α

Reject H₀. Evidence supports the alternative hypothesis.

p-value ≈ α

Borderline. Consider practical significance and collect more data.

p-value > α

Fail to reject H₀. Insufficient evidence for alternative.

🎯 Practice Quiz

Question 1 of 5

Progress: 0%

🎓 Key Takeaways

🔧

Function Benefits

  • • Reusable code blocks
  • • Fewer errors and bugs
  • • Organized analysis workflow
  • • Easy to test and debug
📊

T-Test Applications

  • • Treatment comparisons
  • • Group differences analysis
  • • Agricultural decisions
  • • Evidence-based farming
🌾

Agricultural Examples

  • • Fertilizer effectiveness trials
  • • Crop variety testing
  • • Irrigation method studies
  • • Pest management evaluation