What does it mean by 95% confidence interval? This is something related to the Type I error and, therefore, the $\alpha$. If we set the $\alpha$ to 0.05, the confidence interval is (1-$\alpha$)*100 %. The 95% is the area under a distribution curve (0.95), between $z_{\alpha/2}$ and $1- z_{\alpha/2}$.
>> z2=norminv(0.025,0,1)
z2 =
-1.9600
>> normspec([z2,-z2],0,1)
ans =
0.9500
The shade area is computed from
\[P({z^{\alpha /2}} < Z < {z^{1-\alpha /2}}) = 1-\alpha \]
where
\[Z = \frac{{\bar X - \mu }}{{\sigma /\sqrt n }}\]
therefore
\[P({z^{\alpha /2}} < \frac{{\bar X-\mu }}{{\sigma /\sqrt n }} < {z^{1-\alpha /2}}) = 1-\alpha \]
and some rearrangements
\[P(\bar X - {z^{1 - \alpha /2}}\frac{\sigma }{{\sqrt n }} < \mu < \bar X - {z^{\alpha /2}}\frac{\sigma }{{\sqrt n }}) = 1-\alpha \]
Thus the lower limit is \[\bar X - {z^{1 - \alpha /2}}\frac{\sigma }{{\sqrt n }}\] and the upper limit is \[\bar X - {z^{1 - \alpha /2}}\frac{\sigma }{{\sqrt n }}\]
For the travel time problem ($\bar X=47.2$,$\sigma /\sqrt n=1.5$), if we set the $\alpha$ to be 0.05, the confidence interval is:
>> interval = 47.2 - [-z2 z2]*1.5
interval =
44.2601 50.1399
That means we are 95% confidence that the real average travel time is between 44.26 to 50.14 minutes, which is actually correct since the compared average travel time is 45 minutes.
Monday, May 31, 2010
P-value Approach to Hypothesis Testing
Recall that in the critical value approach to hypothesis testing, one must set the alpha in order to get the critical value. Then, if a test statistic is higher than this critical value, the null hypothesis will be rejected. Alternatively, the p-value is the probability of observing a value of the test statistics (ie. the mean) as extreme as that is observed. For example, the p-value for lower-tail test is
\[p-value = {P_{{H_0}}}(T \le {t_0})\]
And for upper tail test is
\[p-value = {P_{{H_0}}}(T \ge {t_0})\]
Where $t_0$ is the observed value of the test statistic $T$, and $P_{H_0}$ denotes the probability under the null hypothesis. The p-value is sometime referred to as the observed significance level.
For example, The p-value of average traval time 47.2 from the previous average 45 with standard deviation 1.5 is
The p-value is 0.0712. If we do the hypothesis test at 0.05 significant level, we would not reject the null hypothesis.
\[p-value = {P_{{H_0}}}(T \le {t_0})\]
And for upper tail test is
\[p-value = {P_{{H_0}}}(T \ge {t_0})\]
Where $t_0$ is the observed value of the test statistic $T$, and $P_{H_0}$ denotes the probability under the null hypothesis. The p-value is sometime referred to as the observed significance level.
For example, The p-value of average traval time 47.2 from the previous average 45 with standard deviation 1.5 is
>> mu=45;
>> sig=1.5;
>> xbar=47.2;
>> zobs = (xbar-mu)/sig;
>> pval=1-normcdf(zobs,0,1)
pval =
0.0712
Power of a Hypothesis Test
Remember the $\beta$ (Type II Error) ? There is one convenient way to test the performance of a hypothesis test by determining the probability of not making a Type II error. It is called power of the test: $1-\beta$. In fact, it is the probability of rejecting H0 when it is really false.
Here is the illustration of the beta:
>> normspec([-inf,1.645],3,1)
ans =
0.0877
>> l=linspace(-4,4,100);
>> n=normpdf(l,0,1);
>> hold on;
>> plot(l,n,'r')
>> title("Power = 0.0877")
And here is for the power
>> plot(l,n,'r')
>> title('Power = 1-Beta = 0.9123')
Here is the illustration of the beta:
>> normspec([-inf,1.645],3,1)
ans =
0.0877
>> l=linspace(-4,4,100);
>> n=normpdf(l,0,1);
>> hold on;
>> plot(l,n,'r')
>> title("Power = 0.0877")
And here is for the power
>> normspec([1.645,inf],3,1)
ans =
0.9123
ans =
0.9123
>> plot(l,n,'r')
>> title('Power = 1-Beta = 0.9123')
Sunday, May 30, 2010
Critical Value Approach to Hypothesis Testing
Usually, we define a test statistic by
\[z = \frac{{\bar x - {\mu_0}}}{{{\sigma_{\bar X}}}} = \frac{{\bar x - {\mu_0}}}{{{\sigma_X}/\sqrt n }}\]
Let's do some practical example. If in the year 2000, the average travel time in town A is 45 minutes, a recent survey in the year 2010 of the same town with n=100 commute times found that the average travel time is 47.2 minutes with the standard deviation $\sigma=15$ minutes. Has the average commute time really increased?
Here we have the statistical hypotheses:
H0: $\mu=45$ minutes
H1: $\mu> 45$ minutes
Thus, based on the above information
\[z = \frac{{47.2 - 45}}{{15/\sqrt {100} }} = \frac{{2.2}}{{1.5}} = 1.47\]
This is an upper tail test:
\[P_{H_0}(T \le t) = 1- \alpha \]
We want conduct this test at the significant level $\alpha=0.05$. Conceptually, the rejection region is the top 5% of the area under a standard normal curve, as shown by the following MATLAB code
0.0500
The 1.6449 is the critical value for rejecting H0 at $\alpha=0.05$. Since the statistic test result 1.47 is less than the critical value, we do not reject H0. This means the average travel time in 2010 is not really different from 2000.
\[z = \frac{{\bar x - {\mu_0}}}{{{\sigma_{\bar X}}}} = \frac{{\bar x - {\mu_0}}}{{{\sigma_X}/\sqrt n }}\]
Let's do some practical example. If in the year 2000, the average travel time in town A is 45 minutes, a recent survey in the year 2010 of the same town with n=100 commute times found that the average travel time is 47.2 minutes with the standard deviation $\sigma=15$ minutes. Has the average commute time really increased?
Here we have the statistical hypotheses:
H0: $\mu=45$ minutes
H1: $\mu> 45$ minutes
Thus, based on the above information
\[z = \frac{{47.2 - 45}}{{15/\sqrt {100} }} = \frac{{2.2}}{{1.5}} = 1.47\]
This is an upper tail test:
\[P_{H_0}(T \le t) = 1- \alpha \]
We want conduct this test at the significant level $\alpha=0.05$. Conceptually, the rejection region is the top 5% of the area under a standard normal curve, as shown by the following MATLAB code
>> cv = norminv(0.95,0,1)
cv =
1.6449
>> p=normspec([cv,inf],0,1)
p =1.6449
>> p=normspec([cv,inf],0,1)
0.0500
The 1.6449 is the critical value for rejecting H0 at $\alpha=0.05$. Since the statistic test result 1.47 is less than the critical value, we do not reject H0. This means the average travel time in 2010 is not really different from 2000.
Error in Hypothesis Testing
There are two types of errors that can occur when we make a decision in statistical hypothesis testing. The first is a Type I error, which means we reject H0 when it is really true. Another error is called Type II error, when means we accept H0 but it is really false.
I am always confused about these two, despite many years of statistical background :(
In short,
Type I Error: Incorrectly reject the H0
Type II Error: Incorrectly NOT reject the H0
We denote the symbols for the probability of Type I error is $\alpha$ and of Type II error is $\beta$.
The $\alpha$ is sometime called the sinificance level of the test and it represents the maximum probability of Type I error that will be tolerated. Typical values of $\alpha$ are 0.01, 0.05, 0.10.
I am getting more understanding about Type I and Type II error and it can be linked to the True Positive, False Positive, False Negative and True Negative as follow.
Actually, the main confusion came because of the name "positive". Here, "Positive" means "rejecting H0" and "Negative" means "fail to reject H0" OK?
Therefore, The 2x2 matrix of test/actual conditions is
Moreover, while Type I error is the False Positive (FP) but the $\alpha$ is not the same as "false positive" as most references try to say. It should be "false positive rate" FP/(FP+TN). This way, it makes more sense for the $1-\alpha$ to be called the specificity = TN/(FP+TN).
On the other hand, Type II error is the False Negative (FN) but the $\beta$ is the "false negative rate" FN/(TP+FN). Now, the power or $1-\beta$, which is also called the sensitivity, is TP/(TP+FN).
I am always confused about these two, despite many years of statistical background :(
In short,
Type I Error: Incorrectly reject the H0
Type II Error: Incorrectly NOT reject the H0
The $\alpha$ is sometime called the sinificance level of the test and it represents the maximum probability of Type I error that will be tolerated. Typical values of $\alpha$ are 0.01, 0.05, 0.10.
I am getting more understanding about Type I and Type II error and it can be linked to the True Positive, False Positive, False Negative and True Negative as follow.
Actually, the main confusion came because of the name "positive". Here, "Positive" means "rejecting H0" and "Negative" means "fail to reject H0" OK?
Therefore, The 2x2 matrix of test/actual conditions is
Moreover, while Type I error is the False Positive (FP) but the $\alpha$ is not the same as "false positive" as most references try to say. It should be "false positive rate" FP/(FP+TN). This way, it makes more sense for the $1-\alpha$ to be called the specificity = TN/(FP+TN).
On the other hand, Type II error is the False Negative (FN) but the $\beta$ is the "false negative rate" FN/(TP+FN). Now, the power or $1-\beta$, which is also called the sensitivity, is TP/(TP+FN).
Statistical Hyposthesis Testing
In hypothesis Testing, there are two hypotheses. The first one is called null hypothesis H0, which usually the hypothesis we would like to test. The second one is called alternative hypothesis H1. When we reject H0, the leads to accepting H1.
Technically, H0 is something we hope if we make wrong decision, it will have less severe effects. For example, in a murder case, a suspect is put in a trial. The judge could have two ways of thinking.
H0: The suspect is the murderer.
H1: The suspect is innocent.
or
H0: The suspect is innocent.
H1: The suspect is the murderer.
Can you guess which one every judge think? Of course, the later one. By assume that the suspect is innocent (but he is not), the judge may let go of the suspect (wrong decision). If the judge makes wrong decision, no one die more in the process. However, in the first thinking, The judge may put an innocent people to be killed.
In product inspection for manufacturing process, H0 is the assumption that the product is good, H1 is the otherwise.
Why?, well try to think in terms of the cost of inspection from the manufacturer's point of view.
Technically, H0 is something we hope if we make wrong decision, it will have less severe effects. For example, in a murder case, a suspect is put in a trial. The judge could have two ways of thinking.
H0: The suspect is the murderer.
H1: The suspect is innocent.
or
H0: The suspect is innocent.
H1: The suspect is the murderer.
Can you guess which one every judge think? Of course, the later one. By assume that the suspect is innocent (but he is not), the judge may let go of the suspect (wrong decision). If the judge makes wrong decision, no one die more in the process. However, in the first thinking, The judge may put an innocent people to be killed.
In product inspection for manufacturing process, H0 is the assumption that the product is good, H1 is the otherwise.
Why?, well try to think in terms of the cost of inspection from the manufacturer's point of view.
Tuesday, May 25, 2010
Gelman and Rubin Method for MCMC Convergence
The common problem when constructing a MCMC is when to stop it. It should be stopped when it converges to the target distribution. There are several purposed ideas but let's investigate the Gelman and Rubin Method.
The Gelman and Rubin Method (G&R) is based on multiple chains running at the same time. The starting points are chosen to be distant apart. When the characteristic of these chain i.e. the mean converge to about the same value, let's say it's about time to stop.
The idea of G&R method includes the between-sequence and within-sequence variances. The two variances is then used to calculated a factor, called "estimated potential scale reduction" $\hat R$.
The chains should continue to run if $\hat R$ is still high, until it is going below 1.1 or 1.2.
Example 14.9 of Computational Statistics Handbook with MATLAB shows the use of csgelrub() function for 4 MCMC (Metropolis-Hasting) chains. The characteristic is the mean of each chain. After the chain stopped, we can check the results as
>> nu(:,end)
ans =
0.0248
-0.0574
0.0318
-0.0196
>> rhat(end)
ans =
1.0073
The Gelman and Rubin Method (G&R) is based on multiple chains running at the same time. The starting points are chosen to be distant apart. When the characteristic of these chain i.e. the mean converge to about the same value, let's say it's about time to stop.
The idea of G&R method includes the between-sequence and within-sequence variances. The two variances is then used to calculated a factor, called "estimated potential scale reduction" $\hat R$.
The chains should continue to run if $\hat R$ is still high, until it is going below 1.1 or 1.2.
Example 14.9 of Computational Statistics Handbook with MATLAB shows the use of csgelrub() function for 4 MCMC (Metropolis-Hasting) chains. The characteristic is the mean of each chain. After the chain stopped, we can check the results as
>> nu(:,end)
ans =
0.0248
-0.0574
0.0318
-0.0196
>> rhat(end)
ans =
1.0073
Subscribe to:
Posts (Atom)






