STATISTICAL INFERENCE LAB -3
CB.PS.I5MAT22007
9. Given the following data use chi-square test at 5% level of significance whether the observed
frequencies are consistent with that of expected frequencies.
Observed frequency: 34 20 10
Expected frequency: 36 12 16
observed <- c(34, 10, 20)
expected <- c(36, 12, 16)
chisq_test <- chisq.test(observed, p = expected/sum(expected))
print(chisq_test)
p_value <- chisq_test$p.value
df <- length(observed) - 1
alpha <- 0.05
critical_value <- qchisq(1 - alpha, df)
chi_square_statistic <- sum((observed - expected)^2 / expected)
tabulated_chi_squared <- qchisq(alpha, df)
if (chi_square_statistic > critical_value) {
print("Reject the null hypothesis.")
} else {
print("Accept the null hypothesis.")
}
print(paste("Chi-square statistic:", chi_square_statistic))
print(paste("Critical value:", critical_value))
print(paste("Tabulated chi-square value:", tabulated_chi_squared))
print(paste("p-value:", p_value))
print(paste("Significance level:",alpha))
OUTPUT:
> observed <- c(34, 10, 20)
> expected <- c(36, 12, 16)
> chisq_test <- chisq.test(observed, p = expected/sum(expected))
> print(chisq_test)
Chi-squared test for given probabilities
data: observed
X-squared = 1.4444, df = 2, p-value = 0.4857
> p_value <- chisq_test$p.value
> df <- length(observed) - 1
> alpha <- 0.05
> critical_value <- qchisq(1 - alpha, df)
> chi_square_statistic <- sum((observed - expected)^2 / expected)
> tabulated_chi_squared <- qchisq(alpha, df)
> if (chi_square_statistic > critical_value) {
+ print("Reject the null hypothesis.")
+ } else {
+ print("Accept the null hypothesis.")
+ }
[1] "Accept the null hypothesis."
> print(paste("Chi-square statistic:", chi_square_statistic))
[1] "Chi-square statistic: 1.44444444444444"
> print(paste("Critical value:", critical_value))
[1] "Critical value: 5.99146454710798"
> print(paste("Tabulated chi-square value:", tabulated_chi_squared))
[1] "Tabulated chi-square value: 0.102586588775101"
> print(paste("p-value:", p_value))
[1] "p-value: 0.485671785247712"
> print(paste("Significance level:",alpha))
[1] "Significance level: 0.05"
10. The number of defects in printed circuit boards is hypothesized to follow a poisson
distribution.A random sample of n=60 printed boards has been collected, and the following
number of defects observed,Test at 5% level of significance whether the distribution of
defects in printed circuit boards in poisson.
Number of defects 0 1 2 3
Observed frequency 32 15 9 4
observed <- c(32, 15, 9, 4)
lambda <- sum(observed * 0:3) / sum(observed)
expected <- dpois(0:3, lambda) * sum(observed)
chisq_test <- chisq.test(observed, p = expected / sum(expected))
print(chisq_test)
p_value <- chisq_test$p.value
df <- length(observed) - 1
alpha <- 0.05
critical_value <- qchisq(1 - alpha, df)
chi_square_statistic <- sum((observed - expected)^2 / expected)
tabulated_chi_squared <- qchisq(alpha, df)
print(paste("Tabulated chi-square value:", tabulated_chi_squared))
if (chi_square_statistic > critical_value) {
print("Reject the null hypothesis.")
} else {
print("Accept the null hypothesis.")
}
OUTPUT:
> observed <- c(32, 15, 9, 4)
> lambda <- sum(observed * 0:3) / sum(observed)
> expected <- dpois(0:3, lambda) * sum(observed)
> chisq_test <- chisq.test(observed, p = expected / sum(expected))
Warning message:
In chisq.test(observed, p = expected/sum(expected)) :
Chi-squared approximation may be incorrect
> print(chisq_test)
Chi-squared test for given probabilities
data: observed
X-squared = 4.4323, df = 3, p-value = 0.2184
> p_value <- chisq_test$p.value
> df <- length(observed) - 1
> alpha <- 0.05
> critical_value <- qchisq(1 - alpha, df)
> chi_square_statistic <- sum((observed - expected)^2 / expected)
> tabulated_chi_squared <- qchisq(alpha, df)
> print(paste("Tabulated chi-square value:", tabulated_chi_squared))
[1] "Tabulated chi-square value: 0.351846317749271"
> if (chi_square_statistic > critical_value) {
+ print("Reject the null hypothesis.")
+ } else {
+ print("Accept the null hypothesis.")
+ }
[1] "Accept the null hypothesis."
11.Four coins were tossed 160 times and the following results were obtained.
No.of heads 0 1 2 3 4
Observed frequency 17 52 54 31 6
Under the assumption that the coins are balanced find
(i)the expected frequencies of getting 0,1,2,3 or 4 heads and
(ii)test the goodness of fit.
observed <- c(17, 52, 54, 31, 6)
total_tosses <- sum(observed)
prob_heads <- dbinom(0:4, size = 4, prob = 0.5)
expected <- prob_heads * total_tosses
chisq_test <- chisq.test(observed, p = expected / sum(expected))
print(chisq_test)
p_value <- chisq_test$p.value
df <- length(observed) - 1
alpha <- 0.05
critical_value <- qchisq(1 - alpha, df)
chi_square_statistic <- sum((observed - expected)^2 / expected)
tabulated_chi_squared <- qchisq(alpha, df)
print(paste("Tabulated chi-square value:", tabulated_chi_squared))
if (chi_square_statistic > critical_value) {
print("Reject the null hypothesis.")
} else {
print("Accept the null hypothesis.")
}
OUTPUT:
> observed <- c(17, 52, 54, 31, 6)
> total_tosses <- sum(observed)
> prob_heads <- dbinom(0:4, size = 4, prob = 0.5)
> expected <- prob_heads * total_tosses
> chisq_test <- chisq.test(observed, p = expected / sum(expected))
> print(chisq_test)
Chi-squared test for given probabilities
data: observed
X-squared = 12.725, df = 4, p-value = 0.0127
> p_value <- chisq_test$p.value
> df <- length(observed) - 1
> alpha <- 0.05
> critical_value <- qchisq(1 - alpha, df)
> chi_square_statistic <- sum((observed - expected)^2 / expected)
> tabulated_chi_squared <- qchisq(alpha, df)
> print(paste("Tabulated chi-square value:", tabulated_chi_squared))
[1] "Tabulated chi-square value: 0.710723021397324"
> if (chi_square_statistic > critical_value) {
+ print("Reject the null hypothesis.")
+ } else {
+ print("Accept the null hypothesis.")
+ }
[1] "Reject the null hypothesis."
12.Test at 5% level of significance with an alternative hypothesis that one of the two population
variances is greater than the other based on their sample variances equal to 16 and 25 and
respective degrees of freedom are 11 and 9.
var1 <- 16
var2 <- 25
df1 <- 11
df2 <- 9
F_statistic <- var1 / var2
alpha <- 0.05
critical_value <- qf(1 - alpha, df1, df2)
print(paste("F-Statistic:", F_statistic))
print(paste("Critical Value:", critical_value))
if (F_statistic > critical_value) {
print("Reject the null hypothesis.")
} else {
print("Accept the null hypothesis.")
}
OUTPUT:
> var1 <- 16
> var2 <- 25
> df1 <- 11
> df2 <- 9
> F_statistic <- var1 / var2
> alpha <- 0.05
> critical_value <- qf(1 - alpha, df1, df2)
> print(paste("F-Statistic:", F_statistic))
[1] "F-Statistic: 0.64"
> print(paste("Critical Value:", critical_value))
[1] "Critical Value: 3.10248540752838"
> if (F_statistic > critical_value) {
+ print("Reject the null hypothesis.")
+ } else {
+ print("Accept the null hypothesis.")
+ }
[1] "Accept the null hypothesis."
Thickness(in microns) <=175 175-177 177-179 179-181 181-183 183-185 >=185
No.of sample 5 12 17 25 20 15 6
observations <- c(5, 12, 17, 25, 20, 15, 6)
class_midpoints <- c(175, 176, 178, 180, 182, 184, 185)
skew <- sum(observations * (class_midpoints - mean(class_midpoints))^3) /
(length(observations) *sd(class_midpoints)^3)
kurt <- sum(observations * (class_midpoints - mean(class_midpoints))^4) /
(length(observations)*sd(class_midpoints)^4) - 3
if (abs(skew) <= 1 && abs(kurt) <= 1) {
print("The data is normally distributed.")
} else {
print("The data is not normally distributed.")
}
OUTPUT:
> observations <- c(5, 12, 17, 25, 20, 15, 6)
> class_midpoints <- c(175, 176, 178, 180, 182, 184, 185)
> skew <- sum(observations * (class_midpoints - mean(class_midpoints))^3) / (length(obs
> kurt <- sum(observations * (class_midpoints - mean(class_midpoints))^4) / (length(obs
> if (abs(skew) <= 1 && abs(kurt) <= 1) {
+ print("The data is normally distributed.")
+ } else {
+ print("The data is not normally distributed.")
+ }
[1] "The data is not normally distributed."
>