R Markdown

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:

9.1 Introduction to Hypothesis Testing

    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.

Differences Between One-Tailed and Two-Tailed Tests

One-tailed tests
•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
two-tailed tests
•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

A substantive result is when the outcome of a statistical study produces results that are important to the decision maker.

steps for hypothesis testing

step 1, establishing a null and an alternative hypothesis

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.

Step 2 is to select the most appropriate statistical test to use for the analysis

Step 3, the value of alpha is set. Alpha is the probability of committing a Type I error and will be discussed later. Common values of alpha include .05, .01, .10, and .001.

Step 4 is to establish the decision rule, which should be done before the study is undertaken.

Using alpha and the test statistic, critical values can be determined

Step 5 is to gather sample data.

step 6 After the data are sampled, the test statistic can be calculated

Step 7 is reaching a statistical conclusion

Step 8 is determining the business implications of the statistical decision.

Rejection and Nonrejection Regions

Type I and Type II Errors

    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)

9.2 Testing Hypotheses About a Population Mean Using the z Statistic (σ Known)

z Test for a Single Mean

\(z=\dfrac{\bar x-\mu}{\dfrac\sigma{\sqrt n}}\)

Testing the Mean with a Finite Population

\(z=\dfrac{\bar x-\mu}{\dfrac\sigma{\sqrt n}\sqrt {\dfrac{N-n}{n-1}}}\)

Using the Critical Value Method to Test Hypotheses

Same formula, different formation \(z_c=\dfrac{\bar{x_c}-\mu}{\dfrac \sigma{\sqrt n}}\)

9.3 Testing Hypotheses About a Population Mean Using the t Statistic (σ Unknown)

Table9.3 z Test vs. t Test for a Single Mean

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

9.4 Testing Hypotheses About a Proportion

z Test of a Population Proportion

\(z=\dfrac{\hat p-p}{\sqrt{\dfrac{p\cdot q}n}}\)

9.5 Testing Hypotheses About a Variance

Formula for testing hypotheses about a population variance

\(\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

9.6 Solving for Type II Errors

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

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:

Some Observations About Type II Errors

If the alternative mean or proportion is close to the hypothesized value, the probability of committing a Type II error is high. If the alternative value is relatively far away from the hypothesized value, the probability of committing a Type II error is small.

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.

Operating Characteristic and Power Curves

power is the probability of rejecting the null hypothesis when it is false and represents the correct decision of selecting the alternative hypothesis when it is true

Effect of Increasing Sample Size on the Rejection Limits

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.

CHAPTER 16 Analysis of Categorical Data

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.

16.1 Chi-Square Goodness-of-Fit Test

Chi-Square Goodness-of-Fit Test

\(\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

demo problem 16.2

test whether below table is poisson distributed

NUMBER OF ARRIVALS OBSERVED FREQUENCIES
0 7
1 18
2 25
3 17
4 12
≥5 5

Step 1. The hypotheses follow.

\(H_0:\) The frequency distribution is Poisson. \(H_a:\) The frequency distribution is not Poisson.

Step 2. The appropriate statistical test for this problem is

\(\chi^2=\sum{\dfrac{(f_o-f_e)^2}{f_e}}\)

Step 3. Alpha is .05

Step 4. The degrees of freedom are k − 2 = 6 − 1 − 1 = 4

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

Step 5.

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

Step 6.

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

Step 7.

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.

Step 8.

The supervisor can use the Poisson distribution as the basis for other types of analysis, such as queuing modeling.

Caution:

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.

16.2 Contingency Analysis: Chi-Square Test of Independence

    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.

Formulas

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-Square Test of Independence

\(\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

note

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).

Demo problem

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

Step 1. The hypotheses follow.

\(H_o:\) Type of gasoline is independent of income. \(H_a:\) Type of gasoline is not independent of income.

Step 2.

The appropriate statistical test is

\(\chi^2=\sum\sum\dfrac{(f_o-f_e)^2}{f_e}\)

Step 3.

Alpha is .01.

Step 4.

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

Step 5.

Observed data is in dataframe as demonstrated above

Step 6.

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

Step 7.

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.

Step 8.

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.

automated testing

chisq.test(tbl)
## 
##  Pearson's Chi-squared test
## 
## data:  tbl
## X-squared = 70.727, df = 6, p-value = 2.9e-13