One Sample analysis

# ---------------------------------------------------------
# Students' scores (sample data)
# Each value represents one student's geography score
# ---------------------------------------------------------

scores <- c(70,80,75,65,50,80,85,77,76,78,66,64,68,69,64)

# ---------------------------------------------------------
# Descriptive statistics
# Calculate the average score (mean)
mean(scores)
## [1] 71.13333
# Measure how much scores vary around the mean (standard deviation)
sd(scores)
## [1] 8.854915
# ---------------------------------------------------------
# 95% Confidence Interval for the population mean
# Estimate the range where the true average score may lie
n <- length(scores)
mean(scores) + c(-1,1) * qt(0.975, n-1) * sd(scores)/sqrt(n)
## [1] 66.22964 76.03702
# ---------------------------------------------------------
# One-sample t-test
# H0: population mean = 65
# Test whether students’ average score is different from 65
t.test(scores, mu = 65)
## 
##  One Sample t-test
## 
## data:  scores
## t = 2.6826, df = 14, p-value = 0.01785
## alternative hypothesis: true mean is not equal to 65
## 95 percent confidence interval:
##  66.22964 76.03702
## sample estimates:
## mean of x 
##  71.13333
# ---------------------------------------------------------
# Simple visualization
# Boxplot shows distribution, median, and spread of scores
boxplot(scores)

# Add a reference line at score = 65
# This helps compare students’ performance with the target level
abline(h = 65, lty = 2)