Download Data science for Doctors: Inferential Statistics - R

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Data science for Doctors:
Inferential
Statistics
Solutions (part-2)
Below are the solutions to these exercises on inferential
statistics.
####################
#
#
#
Exercise 1
#
#
#
####################
binom.test(5 ,30, mean(data$class),alternative = "two.sided")
##
##
Exact binomial test
##
## data: 5 and 30
## number of successes = 5, number of trials = 30, p-value =
0.03587
## alternative hypothesis: true probability of success is not
equal to 0.3489583
## 95 percent confidence interval:
## 0.0564217 0.3472117
## sample estimates:
## probability of success
##
0.1666667
####################
#
#
#
Exercise 2
#
#
#
####################
binom.test(c(5,
"two.sided")
25),
mean(data$class)
,alternative
=
##
##
Exact binomial test
##
## data: c(5, 25)
## number of successes = 5, number of trials = 30, p-value =
## 0.0003249
## alternative hypothesis: true probability of success is not
equal to 0.5
## 95 percent confidence interval:
## 0.0564217 0.3472117
## sample estimates:
## probability of success
##
0.1666667
####################
#
#
#
Exercise 3
#
#
#
####################
binom.test(5, 30, mean(data$class), alternative="less")
##
##
Exact binomial test
##
## data: 5 and 30
## number of successes = 5, number of trials = 30, p-value =
0.0239
## alternative hypothesis: true probability of success is less
than 0.3489583
## 95 percent confidence interval:
## 0.0000000 0.3189712
## sample estimates:
## probability of success
##
0.1666667
#OR
pbinom(5, 30, mean(data$class))
## [1] 0.0238959
# We reject our null hypothesis
####################
#
#
#
Exercise 4
#
#
#
####################
binom.test(5,30,
conf.level=0.99,alternative="less")
mean(data$class),
##
##
Exact binomial test
##
## data: 5 and 30
## number of successes = 5, number of trials = 30, p-value =
0.0239
## alternative hypothesis: true probability of success is less
than 0.3489583
## 99 percent confidence interval:
## 0.0000000 0.3808047
## sample estimates:
## probability of success
##
0.1666667
# we can't reject our null hypothesis
####################
#
#
#
Exercise 5
#
#
#
####################
binom.test(2,
30,
mean(data$class),
conf.level=0.999,alternative="less")
##
##
Exact binomial test
##
## data: 2 and 30
## number of successes = 2, number of trials = 30, p-value =
## 0.0003637
## alternative hypothesis: true probability of success is less
than 0.3489583
## 99.9 percent confidence interval:
## 0.0000000 0.3214435
## sample estimates:
## probability of success
##
0.06666667
# We reject our null hypothesis
####################
#
#
#
Exercise 6
#
#
#
####################
z <- 1.96
low <- mean(data$mass) - z*sd(data$mass)/sqrt(30)
high <- mean(data$mass) + z*sd(data$mass)/sqrt(30)
low;high
## [1] 29.17127
## [1] 34.81389
####################
#
#
#
Exercise 7
#
#
#
####################
z <- (29 - mean(data$mass))/(sd(data$mass)/sqrt(30))
####################
#
#
#
Exercise 8
#
#
#
####################
2*pnorm(-abs(z),,1) #Reject the null hypothesis
## [1] 0.03761903
####################
#
#
#
Exercise 9
#
#
#
####################
library(TeachingDemos)
z.test(29,mu=mean(data$mass),sd=sd(data$mass)/sqrt(30),
alternative = "two.sided", conf.level = 0.95)
##
##
One Sample z-test
##
## data: 29
## z = -2.079, n = 1.0000, Std. Dev. = 1.4394, Std. Dev. of
the
## sample mean = 1.4394, p-value = 0.03762
## alternative hypothesis: true mean is not equal to 31.99258
## 95 percent confidence interval:
## 26.17874 31.82126
## sample estimates:
## mean of 29
##
29
####################
#
#
#
Exercise 10
#
#
#
####################
z.test(29,mu=mean(data$mass),sd=sd(data$mass)/sqrt(30),
alternative = "less", conf.level = 0.99)
##
##
##
One Sample z-test
## data: 29
## z = -2.079, n = 1.0000, Std. Dev. = 1.4394, Std. Dev. of
the
## sample mean = 1.4394, p-value = 0.01881
## alternative hypothesis: true mean is less than 31.99258
## 99 percent confidence interval:
##
-Inf 32.34865
## sample estimates:
## mean of 29
##
29
Related documents