0% found this document useful (0 votes)
22 views5 pages

Experiment 7 Prob R

The document outlines an experiment focused on hypothesis testing for one sample mean and proportion using R functions. It includes procedures for conducting tests, examples with calculations for penguin weights and cookie fat content, and a case study on typhoid patient fatality rates. The document emphasizes the importance of understanding critical values, test statistics, and the conclusions drawn from p-values in hypothesis testing.

Uploaded by

sabhariraj2007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views5 pages

Experiment 7 Prob R

The document outlines an experiment focused on hypothesis testing for one sample mean and proportion using R functions. It includes procedures for conducting tests, examples with calculations for penguin weights and cookie fat content, and a case study on typhoid patient fatality rates. The document emphasizes the importance of understanding critical values, test statistics, and the conclusions drawn from p-values in hypothesis testing.

Uploaded by

sabhariraj2007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Experiment-7

Testing of hypothesis for one sample mean and proportion


from real time problems
Aim: To understand the testing of hypothesis for large sample tests using R functions

Testing of Hypothesis - Large Sample mean Test


Introduction

Hypothesis tests are used to make decisions or judgments about the value of a parameter, such as the
population mean. There are two approaches for conducting a hypothesis test; the critical value
approach and the P-value approach. Since a sample statistic is being used to make decisions or
judgments about the value of a parameter it is possible that the decision reached is an error; there are
two types of errors made when conducting a hypothesis test; Type I Error and Type II Error.

Test of significance of the difference between sample mean and population mean
X  
z
 
n

Procedure:
 Import the data set
 Determine the critical value and sample statistic using R functions
 Conclude the problem using R functions
Problem

Suppose the mean weight of King Penguins found in an Antarctic colony last year was 15.4 kg.
In a sample of 35 penguins same time this year in the same colony, the mean penguin weight is
14.6 kg. Assume the population standard deviation is 2.5 kg. At 0 .05 significance level, can we
reject the null hypothesis that the mean penguin weight does not differ from last year?
Codes and Results:
# Input the sample mean
xbar=14.6
xbar

## [1] 14.6

# Input the population mean


mu0=15.4
mu0
## [1] 15.4

# Input the standard deviation


sigma=2.5
sigma

## [1] 2.5

# Input the sample size


n=35
n

## [1] 35

# Test Statistic
z=(xbar-mu0)/(sigma/sqrt(n))
z

## [1] -1.893146

# Level of significance
alpha=0.05
alpha

## [1] 0.05

# Two-tailed critical value


zhalfalpha=qnorm(1-(alpha/2))
zhalfalpha

## [1] 1.959964

c(-zhalfalpha,zhalfalpha)

## [1] -1.959964 1.959964

# To find p-value
pval=2*pnorm(z)
pval

## [1] 0.05833852

# conclusion
if(pval>alpha){print("Accept Null hypothesis")} else{print("Reject Null
hypothesis")}

## [1] "Accept Null hypothesis"

Problem:
Suppose the food label on a cookie bag states that there is at most 2 grams of saturated fat
in a single cookie. In a sample of 35 cookies, it is found that the mean amount of saturated
fat per cookie is 2.1 grams. Assume that the population standard deviation is 0.25 grams.
At 0.05 significance level, can we reject the claim on food label?
xbar=2.1
mu0=2
sigma=0.25
n=35
z=(xbar-mu0)/(sigma/sqrt(n))
z
##[1] 2.366432
alpha=0.05
## one tailed test
zalpha=qnorm(1-alpha)
zalpha
##[1] 1.644854
pval=pnorm(z)
pval
## Reject null hypothesis”

Testing of Hypothesis - Large Sample proportion Test

Test of significance of the difference between sample proportion and population proportion
pP
z 
 PQ
 n
Procedure:
 Import the data set
 Determine the critical value and sample statistic using R functions
 Conclude the problem using R functions
Problem:
The fatality rate of typhoid patients is believed to be 17.26%. In a certain year 640 patients suffering
from typhoid were treated in a metropolitan hospital and only 63 patients died. Can you consider the
hospital efficient?

Code and Results:


# Input the data
# Size of the sample
n=640
n

## [1] 640

# Sample proportion
Sprop=63/n
Sprop

## [1] 0.0984375
# Population proportion
Pprop=0.1726
Pprop

## [1] 0.1726

# probability of failure
q=1-Pprop
q

## [1] 0.8274

# test statistic
z=(Sprop-Pprop)/sqrt(Pprop*q/n)
z

## [1] -4.964736

#critical value
E=qnorm(.975)
# critical region
c(-E,E)

## [1] -1.959964 1.959964

# confidence interval
Sprop+c(-E,E)*sqrt(Pprop*(1-Pprop)/n)##

[1] 0.06915985 0.12771515

# Conclusion
if(z>-E && z<E){print("Hospital is not efficient")} else{print("Hospital is
efficient")}

## [1] "Hospital is efficient"

Suppose 60% of citizens voted in last election. 85 out of 148 people in a telephone survey
said that they voted in current election. At 0.05 significance level, can we reject the null
hypothesis that the proportion of voters in the population is above 60% this year?
p=85/148
p0=60/100
n=148
q0=1-p0
z=(p-p0)/sqrt(p0*q0/n)
z
##[1] -0.6375983
alpha=0.05
zalpha=qnorm(1-alpha)
-zalpha
##[1] -1.644854

Conclusion: Testing of hypothesis for large sample tests using R functions has been explored and concluded
Note:
Ask the students to print the null and alternate hypothesis and to use proper loops to print the result.

You might also like