Monte Carlo hypothesis test

조회 수: 2 (최근 30일)
M Fernandes
M Fernandes 2017년 10월 27일
편집: M Fernandes 2017년 10월 28일
Dear Matlab users, I want to do a Monte Carlo simulation of a test of a nonlinear hypothesis, my null hypothesis is beta1*beta2=1. I am using the following code:
alpha=1;
beta1=0.5;
beta2=2;
n=100;
m=10;
beta1_hat=zeros(m,1);
for i=1:m
x1=randn(n,1);
x2=randn(n,1);
e=randn(n,1);
y=alpha+beta1*x1+beta2*x2+e;
end
[h,pvalue,ci]=ttest(beta1*beta2,1)
However, when I run the code, I obtain the following: h = NaN pvalue = NaN ci = NaN NaN
I used this code for the hypothesis testing, following this: https://www.mathworks.com/help/stats/hypothesis-testing.html . Another question that I have is why do they divide by 100 price2 in the ttest?
Thanks!
  댓글 수: 2
Brendan Hamm
Brendan Hamm 2017년 10월 27일
beta1*beta2 is a scalar and so is 1 and there are not enough samples to perform any hypothesis test. Are you trying to estimate the beta coefficients from the linear equation? If this is the case, then you likely want to be using y somewhere, which you currently aren't.
M Fernandes
M Fernandes 2017년 10월 27일
편집: M Fernandes 2017년 10월 28일
Thank you, Brendan Hamm for your answer.
What I want to do is, considering a multiple linear regression model, propose a test statistic to test the nonlinear hypothesis that the product of the slopes of two explanatory equals one (in the model y=β1+β2X2+β3X3+ε test the null hypothesis that H0: β2×β3=1).
I tried to rethink in my code:
beta1=1;
beta2=0.5;
beta3=2;
n=100;
m=1000;
beta_hat=zeros(m,1);
for i=1:m
x1=randn(n,1);
x2=randn(n,1);
e=randn(n,1);
y=beta1+beta2*x1+beta3*x2+e;
X1=[ones(n,1) x1];
beta_hatvec2=(inv(X1'*X1))*X1'*y;
X2=[ones(n,1) x2];
beta_hatvec3=(inv(X2'*X2))*X2'*y;
beta_hat2(i)=beta_hatvec2(2);
beta_hat3(i)=beta_hatvec3(2);
end
[h]=ttest(beta_hat2*beta_hat3,1)
But know Matlab tells me
"Error using *
Inner matrix dimensions must agree."

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Hypothesis Tests에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by