Variable Types
The following variables are included in our data set:
Sex: 0=female, 1=male
Age: Age in years
Married: 0=not married, 1=married
Income: total income for the past 12 months in $US 1000
HoursWk: hours of work per week
Race: asian, black, white, or other
USCitizen: 1=citizen, 0=non-citizen
HealthInsurance: 1=have insurance, 0=no insurance
Language: 1=native English speaker, 0=other
2 Creating Sub-sample
## Load the package and the data set
library (Lock5Data)
d<-as.data.frame(ACS, head=T)
mysample<-d[sample(1:nrow(d),100,replace=F),]
mysample
3 Developing 90% Confidence Interval
## create a new variable for Income, deleting empty observations
Income.response=na.omit(mysample$Income)
Income.response
## [1] 31.20 1.90 0.00 0.00 37.00 0.00 15.00 8.00 10.50 0.00
## [11] 40.00 17.00 294.00 85.00 16.00 0.00 19.00 55.00 12.00 45.00
## [21] 0.00 0.00 45.00 52.00 80.00 25.00 0.00 19.30 0.00 29.70
## [31] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 1.50 0.00 0.00
## [41] 0.00 26.00 20.00 70.00 0.00 0.00 20.00 0.00 13.00 25.00
## [51] 55.00 0.00 65.00 0.00 5.80 4.60 0.00 10.00 15.00 47.00
## [61] 0.00 20.20 22.00 47.00 0.00 20.00 28.00 83.00 22.00 0.00
## [71] 0.00 0.00 0.00 0.00 32.00 0.36 0.00 38.00 0.00 0.00
## [81] 36.00
## calculating a new sample size
n=length(Income.response)
## calculating the sample standard deviation
s=sd(Income.response)
## calculating standard error and margin of error
SE=s/sqrt(n)
E=qt(0.95, df=n-1)*SE
## calculating mean value and confidence interval
xbar=mean(Income.response)
xbar+c(-E,E)
4 Examine the Difference in Income between English and non-English Speakers
## t-test for independent samples is used to examine the difference. The following command runs t-test in R:
t.test(mysample$Income~mysample$Language)
## Welch Two Sample t-test
## data: mysample$Income by mysample$Language
## t = 0.025828, df = 14.324, p-value = 0.9798
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -19.39730 19.87119
## sample estimates:
## mean in group 0 mean in group 1
## 20.57028 20.33333
Since p-value is higher than 0.05, we failed to reject the null hypothesis. There is no evidence for the mean annual income of native English speakers being different from the mean annual income of non-native English speakers (at the 5% level of significance). Their income seems to be approximately equal in both groups