This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
A research hypothesis is a statement of what the researcher believes will be the outcome of an experiment or a study
A statistical hypothesis is a formal hypothesis structure set up with a null and an alternative hypothesis to scientifically test research hypotheses.
the null hypothesis states that the “null” condition exists; that is, there is nothing new happening, the old theory is still true, the old standard is correct, and the system is in control.
The alternative hypothesis, on the other hand, states that the new theory is true, there are new standards, the system is out of control, and/or something is happening.
•Null hypothesis has an = sign
•Directional
•Cues in problem are directional words such as: higher, lower, older, younger, more, less, longer, shorter, etc.
•Alternative hypothesis has either > or < sign
•The direction (> or <) not included in the alternative hypotheses is assumed to be included in the null hypothesis—although not shown
•Null hypothesis has an = sign
•Nondirectional
•Cues in problem are nondirectional words such as: same, different, equal, not equal, control, out-of-control
•Alternative hypothesis can have only ≠ sign
•Null and alternative hypotheses include all possible cases
In the hypothesis testing process, it is always assumed that the null hypothesis is true at the beginning of the study. In other words, it is assumed that the process is in control (no problems in the process), the market share has not increased, older workers are not more loyal to a company than younger workers, and so on. This process is analogous to the U.S. trial system in which the accused is presumed innocent at the beginning of the trial.
Using alpha and the test statistic, critical values can be determined
A Type I error is committed by rejecting a true null hypothesis.
A Type II error is committed when a business researcher fails to reject a false null hypothesis.
| Null True | Null False | |
|---|---|---|
| Fail to reject NULL | Correct Decision | Type II Error(\(\beta\)) |
| Reject NULL | Type I Error(\(\alpha\)) | Correct Decision(Power) |
\(z=\dfrac{\bar x-\mu}{\dfrac\sigma{\sqrt n}}\)
\(z=\dfrac{\bar x-\mu}{\dfrac\sigma{\sqrt n}\sqrt {\dfrac{N-n}{n-1}}}\)
Same formula, different formation \(z_c=\dfrac{\bar{x_c}-\mu}{\dfrac \sigma{\sqrt n}}\)
| z TEST | t TEST | |
|---|---|---|
| BASIC FORMULA: | \(z=\dfrac{\bar x-\mu}{\dfrac\sigma{\sqrt n}}\) | \(t=\dfrac{\bar x-\mu}{\dfrac s{\sqrt n}}\) |
| DEGREES OF FREEDOM (df): | Does not use degrees of freedom (df) | df = n − 1 |
| POPULATION STANDARD DEVIATION (σ): | Must know the population standard deviation, σ | Do not know σ. Uses sample standard deviation, s |
| SAMPLE SIZE: | n ≥ 30 always okay | n < 30 okay only if population is normally distributed |
| ASSUMPTIONS: | No assumptions unless n < 30. | If n < 30, population must be normally distributed |
\(z=\dfrac{\hat p-p}{\sqrt{\dfrac{p\cdot q}n}}\)
\(\chi^2=\dfrac{(n-1)s^2}{\sigma^2}\)
\(df=n-1\)
v <- c(23, 17, 20, 29, 21, 14, 19, 24)
s2 = var(v)
s2
## [1] 20.98214
n = length(v)
df = n - 1
v.v = 4
chi2 = df * s2 / v.v
chi2
## [1] 36.71875
If a researcher reaches the statistical conclusion to fail to reject the null hypothesis, he makes either a correct decision or a Type II error. If the null hypothesis is true, the researcher makes a correct decision. If the null hypothesis is false, then the result is a Type II error. In business, failure to reject the null hypothesis may mean staying with the status quo, not implementing a new process, or not making adjustments. If a new process, product, theory, or adjustment is not significantly better than what is currently accepted practice, the decision maker makes a correct decision. However, if the new process, product, theory, or adjustment would significantly improve sales, the business climate, costs, or morale, the decision maker makes an error in judgment (Type II). In business, Type II errors can translate to lost opportunities, poor product quality (as a result of failure to discern a problem in the process), or failure to react to the marketplace. Sometimes the ability to react to changes, new developments, or new opportunities is what keeps a business moving and growing. Thus Type II error plays an important role in business statistical decision making.
Determining the probability of committing a Type II error is more complex than finding the probability of committing a Type I error. The probability of committing a Type I error either is given in a problem or is stated by the researcher before proceeding with the study. A Type II error, β, varies with possible values of the alternative parameter. For example, suppose a researcher is conducting a statistical test on the following hypotheses regarding 12-oz. cans of soft drink beverage:
In general, if the alternative value is relatively far from the hypothesized value, the probability of committing a Type II error is smaller than it is when the alternative value is close to the hypothesized value. The probability of committing a Type II error decreases as alternative values of the hypothesized parameter move farther away from the hypothesized value. This situation is shown graphically in operating characteristic curves and power curves.
Increased sample size not only affects the distance of the critical mean value from the hypothesized value of the distribution, but also can result in reducing β for a given value of α.
It is possible to reduce the probabilities of committing Type I and Type II errors simultaneously by increasing sample size.
1.Use the chi-square goodness-of-fit test to analyze probabilities of multinomial distribution trials along a single dimension. 2.Use the chi-square test of independence to perform contingency analysis.
\(\chi^2=\sum{\dfrac{(f_o-f_e)^2}{f_e}}\)
\(df=k-1-c\)
where
\(f_o=\) frequency of observed values \(f_e=\) frequency of expected values \(k=\) number of categories \(c=\) number of parameters being estimated from the sample data
This formula compares the frequency of observed values to the frequency of the expected values across the distribution.
The test loses one degree of freedom because the total number of expected frequencies must equal the number of observed frequencies; that is, the observed total taken from the sample is used as the total for the expected frequencies
In addition, in some instances a population parameter, such as λ, μ, or σ, is estimated from the sample data to determine the frequency distribution of expected values. Each time this estimation occurs, an additional degree of freedom is lost.
As a rule, if a uniform distribution is being used as the expected distribution or if an expected distribution of values is given, k − 1 degrees of freedom are used in the test.
In testing to determine whether an observed distribution is Poisson, the degrees of freedom are k − 2 because an additional degree of freedom is lost in estimating λ.
In testing to determine whether an observed distribution is normal, the degrees of freedom are k − 3 because two additional degrees of freedom are lost in estimating both μ and σ from the observed sample data.
Actually the chi-square distributions constitute a family, with each distribution defined by the degrees of freedom (df) associated with it.
For small df values the chi-square distribution is skewed considerably to the right (positive values). As the df increase, the chi-square distribution begins to approach the normal curve.
qchisq(.05, 3, lower.tail = FALSE)
## [1] 7.814728
qchisq(.01, 11, lower.tail = FALSE)
## [1] 24.72497
test whether below table is poisson distributed
| NUMBER OF ARRIVALS | OBSERVED FREQUENCIES |
|---|---|
| 0 | 7 |
| 1 | 18 |
| 2 | 25 |
| 3 | 17 |
| 4 | 12 |
| ≥5 | 5 |
\(H_0:\) The frequency distribution is Poisson. \(H_a:\) The frequency distribution is not Poisson.
\(\chi^2=\sum{\dfrac{(f_o-f_e)^2}{f_e}}\)
because the expected distribution is Poisson. An extra degree of freedom is lost, because the value of lambda must be calculated by using the observed sample data.
For α = .05, the critical table value is \(\chi^2_{.05,4}=9.4877\). The decision rule is to reject the null hypothesis if the observed chi-square is greater than \(\chi^2_{.05,4}=9.4877\).
qchisq(.05, 4, lower.tail = FALSE)
## [1] 9.487729
| NUMBER OF ARRIVALS | OBSERVED FREQUENCIES | ARRIVAL × OBSERVED |
|---|---|---|
| 0 | 7 | 0 |
| 1 | 18 | 18 |
| 2 | 25 | 50 |
| 3 | 17 | 51 |
| 4 | 12 | 48 |
| ≥5 | 5 | 25 |
| \(\lambda=\dfrac{192}{84}=2.3\) | 84 | 192 |
arrivals <- c(0, 1, 2, 3, 4, 5)
observed <- c(7, 18, 25, 17, 12, 5)
arr.dot.obsvd <- arrivals * observed
tt = sum(arr.dot.obsvd)
lambda = tt / sum(observed)
round(lambda, 1)
## [1] 2.3
Expected probabilities
p0_4 <- round(dpois(seq(0,4), 2.3), 4)
p5 <- 1 - sum(p0_4)
exp_prob = round(c(p0_4, p5), 4)
exp_prob
## [1] 0.1003 0.2306 0.2652 0.2033 0.1169 0.0837
Expected frequencies
expd.freq = round(exp_prob * sum(observed), 2)
expd.freq
## [1] 8.43 19.37 22.28 17.08 9.82 7.03
The supervisor uses these expected frequencies and the observed frequencies to compute the observed value of chi-square
chi2 <- round(sum((observed - expd.freq)^2 / expd.freq), 2)
chi2
## [1] 1.74
The observed value of 1.74 is not greater than the critical chi-square value of 9.4877, so the supervisor’s decision is to not reject the null hypothesis. In other words, he fails to reject the hypothesis that the distribution of bank arrivals is Poisson.
The supervisor can use the Poisson distribution as the basis for other types of analysis, such as queuing modeling.
When the expected value of a category is small, a large chi-square value can be obtained erroneously, leading to a Type I error. To control for this potential error, the chi-square goodness-of-fit test should not be used when any of the expected frequencies is less than 5. If the observed data produce expected values of less than 5, combining adjacent categories (when meaningful) to create larger frequencies may be possible.
The goodness-of-fit test cannot be used to analyze two variables simultaneously. A different chi-square test, the chi-square test of independence, can be used to analyze the frequencies of two variables with multiple categories to determine whether the two variables are independent.
the chi-square test of independence is a test of whether the variables are related.
The null hypothesis for a chi-square test of independence is that the two variables are independent (not related).
If the null hypothesis is rejected, the conclusion is that the two variables are not independent and are related.
Using the multiplicative law for independent events presented in in Chapter 4: \(P(A\cap F)=P(A)\cdot P(F)\)
If A and F are independent, then
\(P(A)=\dfrac {n_A}N,P(F)=\dfrac {n_F}N\), and \(P(A\cap F)=\dfrac {n_A}N\cdot\dfrac {n_F}N\)
Expected frequency for the cell of A and F:
\(e_{AF}=\dfrac {n_A}N\cdot\dfrac {n_F}N(N)=\dfrac {n_A\cdot n_F}N\)
In general, if the two variables are independent, the expected frequency values of each cell can be determined by
\(e_{ij}=\dfrac {n_i\cdot n_j}N\)
where
\(i=\) the row \(j=\) the column \(n_i=\) the total or row \(i\) \(n_j=\) the total or column \(j\) \(N=\) the total of all frequencies
\(\chi^2=\sum\sum\dfrac{(f_o-f_e)^2}{f_e}\)
\(df=(r-1)(c-1)\)
where:
\(r=\) number of rows \(c=\) number of columns \(f_o=\) frequency of observed values \(f_e=\) frequency of expected values
The null hypothesis for a chi-square test of independence is that the two variables are independent. The alternative hypothesis is that the variables are not independent. This test is one-tailed. The degrees of freedom are (r − 1)(c − 1).
Regular <- c(85, 102, 36, 15)
Premium <- c(16, 27, 22, 23)
Premium.Extra <- c(6, 13, 15, 25)
tbl <- cbind(Regular, Premium, Premium.Extra)
tbl2 <- addmargins(tbl)
tbl
## Regular Premium Premium.Extra
## [1,] 85 16 6
## [2,] 102 27 13
## [3,] 36 22 15
## [4,] 15 23 25
tbl2
## Regular Premium Premium.Extra Sum
## 85 16 6 107
## 102 27 13 142
## 36 22 15 73
## 15 23 25 63
## Sum 238 88 59 385
\(H_o:\) Type of gasoline is independent of income. \(H_a:\) Type of gasoline is not independent of income.
The appropriate statistical test is
\(\chi^2=\sum\sum\dfrac{(f_o-f_e)^2}{f_e}\)
Alpha is .01.
df <- (dim(tbl)[1]-1) * (dim(tbl)[2]-1)
df
## [1] 6
cv = round(qchisq(.01, df, lower.tail = FALSE), 4)
cv
## [1] 16.8119
Observed data is in dataframe as demonstrated above
a = dim(tbl)[1]
b = dim(tbl)[2]
N = tbl2[a+1, b+1]
e <- array(numeric(),c(a,b))
for (i in seq(1, a)) {
for (j in seq(1, b)) {
e[i, j] = round(tbl2[i, b+1] * tbl2[a+1, j] / N, 2)
s = sprintf("e%d%d = %3d * %3d / %d = %5.2f", i, j, tbl2[i, b+1], tbl2[a+1, j], N, e[i ,j])
print(s)
}
}
## [1] "e11 = 107 * 238 / 385 = 66.15"
## [1] "e12 = 107 * 88 / 385 = 24.46"
## [1] "e13 = 107 * 59 / 385 = 16.40"
## [1] "e21 = 142 * 238 / 385 = 87.78"
## [1] "e22 = 142 * 88 / 385 = 32.46"
## [1] "e23 = 142 * 59 / 385 = 21.76"
## [1] "e31 = 73 * 238 / 385 = 45.13"
## [1] "e32 = 73 * 88 / 385 = 16.69"
## [1] "e33 = 73 * 59 / 385 = 11.19"
## [1] "e41 = 63 * 238 / 385 = 38.95"
## [1] "e42 = 63 * 88 / 385 = 14.40"
## [1] "e43 = 63 * 59 / 385 = 9.65"
e
## [,1] [,2] [,3]
## [1,] 66.15 24.46 16.40
## [2,] 87.78 32.46 21.76
## [3,] 45.13 16.69 11.19
## [4,] 38.95 14.40 9.65
calc chi2
chi2 <- sum(round((e - tbl)^2 / e, 2))
chi2
## [1] 70.78
The observed value of chi-square, 70.78, is greater than the critical value of chi-square, 16.8119, obtained from Table A.8. The business researcher’s decision is to reject the null hypothesis; that is, type of gasoline preferred is not independent of income.
Having established that conclusion, the business researcher can then examine the outcome to determine which people, by income brackets, tend to purchase which type of gasoline and use this information in market decisions.
chisq.test(tbl)
##
## Pearson's Chi-squared test
##
## data: tbl
## X-squared = 70.727, df = 6, p-value = 2.9e-13