1. A Bloomberg Businessweek subscriber study asked, “in the past 12 months, when traveling for business, what type of airline ticket did you purchase most often?” A second question asked if the type of airline ticket purchased most often was for domestic or international travel. Sample data obtained are shown in the following table.
Type of Ticket |
Domestic Flight |
International Flight |
---|---|---|
First class |
29 |
22 |
Business class |
95 |
121 |
Economy class |
518 |
135 |
a) The study wants to test whether the type of ticket is independent of the type of flight. Clearly state the null and alternative hypotheses.
b) Compute the expected frequencies by completing the table below.
Type of Ticket |
Domestic Flight |
International Flight |
Total |
First Class |
|||
Business Class |
|||
Economy Class |
|||
Total |
c) Compute the test statistic.
Please copy your R code and the result and paste
them here.
d) At 5% significance level, compute the critical
value for the test statistic and the p value for the test. Draw
your conclusion.
Please copy your R code and the result and paste
them here.
e) Use the function chisq.test() in R to run the test directly to confirm your results above are correct.
Please copy your R code and the result and paste them here.
The obtained sample data is
Domestic flight | International flight | Total | |
First Class | 29 | 22 | 51 |
Business Class | 95 | 121 | 216 |
Economy Class | 518 | 135 | 653 |
Total | 642 | 278 | 920 |
a) Now we have to test whether the type of ticket is independent of the type of flight. Therefore the hypothesis is
Null hypothesis, H0 : Type of ticket is independent of the type of flight
Alternate hypothesis, H1 : Type of ticket is not independent of the type of flight.
b)
Now the expected frequencies are obtained by using following formula
Hence
Domestic flight | International flight | Total | |
First Class | 35.5891 | 15.4109 | 51 |
Business Class | 150.7304 | 65.2696 | 216 |
Economy Class | 455.6804 | 197.3196 | 653 |
Total | 642 | 278 | 920 |
c)
The test statistic for testing above hypothesis is
Oij (Observed frequency) | Eij (Expected frequency) | (Oij-Eij)2/Eij |
29 | 35.5891 | 1.2199 |
22 | 15.4109 | 2.8172 |
95 | 150.7304 | 20.6055 |
121 | 65.2696 | 47.5854 |
518 | 455.6804 | 8.5229 |
135 | 197.3196 | 19.6824 |
Total | 920 |
Therefore the value of test statistic is 100.4334.
R-Code:
> Oij=c(29,22,95,121,518,135) ## Oij = Observed
Frequency
> Eij=c(35.5891,15.4109,150.7304,65.2696,455.6804,197.3196) ##
Eij = Expected Frequency
> chi_test=sum(((Oij-Eij)^2)/Eij) ## chisquare test
statistic
> chi_test
[1] 100.4334
Therefore the value of test statistic is 100.4334.
d)
Let the level of significance = = 0.05 and (r-1)*(c-1) = 2
Hence the degrees of freedom = 2
Therefore the critical value for the test statistic is
Now value of A is computed by using following formula
Hence A = 5.991 -------------------(By using chisquare table)
Therefore, the critical value for the test statistic is 5.991.
P-value is
Therefore p- value is 0.
R code:
> Oij=c(29,22,95,121,518,135) ## Oij = Observed
Frequency
> Eij=c(35.5891,15.4109,150.7304,65.2696,455.6804,197.3196) ##
Eij = Expected Frequency
> chi_test=sum(((Oij-Eij)^2)/Eij) ## chisquare test
statistic
> critical_value = qchisq(p=0.05, df=2, lower.tail=FALSE)
> critical_value
[1] 5.991465
> pvalue=pchisq(chi_test,df=2,lower.tail=FALSE) ## pvalue for
test
> pvalue
[1] 1.552954e-22
e)
> data=matrix(c(29,95,518,22,121,135),nrow=3,ncol=2)
> data
[,1] [,2]
[1,] 29 22
[2,] 95 121
[3,] 518 135
> chisq.test(data)
Pearson's Chi-squared test
data: data
X-squared = 100.43, df = 2, p-value < 2.2e-16
Get Answers For Free
Most questions answered within 1 hours.