You are on page 1of 17

WINTER SEMESTER 2022-2023

NAME: Chethan N V

REG.NO: 21BCE0427

Course Title: Probability and Statistics

Course Code: BMAT202P

Slot: L5+L6

EXPERIMENT NO : LAB ASSIGNMENT – 5

FACULTY NAME: Padigepati Naveen


Problem – 1

Aim: To find t-test.


Code:
> #Name: Chethan N V
> #Reg No: 21BCE0427
>
> #Question 1
>
> sample_A=c(24,27,26,21,25)
> sample_B=c(27,30,28,31,22,36)
>
> # Perform two-sample t-test assuming equal variances
> t.test(sample_A, sample_B, var.equal = TRUE)

Two Sample t-test

data: sample_A and sample_B


t = -1.9178, df = 9, p-value = 0.08736
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-9.5900135 0.7900135
sample estimates:
mean of x mean of y
24.6 29.0
>
>
> #H0: The nicotine content in Sample A is equal to the nicotine content
in Sample B.
> #H1: The nicotine content in Sample A is not equal to the nicotine
content in Sample B.
>
> #The p-value is 0.08736 which is greater than the significance level of
0.05, indicating that we fail to reject that null hypothesis,
>
> #Therefore, we can conclude that there is not enough evidence to suggest
that the nicotine content in Sample A is different from the nicotine
content in Sample B.
>
>
>
>
>
>
> #b)
> nails <- c(7.2, 7.3, 7.1, 6.9, 6.8, 6.5, 6.9, 6.8, 7.1, 7.2)
> t.test(nails,mu=7)

One Sample t-test

data: nails
t = -0.25916, df = 9, p-value = 0.8013
alternative hypothesis: true mean is not equal to 7
95 percent confidence interval:
6.805424 7.154576
sample estimates:
mean of x
6.98
> #H0: The mean length of nails produced by the machine is 7 cms.
> #H1: The mean length of nails produced by the machine is not equal to 7
cms.
>
> #The p-value is 0.8013 , which is greater than the significance level of
0.05, indicating that we fail to reject the null hypothesis.
> #Therefore, we can conclude that there is not enough evidence to suggest
that the mean length of nails produced by the machine is different from 7
cms, and we cannot say anything about the reliability of the machine based
on this sample.
>
Screenshot:
Problem 2:

Aim: t-test
Code:
> #Name: Chethan N V
> #Reg No: 21BCE0427
>
> #Question 2
>
> before = c(45, 73, 46, 124, 33, 57, 83, 34, 26, 17)
> after = c(36, 60, 44, 119, 35, 51, 77, 29, 24, 11)
>
> #Null hypothesis (H0): The safety program is not effective
in reducing accidents.
> #Alternative hypothesis (Ha): The safety program is
effective in reducing accidents.
>
> # perform paired t-test
> t.test(before, after, paired = TRUE, alternative = "less",
conf.level = 0.95)

Paired t-test

data: before and after


t = 4.0333, df = 9, p-value = 0.9985
alternative hypothesis: true mean difference is less than 0
95 percent confidence interval:
-Inf 7.563381
sample estimates:
mean difference
5.2

> The p-value is 0.9985, which is greater than the


significance level of 0.05, indicating that we can accept null
hypothesis
Error: unexpected symbol in "The p"
>
> #Therefore we can conclude that The safety program is not
effective in reducing accidents.
>
Screenshots:
Problem 3:

Aim: To find Chi-test

Code:
> #Name: Chethan N V
> #Reg no: 21BCE0427
>
> #Question 3
>
>
> obs_freq=c(17, 52, 54, 31, 6)
> n=sum(obs_freq)
> exp_freq=dbinom(0:4, 4, 0.5)*n
> exp_freq
[1] 10 40 60 40 10
>
> exp_freq1 =dbinom(0:4, 4, 0.5)*sum(obs_freq)
> # perform chi-squared test
> chisq.test(obs_freq,p=dbinom(0:4, 4, 0.5), rescale.p = TRUE)

Chi-squared test for given probabilities

data: obs_freq
X-squared = 12.725, df = 4, p-value = 0.0127

> #the p-value is 0.0127 which is less than 0.05


>
>
> #Null hypothesis (H0): The observed frequencies follow a
binomial distribution with aprobability of 0.5 for each trial.
> #Alternative hypothesis (Ha): The observed frequencies do
not follow a binomial distribution with a probability of 0.5
for each trial.
>
> #as p-value<0.05 reject H0 and conclude that The observed
frequencies do not follow a binomial distribution with a
probability of 0.5 for each trial.
>
>
Screenshots:
Problem 4:

Aim: To perform F-test

Code:
> #Name: Chethan N V
> #Reg No; 21BCE0427
> #Question 4
>
> #sample 1
> x = c(16, 26, 27, 23, 24, 22)
>
> #sample 2
> y = c(33, 42, 35, 32, 28, 31)
>
> #perform F-test
>
> var.test(x,y)

F test to compare two variances

data: x and y
F = 0.6696, num df = 5, denom df = 5, p-value = 0.6706
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
0.09369826 4.78524246
sample estimates:
ratio of variances
0.6696035

> #Null hypothesis (H0): The variances of the two populations are
equal.
> #Alternative hypothesis (Ha): The variances of the two
populations are not equal.
>
>
> #TThe p-value is -.6706 which is greater than 0.05, this
indicates that we cannot reject null hypothesis that the variances
of the two populations are equal.
>
> #Therefore we can conclude that the estimates of variances do
not differ significantly.
>
>
Screenshot:
Problem 5:

Aim: To perform ANOVA table test

Code:
> #Name: Chethan N V
> #Regno: 21BCE0427
>
> #Question 5
>
> Salesman = c(rep("A", 3), rep("B", 3), rep("C", 3), rep("D", 3))
> Season = c(rep(c("Summer", "Winter", "Monsoon"), 4))
> Sales = c(36, 28, 26, 36, 29, 28, 21, 31, 29, 35, 32, 29)
> Total = c(128, 120, 112, 90, 93, 81, 96, 360)
> )
Error: unexpected ')' in ")"
>
> sales_data <- data.frame(Salesman,Season,Sales,Total)
Error in data.frame(Salesman, Season, Sales, Total) :
arguments imply differing number of rows: 12, 8
> Total = c(128, 120, 112, 90, 93, 81, 96, 360,0,0,0,0)
> sales_data <- data.frame(Salesman,Season,Sales,Total)
>
> # perform two-way ANOVA
> result <- aov(Sales ~ Salesman + Season, data = sales_data)
> summary(result)
Df Sum Sq Mean Sq F value Pr(>F)
Salesman 3 42 14.00 0.618 0.629
Season 2 32 16.00 0.706 0.531
Residuals 6 136 22.67
>
>
> #The null hypothesis for the two-way ANOVA test is that there is no
significant difference among the means of the sales of the four
salesmen in three seasons.
> #The alternative hypothesis is that there is a significant
difference among the means of the sales of the four salesmen in three
seasons.
>
>
> #The p-value for the Salesman factor is 0.629, which is greater than
the significance level of 0.05, indicating that there is no
significant difference among the means of the four salesmen.
> #The p-value for the Season factor is 0.0531, which is greater than
the significance level of 0.05, indicating that there is not enough
evidence to reject the null hypothesis that there is no significant
difference among the means of the three seasons.
>
>
> #Therefore, we can conclude that there is a significant difference
among the means of the four salesmen with regard to the sales, but no
significant difference among the means of the three seasons.
Screenshot:

You might also like