Lab Kamal Sir
Lab Kamal Sir
A random sample of size 10 is available from a normal distribution with a variance of 2.52. A null
hypothesis H0: µ = 50 is to be tested. The hypothesis will be accepted if 48.5 < 𝑋 < 51.5. Obtain the
probabilities of type I and type II errors against the alternative hypothesis H1: µ = 52. Now, arbitrarily
using different accepted regions and sample sizes, show how the two errors and powers of the test
change.
Solution:
# Given data
n <- 10 # Sample size
variance <- 2.52 # Variance
sigma <- sqrt(variance) # Standard deviation
mu_null <- 50 # Null hypothesis mean
mu_alt <- 52 # Alternative hypothesis mean
lower_limit <- 48.5 # Lower bound of acceptance region
upper_limit <- 51.5 # Upper bound of acceptance region
# Type II Error (β): Probability of failing to reject H0 when H1 is true (H1: mu = 52)
z_lower_alt <- (lower_limit - mu_alt) / se
z_upper_alt <- (upper_limit - mu_alt) / se
beta <- pnorm(z_upper_alt) - pnorm(z_lower_alt)
# Define a function to calculate errors and power based on sample size and acceptance region
calculate_errors_and_power <- function(n, lower_limit, upper_limit, mu_null, mu_alt, sigma) {
se <- sigma / sqrt(n)
Problem 02: Using any suitable data, test the overall significance of the treatments. Also, perform
multiple comparison (Tukey, Duncan, Scheffe and Bonferroni) tests to test the pairwise significance of
the treatments using the same data.
Solution :
# Step 1: Simulate some example data (replace this with your real dataset if you have one)
set.seed(123) # For reproducibility
treatment <- factor(rep(c("A", "B", "C", "D"), each = 10)) # 4 treatments with 10 observations each
value <- c(rnorm(10, mean = 5, sd = 2), # Treatment A
rnorm(10, mean = 7, sd = 2), # Treatment B
rnorm(10, mean = 6, sd = 2), # Treatment C
rnorm(10, mean = 8, sd = 2)) # Treatment D
# If p-value < 0.05, we reject the null hypothesis and conclude that there is a significant difference
#among treatments
# Scheffe's Test
scheffe_result <- scheffe.test(anova_result, "treatment")
print(scheffe_result)
# Bonferroni's Test
# We use the glht function from the multcomp package for Bonferroni adjustment
bonferroni_result <- glht(anova_result, linfct = mcp(treatment = "Tukey"))
summary(bonferroni_result)
Problem 03: Perform permutation test or two samples bootstrapping method for any suitable data.
Solution:
# Number of permutations
n_permutations <- 10000
# P-value: The proportion of permutations where the absolute difference is greater than or equal to the
observed difference
p_value_perm <- mean(abs(permutation_diffs) >= abs(obs_diff))
Problem 04: From a suitable data set, estimate the density function 𝑓 by Kernel method using the
kernels such as Epanechnikov, triangle, quartic and Gaussian.
Solution:
Install.packages(“ggplot2”)
library(ggplot2)
# Step 1: Generate a synthetic dataset (e.g., 1000 observations from a normal distribution)
set.seed(123) # For reproducibility
data <- rnorm(1000, mean = 5, sd = 2)
# Add a legend
legend("topright", legend = c("Epanechnikov", "Triangle", "Quartic", "Gaussian"),
col = c("blue", "red", "green", "purple"), lwd = 2)