Komputasi Statistika

~ Tugas 2 ~


Kontak : \(\downarrow\)
Email
Instagram https://www.instagram.com/diasary_nm/
RPubs https://rpubs.com/diyasarya/

Exercise 1

Find a point estimate of average university student Age with the sample data from survey!
Please explain something from your exercise result.

Answer 1

library(MASS)
Age.survey = survey$Age
mean(Age.survey, na.rm=TRUE)
## [1] 20.37451
p.est<-t.test(Age.survey, conf.level = 0.95)
p.est$conf.int
## [1] 19.54600 21.20303
## attr(,"conf.level")
## [1] 0.95

Exercise 2

Assume the population standard deviation [Math Processing Error] of the student Age in data survey is 7. Find the margin of error and interval estimate at 95% confidence level.

Answer 2

age.response = na.omit(survey$Age)
n = length(age.response)
sigma = 7
sem = sigma/sqrt(n)
E = qnorm(.975)*sem 
E
## [1] 0.8911934
xbar = mean(age.response)
xbar
## [1] 20.37451
xbar + c(-E, E)
## [1] 19.48332 21.26571

Exercise 3

Without assuming the population standard deviation [Math Processing Error] of the student Age in survey, find the margin of error and interval estimate at 95% confidence level.

Answer 3

age.response = na.omit(survey$Age)
n = length(age.response)
s = 9.48
SE = s/sqrt(n)
E = qt(.975, df=n-1)*SE
E
## [1] 1.213152
xbar = mean(age.response)
xbar
## [1] 20.37451
xbar + c(-E, E)
## [1] 19.16136 21.58767

Exercise 4

Improve the quality of a sample survey by increasing the sample size with unknown standard deviation!.

Answer 4

z_star1 = qnorm(.975)
z_star1
## [1] 1.959964
E = 1.63
z_star1^2*sigma^2/E^2
## [1] 70.84628

Excercise 5

Assume you don’t have planned proportion estimate, find the sample size needed to achieve 5% margin of error for the male student survey at 95% confidence level!

Answer 5

zstar = qnorm(.975)
E = 0.05
zstar^2/E^2
## [1] 1536.584

Exercise 6

Perform confidence intervals analysis on this data set (cps04.csv) from 2004 that includes data on average hourly earnings, marital status, gender, and age for thousands of people.

Answer 6

e6 = read.csv("cps04.csv")
mean(e6$age, na.rm=TRUE)
## [1] 29.75445
p.est <- t.test(e6$age, conf.level = 0.95)
p.est$conf.int
## [1] 29.69103 29.81786
## attr(,"conf.level")
## [1] 0.95
t.test(e6$age)
## 
##  One Sample t-test
## 
## data:  e6$age
## t = 919.71, df = 7985, p-value < 2.2e-16
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  29.69103 29.81786
## sample estimates:
## mean of x 
##  29.75445

Population Proportion

female = e6$female
n = length(female)
k = sum(female == "1")
pbar = k/n; pbar
## [1] 0.414851

Interval Population Proportion

prop.test(k, n)
## 
##  1-sample proportions test with continuity correction
## 
## data:  k out of n, null probability 0.5
## X-squared = 231.26, df = 1, p-value < 2.2e-16
## alternative hypothesis: true p is not equal to 0.5
## 95 percent confidence interval:
##  0.4040262 0.4257582
## sample estimates:
##        p 
## 0.414851