Email             :
RPubs            : https://rpubs.com/ferdnw/
Address         : ARA Center, Matana University Tower
                         Jl. CBD Barat Kav, RT.1, Curug Sangereng, Kelapa Dua, Tangerang, Banten 15810.

Point Estimate of Population Mean

For any particular random sample, we can always compute it’s sample mean. Although most often it is not the actual population mean, it does serve as a good point estimate. Note that, the population-mean is a measure of the center or “average” value in the whole population of a variable measured. Accordingly, the sample mean is a sample estimate of the population mean. It is the same measure of center, obtained from a sample. The variable in your sample must be measured at the interval or ratio level.

Exercise 5

Find a point estimate of average university student Age with the sample data from survey!

library(MASS)

agesurvey = survey$Age                          # select the Age Column
mean(agesurvey, na.rm=TRUE)                        # the point estimate of student age
## [1] 20.37451

The Average Students Age is Around 20y.o

Sampling Size of Population Mean (Known σ )

In some cases we have improve the quality of a sample survey by increasing the sample size. We can use the following formula to provide the sample size needed under the requirement of population mean interval estimate at
(1−α) confidence level, margin of error E , and population variance σ^2 . Here, zα/2 is the 100(1−α/2) percentile of the standard normal distribution.

Case 17

Assume the population standard deviation
σ of the student height in survey is 9.48. Find the sample size needed to achieve a 1.2 centimeters margin of error at 95% confidence level.

zstar = qnorm(.975)                                    # quantiles (95% confidence level)
sigma = 9.48                                           # assume population standard deviation 
E = 1.2                                                # expected error
zstar^2*sigma^2/ E^2                                   # sampling size 
## [1] 239.7454

Based on the assumption of population standard deviation being 9.48, it needs a sample size of 240 to achieve a 1.2 centimeters margin of error at 95% confidence level.

Exercise 6

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

zstar = qnorm(.975)                                    # quantiles (95% confidence level)
sigma = 9.48                                           # assume population standard deviation 
E =  0.72                                             # Reduce the Expected Error by 40%
zstar^2*sigma^2/ E^2                                   # sampling size 
## [1] 665.9596

Dengan asumsi bahwa SD = 9.48 MaKa buth sampel sebanyak 666 untuk mendapatkan nilai margin error 0.72cm ddengan CI 95%

Sampling Size of Population Proportion

The quality of a sample survey can be improved by increasing the sample size. The formula below provide the sample size needed under the requirement of population proportion interval estimate at (1−α) confidence level, margin of error , and planned proportion estimate p . Here, zα/2 is the 100(1−α/2) percentile of the standard normal distribution. n=(zα/2)^2 p(1−p) / E^2

Case 19

Using a 50% planned proportion estimate, find the sample size needed to achieve 5% margin of error for the female student survey at 95% confidence level.

zstar = qnorm(.975)                                    # quantiles (95% confidence level)
p = 0.5                                                # 50% planned proportion estimate
E = 0.05                                               # expected error
zstar^2*p*(1-p)/E^2                                    # sampling size
## [1] 384.1459

Dengan Proporasi 50-50, untuk mendapatkan error rate 5% maka sibtuhkan 385 Siswa Perempuan.

Exercise 7

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!

zstar = qnorm(.975)                                    # quantiles (95% confidence level)
p = 0.75                                                # Unplanned proportion estimate, Proportion We Received From Data is Male 75-25 Female
E = 0.05                                               # expected error
zstar^2*p*(1-p)/E^2                                    # sampling size
## [1] 288.1094

Dengan Proporsi Laki-Laki ke Perempuan 75-25 sebagai contoh, dibutuhkan sampel laki-laki sebanyak 289 orang.

Exercise 8

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

cps = read.csv('cps04.csv')

Estimasi Mean Usia

mean(cps$age, na.rm=T)
## [1] 29.75445

Rata-Rata berusia 29-30 an Tahun

Age Margin of Error

SE = (sd(cps$age))/ 7986
E = qt(.975, 7985)*SE

E
## [1] 0.000709662

Confidence Interval 95% of Age

mean(cps$age, na.rm=T) + c(-E, E)                                        # confidence interval as told
## [1] 29.75374 29.75515

Dengan Confidence Interval 95% kita bisa tahu bahwa sebaran atau erornya sangat kecil, jadi kebanyakan persebaran data ada di usia 29-30

Menggunakan T-Test

t.test(cps$age)
## 
##  One Sample t-test
## 
## data:  cps$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

Proporsi Marriage Status

single = cps$bachelor

a = sum(cps$bachelor == "1")
b = length(single)

propmar = a/b
propmar
## [1] 0.4557976

Estimasi Sebanyak 45,57% dari proporsi masih Single atau Belum Menikah.

prop.test(a,b)
## 
##  1-sample proportions test with continuity correction
## 
## data:  a out of b, null probability 0.5
## X-squared = 62.237, df = 1, p-value = 3.045e-15
## alternative hypothesis: true p is not equal to 0.5
## 95 percent confidence interval:
##  0.4448359 0.4668022
## sample estimates:
##         p 
## 0.4557976

Dengan Confidence Interval, kita bisa memperkirakan pada populasi bahwa sekitar 44.48% sampai 46.68% Masih Single.

Proporsi Wanita-Pria

female = cps$female

aa = sum(cps$female == "1")
bb = length(female)

propfe = aa/bb
propfe
## [1] 0.414851

Estimasi bahwa 41.48% Populasi adalah WAnita

prop.test(aa,bb)
## 
##  1-sample proportions test with continuity correction
## 
## data:  aa out of bb, 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

Dengan Confidence Interval pada 95% diperkirakan pada populasi, 40.40% sampai 42.57% adalah WAnita.