There are 10 questions and each question (part of a question) is worth 7.5 points each. When completed, knit the file to a .HTML and save the file as Test#1_LastName and submit the .HTML file to the Test #1 assignment link in Canvas.
Due Date: Tuesday November 26, 2019 by 11:59p.m. EST.
No, there will be no variables before the “~” symbol in the xtabs () function. When the data has been tabulated as a frequency, we will place the frequency variable before the “~” sign.
library(vcd)
## Loading required package: grid
#run code below
data("DanishWelfare",package="vcd")
#creating a crosstabulation of alcohol consumption (Alcohol), location (Urban) and
#marital status(Status)
structable(Alcohol ~ Urban + Status, DanishWelfare)
## Alcohol <1 1-2 >2
## Urban Status
## Copenhagen Widow 4 4 4
## Married 4 4 4
## Unmarried 4 4 4
## SubCopenhagen Widow 4 4 4
## Married 4 4 4
## Unmarried 4 4 4
## LargeCity Widow 4 4 4
## Married 4 4 4
## Unmarried 4 4 4
## City Widow 4 4 4
## Married 4 4 4
## Unmarried 4 4 4
## Country Widow 4 4 4
## Married 4 4 4
## Unmarried 4 4 4
#insert your modified code below
structable(Status ~ Urban + Alcohol, DanishWelfare)
## Status Widow Married Unmarried
## Urban Alcohol
## Copenhagen <1 4 4 4
## 1-2 4 4 4
## >2 4 4 4
## SubCopenhagen <1 4 4 4
## 1-2 4 4 4
## >2 4 4 4
## LargeCity <1 4 4 4
## 1-2 4 4 4
## >2 4 4 4
## City <1 4 4 4
## 1-2 4 4 4
## >2 4 4 4
## Country <1 4 4 4
## 1-2 4 4 4
## >2 4 4 4
It is in frequency form
Since the DanishWelfare data frame is in frequency form, we can place the variable ‘Freq’ in the xtabs () function to the left of the ‘-’ sign.
Reminder: Three criteria for Binomial experiment (from our class notes): 1. n independent trials (state n and explain why trial are independent) 2. only one of two outcomes; “success” and “failure” (specify what is a “success” and what is a “failure”) 3. the probability of “success” stays the same from trial to trial (state p and why the probability stays the same from trial to trial)
Data from gs.statcounter.com website shows that Chrome browser has 68.91% market share in desktop browser market. We can randomly select 10 desktop browser visitors and keep track of how many of them use Chrome. 1. n independent experiments. We have observed whether desktop browser visitors use Chrome. In this experiment, n is equal to 10. These 10 routes are independent, because whether one visitor uses Chrome does not affect whether another visitor uses Chrome. 2. The test has only two results, yes or no. We would consider the fact that the visitor is using the Chrome browser and the fact that the visitor is not using the Chrome browser. 3. From one trial to another, the probability of answering “yes” remains the same. From the data of the website, the probability of visitors using the Chrome browser is 68.91%.
Is this a binomial experiment? State Yes or No. If Yes, describe the three criteria that make this experiment Binomial. If No, state why this is not a Binomial experiment.
Yes. Suppose we have collected data on p% of people vaccinated this year. We would consider this a binomial experiment for this particular question. ’Are you vaccinated this year? Perform a fixed number of tests. It is worth noting that experiments on other issues may not be a binomial experiment because we do not have information on these issues. We think this is just two experiments for this particular problem, not experiments for the entire researcher.
(1)n independent experiments. We observe whether a person has been vaccinated this year. In this experiment, n is equal to 100. These 100 trials are independent because whether one person is vaccinated does not affect whether another is vaccinated. (2)The test has only two results, yes or no. We will treat “yes” as a fact that the person is vaccinated, and “no” as a fact that the person is not vaccinated. (3)From one trial to another, the probability of answering “yes” remains the same. Based on the data collected, the probability of a person being vaccinated is P%.
Is this a binomial experiment? State Yes or No. If Yes, describe the three criteria that make this experiment Binomial. If No, state why this is not a Binomial experiment.
No, this is not a binomial experiment. The test has more than two results. For the first 5 questions, there are only “right” or “wrong” results, but for the last 5 questions, there are 4 outcomes.
dbinom(6,10,0.25)
## [1] 0.016222
pbinom(5,10,0.25)
## [1] 0.9802723
Use the appropriate R function (must be one we discussed in class) to find the probability.
meanofPatient=4
#P(X>6)
ppois(6,meanofPatient,lower.tail = FALSE)
## [1] 0.110674
Use the appropriate R function (must be one we discussed in class) to find the probability.
ppois(5,meanofPatient,lower.tail = FALSE)
## [1] 0.2148696
Use the appropriate R function (must be one we discussed in class) to find the probability.
dpois(6,meanofPatient)
## [1] 0.1041956
data("CyclingDeaths", package = "vcdExtra")
CyclingDeaths
## date deaths
## 1 2005-01-01 1
## 2 2005-01-15 0
## 3 2005-01-29 0
## 4 2005-02-12 0
## 5 2005-02-26 1
## 6 2005-03-12 1
## 7 2005-03-26 1
## 8 2005-04-09 0
## 9 2005-04-23 2
## 10 2005-05-07 0
## 11 2005-05-21 1
## 12 2005-06-04 0
## 13 2005-06-18 3
## 14 2005-07-02 1
## 15 2005-07-16 1
## 16 2005-07-30 2
## 17 2005-08-13 0
## 18 2005-08-27 0
## 19 2005-09-10 1
## 20 2005-09-24 0
## 21 2005-10-08 0
## 22 2005-10-22 0
## 23 2005-11-05 3
## 24 2005-11-19 0
## 25 2005-12-03 2
## 26 2005-12-17 0
## 27 2005-12-31 1
## 28 2006-01-14 0
## 29 2006-01-28 1
## 30 2006-02-11 0
## 31 2006-02-25 0
## 32 2006-03-11 1
## 33 2006-03-25 1
## 34 2006-04-08 0
## 35 2006-04-22 1
## 36 2006-05-06 0
## 37 2006-05-20 1
## 38 2006-06-03 1
## 39 2006-06-17 0
## 40 2006-07-01 0
## 41 2006-07-15 3
## 42 2006-07-29 0
## 43 2006-08-12 0
## 44 2006-08-26 3
## 45 2006-09-09 1
## 46 2006-09-23 1
## 47 2006-10-07 1
## 48 2006-10-21 0
## 49 2006-11-04 1
## 50 2006-11-18 1
## 51 2006-12-02 0
## 52 2006-12-16 1
## 53 2006-12-30 1
## 54 2007-01-13 0
## 55 2007-01-27 0
## 56 2007-02-10 0
## 57 2007-02-24 3
## 58 2007-03-10 0
## 59 2007-03-24 1
## 60 2007-04-07 1
## 61 2007-04-21 1
## 62 2007-05-05 0
## 63 2007-05-19 0
## 64 2007-06-02 0
## 65 2007-06-16 1
## 66 2007-06-30 0
## 67 2007-07-14 0
## 68 2007-07-28 0
## 69 2007-08-11 0
## 70 2007-08-25 2
## 71 2007-09-08 0
## 72 2007-09-22 0
## 73 2007-10-06 1
## 74 2007-10-20 0
## 75 2007-11-03 0
## 76 2007-11-17 0
## 77 2007-12-01 2
## 78 2007-12-15 1
## 79 2007-12-29 0
## 80 2008-01-12 1
## 81 2008-01-26 0
## 82 2008-02-09 1
## 83 2008-02-23 0
## 84 2008-03-08 1
## 85 2008-03-22 0
## 86 2008-04-05 1
## 87 2008-04-19 1
## 88 2008-05-03 0
## 89 2008-05-17 0
## 90 2008-05-31 0
## 91 2008-06-14 1
## 92 2008-06-28 0
## 93 2008-07-12 0
## 94 2008-07-26 1
## 95 2008-08-09 0
## 96 2008-08-23 0
## 97 2008-09-06 1
## 98 2008-09-20 1
## 99 2008-10-04 0
## 100 2008-10-18 1
## 101 2008-11-01 0
## 102 2008-11-15 2
## 103 2008-11-29 0
## 104 2008-12-13 2
## 105 2008-12-27 0
## 106 2009-01-10 1
## 107 2009-01-24 1
## 108 2009-02-07 0
## 109 2009-02-21 0
## 110 2009-03-07 0
## 111 2009-03-21 0
## 112 2009-04-04 2
## 113 2009-04-18 0
## 114 2009-05-02 1
## 115 2009-05-16 1
## 116 2009-05-30 0
## 117 2009-06-13 0
## 118 2009-06-27 2
## 119 2009-07-11 0
## 120 2009-07-25 0
## 121 2009-08-08 0
## 122 2009-08-22 0
## 123 2009-09-05 1
## 124 2009-09-19 0
## 125 2009-10-03 0
## 126 2009-10-17 1
## 127 2009-10-31 1
## 128 2009-11-14 0
## 129 2009-11-28 1
## 130 2009-12-12 0
## 131 2009-12-26 1
## 132 2010-01-09 0
## 133 2010-01-23 1
## 134 2010-02-06 1
## 135 2010-02-20 0
## 136 2010-03-06 2
## 137 2010-03-20 0
## 138 2010-04-03 1
## 139 2010-04-17 1
## 140 2010-05-01 0
## 141 2010-05-15 1
## 142 2010-05-29 0
## 143 2010-06-12 0
## 144 2010-06-26 0
## 145 2010-07-10 1
## 146 2010-07-24 1
## 147 2010-08-07 0
## 148 2010-08-21 0
## 149 2010-09-04 0
## 150 2010-09-18 0
## 151 2010-10-02 0
## 152 2010-10-16 0
## 153 2010-10-30 0
## 154 2010-11-13 0
## 155 2010-11-27 0
## 156 2010-12-11 0
## 157 2010-12-25 1
## 158 2011-01-08 0
## 159 2011-01-22 1
## 160 2011-02-05 0
## 161 2011-02-19 0
## 162 2011-03-05 1
## 163 2011-03-19 1
## 164 2011-04-02 1
## 165 2011-04-16 2
## 166 2011-04-30 0
## 167 2011-05-14 1
## 168 2011-05-28 1
## 169 2011-06-11 1
## 170 2011-06-25 0
## 171 2011-07-09 0
## 172 2011-07-23 2
## 173 2011-08-06 0
## 174 2011-08-20 0
## 175 2011-09-03 0
## 176 2011-09-17 0
## 177 2011-10-01 1
## 178 2011-10-15 1
## 179 2011-10-29 1
## 180 2011-11-12 0
## 181 2011-11-26 1
## 182 2011-12-10 0
## 183 2011-12-24 1
## 184 2012-01-07 0
## 185 2012-01-21 0
## 186 2012-02-04 0
## 187 2012-02-18 0
## 188 2012-03-03 1
## 189 2012-03-17 2
## 190 2012-03-31 0
## 191 2012-04-14 0
## 192 2012-04-28 1
## 193 2012-05-12 0
## 194 2012-05-26 0
## 195 2012-06-09 0
## 196 2012-06-23 2
## 197 2012-07-07 1
## 198 2012-07-21 1
## 199 2012-08-04 0
## 200 2012-08-18 0
## 201 2012-09-01 0
## 202 2012-09-15 0
## 203 2012-09-29 0
## 204 2012-10-13 1
## 205 2012-10-27 1
## 206 2012-11-10 1
## 207 2012-11-24 1
## 208 2012-12-08 0
CyclingDeaths.tab <- table(CyclingDeaths$deaths)
CyclingDeaths.tab
##
## 0 1 2 3
## 114 75 14 5
gf <- goodfit(CyclingDeaths.tab)
gf
##
## Observed and fitted values for poisson distribution
## with parameters estimated by `ML'
##
## count observed fitted pearson residual
## 0 114 117.946412 -0.3633792
## 1 75 66.911907 0.9887681
## 2 14 18.979820 -1.1430562
## 3 5 3.589133 0.4108395
summary(gf)
##
## Goodness-of-fit test for poisson distribution
##
## X^2 df P(> X^2)
## Likelihood Ratio 4.151738 2 0.1254474
plot(gf, xlab="Number of Deaths")
Type interpretation of this graph below (what is this graph telling you?):
The number of accidents occurring over a period of time corresponds to the poisson distribution.