# Probability woman exceeds 180cm in height
# P(X > 180) = 1 - P(X <= 180)
1 - pnorm(180, mean = 163, sd = 8)
[1] 0.01679331
Lecture 5
The-one sample variance test uses chi-squared distribution
Recall: Chi-squared distribution with p degrees of freedom is χp2=Z12+…+Zp2 where Z1,…,Zp are iid N(0,1)
Assumption: Suppose given sample X1,…,Xn iid from N(μ,σ2)
Goal: Estimate variance σ2 of population
Test:
Suppose σ0 is guess for σ
The one-sided hypothesis test for σ is H0:σ=σ0H1:σ>σ0
Consider the sample variance S2=n−1∑i=1nXi2−nX2
Since we believe H0, the variance is σ=σ0
S2 cannot be too far from the true variance σ
Therefore we cannot have that S2≫σ2=σ02
If we observe S2≫σ02 then our guess σ0 is probably wrong
Therefore we reject H0 if S2≫σ02
The rejection condition S2≫σ02 is equivalent to σ02(n−1)S2≫1 where n is the sample size
We define our test statistic as χ2:=σ02(n−1)s2
The rejection condition is hence χ2≫1
Recall that σ2(n−1)S2∼χn−12
Assuming σ=σ0, we therefore have χ2=σ02(n−1)S2=σ2(n−1)S2∼χn−12
We reject H0 if χ2=σ02(n−1)S2≫1
As χ2∼χn−12, we decide to rejct H0 if χ2>χn−12(0.05)
By definition the critical value χn−12(0.05) is such that P(χn−12>χn−12(0.05))=0.05
x∗:=χn−12(0.05) is point on x-axis such that P(χn−12>x∗)=0.05
In the picture we have n=12 and χ112(0.05)=19.68
Given the test statistic χ2 the p-value is defined as p:=P(χn−12>χ2)
Notice that p<0.05⟺χ2>χn−12(0.05)
This is because χ2>χn−12(0.05) iff p=P(χn−12>χ2)<P(χn−12>χn−12(0.05))=0.05
Suppose given
The one-sided hypothesis test is H0:σ=σ0H1:σ>σ0 The variance ratio test consists of 3 steps
Month | J | F | M | A | M | J | J | A | S | O | N | D |
---|---|---|---|---|---|---|---|---|---|---|---|---|
Cons. Expectation | 66 | 53 | 62 | 61 | 78 | 72 | 65 | 64 | 61 | 50 | 55 | 51 |
Cons. Spending | 72 | 55 | 69 | 65 | 82 | 77 | 72 | 78 | 77 | 75 | 77 | 77 |
Difference | -6 | -2 | -7 | -4 | -4 | -5 | -7 | -14 | -16 | -25 | -22 | -26 |
Month | J | F | M | A | M | J | J | A | S | O | N | D |
---|---|---|---|---|---|---|---|---|---|---|---|---|
Cons. Expectation | 66 | 53 | 62 | 61 | 78 | 72 | 65 | 64 | 61 | 50 | 55 | 51 |
Cons. Spending | 72 | 55 | 69 | 65 | 82 | 77 | 72 | 78 | 77 | 75 | 77 | 77 |
Difference | -6 | -2 | -7 | -4 | -4 | -5 | -7 | -14 | -16 | -25 | -22 | -26 |
If X∼N(μ,σ2) then P(μ−2σ≤X≤μ+2σ)≈0.95
Recall: Difference = (CE − CS) ∼N(μ,σ2)
Hence if σ=1 P(μ−2≤CE−CS≤μ+2)≈0.95
Meaning of variance ratio test: σ=1⟹CS index is within ±2σ of CE index with probability 0.95
Month | J | F | M | A | M | J | J | A | S | O | N | D |
---|---|---|---|---|---|---|---|---|---|---|---|---|
Difference | -6 | -2 | -7 | -4 | -4 | -5 | -7 | -14 | -16 | -25 | -22 | -26 |
Month | J | F | M | A | M | J | J | A | S | O | N | D |
---|---|---|---|---|---|---|---|---|---|---|---|---|
Difference | -6 | -2 | -7 | -4 | -4 | -5 | -7 | -14 | -16 | -25 | -22 | -26 |
Month | J | F | M | A | M | J | J | A | S | O | N | D |
---|---|---|---|---|---|---|---|---|---|---|---|---|
Difference | -6 | -2 | -7 | -4 | -4 | -5 | -7 | -14 | -16 | -25 | -22 | -26 |
Goal: Perform chi-squared variance ratio test in R
For this we need to compute p-value p=P(χn−12>χ2)
Thus, we need to compute probabilities for chi-squared distribution in R
R command | Meaning |
---|---|
pnorm(x, mean = mu, sd = sig) |
P(X≤x) |
qnorm(p, mean = mu, sd = sig) |
P(X≤q)=p |
dnorm(x, mean = mu, sd = sig) |
f(x) where f is distr. of X |
rnorm(n, mean = mu, sd = sig) |
n random samples from distr. of X |
Note: Syntax of commands
norm = normal p = probability q = quantile
d = distribution r = random
df = n
denotes n degrees of feedomR command | Meaning |
---|---|
pchisq(x, df = n) |
P(X≤x) |
qchisq(p, df = n) |
P(X≤q)=p |
dchisq(x, df = n) |
f(x) where f is distr. of X |
rchisq(m, df = n) |
m random samples from distr. of X |
The χ2 statistic for variance ratio test has distribution χn−12
Question: Compute the p-value p:=P(χn−12>χ2)
The χ2 statistic for variance ratio test has distribution χn−12
Question: Compute the p-value p:=P(χn−12>χ2)
Observe that p:=P(χn−12>χ2)=1−P(χn−12≤χ2)
The code is therefore
Month | J | F | M | A | M | J | J | A | S | O | N | D |
---|---|---|---|---|---|---|---|---|---|---|---|---|
Cons. Expectation | 66 | 53 | 62 | 61 | 78 | 72 | 65 | 64 | 61 | 50 | 55 | 51 |
Cons. Spending | 72 | 55 | 69 | 65 | 82 | 77 | 72 | 78 | 77 | 75 | 77 | 77 |
Difference | -6 | -2 | -7 | -4 | -4 | -5 | -7 | -14 | -16 | -25 | -22 | -26 |
Back to Example: Monthly data on CE and CS
Question: Test the following hypothesis: H0:σ=1H1:σ>1
Month | J | F | M | A | M | J | J | A | S | O | N | D |
---|---|---|---|---|---|---|---|---|---|---|---|---|
Cons. Expectation | 66 | 53 | 62 | 61 | 78 | 72 | 65 | 64 | 61 | 50 | 55 | 51 |
Cons. Spending | 72 | 55 | 69 | 65 | 82 | 77 | 72 | 78 | 77 | 75 | 77 | 77 |
Difference | -6 | -2 | -7 | -4 | -4 | -5 | -7 | -14 | -16 | -25 | -22 | -26 |
# Compute p-value
p_value <- 1 - pchisq(chi_squared, df = n - 1)
# Print p-value
cat("The p-value for one-sided variance test is", p_value)
The p-value for one-sided variance test is 0
Recall: Chi-squared distribution with p degrees of freedom is χp2=Z12+…+Zp2 where Z1,…,Zn are iid N(0,1)
Chi-squared distribution was used to:
Describe distribution of sample variance S2: σ2(n−1)S2∼χn−12
Define t-distribution: tp∼V/pU where U∼N(0,1) and V∼χp2
F-distribution is:
Notation: F-distribution with p and q degrees of freedom is denoted by Fp,q
The F-distribution is obtained as ratio of 2 independent chi-squared distributions
Similar to the proof (seen in Homework 3) that V/pU∼tp where U∼N(0,1) and V∼χp2 are independent
In our case we need to prove X:=V/qU/p∼Fp,q where U∼χp2 and V∼χq2 are independent
U∼χp2 and V∼χq2 are independent. Therefore fU,V(u,v)=fU(u)fV(v)=Γ(2p)Γ(2q)2(p+q)/21u2p−1v2q−1e−(u+v)/2
Consider the change of variables x(u,v):=v/qu/p,y(u,v):=u+v
This way we have X=V/qU/p,Y=U+V
We can compute fX via fX(x)=∫0∞fX,Y(x,y)dy
Since fU,V is known, then also fX,Y is known
Moreover the integral fX(x)=∫0∞fX,Y(x,y)dy can be explicitly computed, yielding the thesis fX(x)=Γ(2p)Γ(2q)Γ(2p+q)(qp)p/2[1+(p/q)x](p+q)/2x(p/2)−1
Suppose X∼Fp,q with q>2. Then IE[X]=q−2q
If X∼Fp,q then 1/X∼Fq,p
If X∼tq then X2∼F1,q
Requires a bit of work. It will be left as Homework assignment
By the Theorem in Slide 43 we have X∼Fp,q⟹X=V/qU/p with U∼χp2 and V∼χq2 independent. Therefore X1=U/pV/q∼Fq,p