CI- Location Normal Model
Data (save the data in file grdata.txt)
98
77
70
57
98
77
70
54
97
77
70
53
96
73
67
50
90
73
64
50
85
73
64
50
85
73
64
35
85
73
64
54
81
73
63
31
80 80 80 80 77 77
70 70 70 70 70 70
60 60 60 60 60 60
33
R Code for CIs
#R code for calculating the CI for the mean of a normal distribution when sigma is known
x=scan("C:/Users/Owner/Desktop/grdata.txt")
hist(x)
sigma0 = 15
gamma = 0.95
n = length(x) # compute n
xbar = mean(x)
se = sigma0 / sqrt (n)
CI = xbar + qnorm(c((1-gamma)/2 , (1+gamma)/2 )) * se
# notice how both confidence limits are computed simultaneously
# by inputting a vector of percentage points !
xbar
sigma0
n
gamma
CI
R output
x=scan("C:/Users/Admin/Desktop/grdata.txt")
Read 55 items
> hist(x)
> sigma0 = 15
> gamma = 0.95
> n = length(x) # compute n
> xbar = mean(x)
> se = sigma0 / sqrt (n)
> CI = xbar + qnorm(c((1-gamma)/2 , (1+gamma)/2 )) * se
> # notice how both confidence limits are computed simultaneously
> # by inputting a vector of percentage points !
> xbar
[1] 69.10909
> sigma0
[1] 15
>n
[1] 55
> gamma
[1] 0.95
> CI
[1] 65.14487 73.07331
> gamma
[1] 0.95
>
CI for proportions
Ex.
If 40 of a sample of 400 computer memory
chips made at Digital Devices, Inc., were found
to be defective. Give a 95% confidence interval
for the proportion defective in the population
from which the sample was taken?
p̂
!" #
gamma = 0.95
n=400
x=40
p=x/n
se=sqrt((p*(1-p))/n)
CI = p + qnorm(c((1-gamma)/2 , (1+gamma)/2 )) * se
CI
Output:
[1] 0.07060054 0.12939946
Or direct R function
> prop.test(x=40, n=400, p=.08, alternative="two.sided")
1-sample proportions test with continuity correction
data: 40 out of 400, null probability 0.08
X-squared = 1.9107, df = 1, p-value = 0.1669
alternative hypothesis: true p is not equal to 0.08
95 percent confidence interval:
0.0732215 0.1347077
sample estimates:
p
0.1
$ " % & " ' & ( '( # '
% σ )&*& + &
Ex:
In a metropolitan area, the concentration of
cadmium (Cd) in leaf lettuce was measured in 6
representative gardens where sewage sludge
was used as fertilizer. The following
measurements (in mg/kg of dry weight) were
obtained.
#
,-
-
> x=scan("C:/Users/Owner/Desktop/cdData.txt")
Read 6 items
> x
[1] 21 38 12 15 14 8
> t.test(x, conf.level=0.95)
One Sample t-test
data: x
t = 4.1295, df = 5, p-value = 0.00909
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
6.795094 29.204906
sample estimates:
mean of x
18
> t.test(x, conf.level=0.90)
One Sample t-test
data: x
t = 4.1295, df = 5, p-value = 0.00909
alternative hypothesis: true mean is not equal to 0
90 percent confidence interval:
9.216608 26.783392
sample estimates:
mean of x
18
A. One-sample t-tests
Ex. An outbreak of Salmonella-related
illness was attributed to ice cream produced
at a certain factory. Scientists measured the
level of Salmonella in 9 randomly sampled
batches of ice cream. The levels (in MPN/g)
were:
.
/%# &" . . ( & ' / '
0 '( & '' %& . %" " ( %
. & ,
1 2 3
Let be the mean level of Salmonella in all
batches of ice cream. Here the hypothesis
of interest can be expressed as:
H0: 0.3
4 5 ,
x=scan("C:/Users/Mihinda/Desktop/salmo.txt")
x
t.test(x, alternative="greater", mu=0.3)
# c("two.sided", "less", "greater")
> x=scan("C:/Users/Mihinda/Desktop/salmo.txt")
Read 9 items
> x
[1] 0.593 0.142 0.329 0.691 0.231 0.793 0.519
0.392 0.418
> t.test(x, alternative="greater", mu=0.3)
One Sample t-test
data: x
t = 2.2051, df = 8, p-value = 0.02927
alternative hypothesis: true mean is greater
than 0.3
95 percent confidence interval:
0.3245133
Inf
sample estimates:
mean of x
0.4564444
© Copyright 2026 Paperzz