Tuesday, June 1, 2010

Monte Carlo Hypothesis Testing (P-Value)

Instead of finding the critical value from the simulated distribution of the test statistics, we use samples to calculate the p-value.

load mcdata;
n=length(mcdata);
sigma=7.8;
M=1000; % number of Monte Carlo trials
 
%start simulation to get sample
Tm = zeros(1,M);
for i=1:M
    xs = sigma*randn(1,n)+454;
    Tm(i)=mean(xs);
end
tobs = mean(mcdata);
ind=find(Tm <= tobs);
pvalhat=length(ind)/M


>> mcp_hypotest

pvalhat =

    0.0060


If the significant level $\alpha=0.05$, this estimated p-value is less than the $\alpha$. We would reject the H0.

No comments:

Post a Comment