R Markdown

# Create a data frame for student scores
student_scores <- data.frame(
  StudentA = c(52, 46, 62, 48, 57, 54),
  StudentB = c(66, 49, 64, 53, 68, NA),  # Note: Replace the missing value with the actual score
  StudentC = c(63, 65, 58, 70, 71, 73)
)

# Display the data frame
print(student_scores)
##   StudentA StudentB StudentC
## 1       52       66       63
## 2       46       49       65
## 3       62       64       58
## 4       48       53       70
## 5       57       68       71
## 6       54       NA       73
# Check for missing values and replace them if needed
any_missing <- any(is.na(student_scores))
if (any_missing) {
  print("Missing values detected. Please replace them with actual scores.")
  # Replace missing values with actual scores
  # For example, you can replace the missing value in StudentB with 60
  student_scores$StudentB[is.na(student_scores$StudentB)] <- 60
}
## [1] "Missing values detected. Please replace them with actual scores."
# Display the updated data frame
print(student_scores)
##   StudentA StudentB StudentC
## 1       52       66       63
## 2       46       49       65
## 3       62       64       58
## 4       48       53       70
## 5       57       68       71
## 6       54       60       73
# Perform Kruskal-Wallis test
res<-kruskal.test(student_scores$StudentA, student_scores$StudentB, student_scores$StudentC)
print(res)
## 
##  Kruskal-Wallis rank sum test
## 
## data:  student_scores$StudentA and student_scores$StudentB
## Kruskal-Wallis chi-squared = 5, df = 5, p-value = 0.4159

#                 Q2
# Given data
values <- matrix(c(120, 110, 90, 95, 40, 45), nrow = 2)
colnames(values) <- c("Republican", "Democratic", "Independent")
rownames(values) <- c("Male", "Female")

# Perform Chi-Square Test of Independence
chi_square_result <- chisq.test(values)
chi_square_result
## 
##  Pearson's Chi-squared test
## 
## data:  values
## X-squared = 0.86404, df = 2, p-value = 0.6492

#Q1

data<-c(5260,5470,5640,6180,6390,6515,6805,7515,7575,8230,8070)
data
##  [1] 5260 5470 5640 6180 6390 6515 6805 7515 7575 8230 8070
n<-length(data)
n
## [1] 11
#mean
mean<-mean(data)
mean
## [1] 6695.455
variance<-var(data)
variance
## [1] 1076927
standard_dev<-sd(data)
standard_dev
## [1] 1037.751
library(ggpubr)
## Warning: package 'ggpubr' was built under R version 4.3.2
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 4.3.2
boxplot(data)

#t test
res<-t.test(data,mu=7525,alternative="two.sided")
res
## 
##  One Sample t-test
## 
## data:  data
## t = -2.6512, df = 10, p-value = 0.02426
## alternative hypothesis: true mean is not equal to 7525
## 95 percent confidence interval:
##  5998.284 7392.625
## sample estimates:
## mean of x 
##  6695.455