T test p values for regression coefficients

10 ビュー (過去 30 日間)
Shahid
Shahid 2013 年 6 月 1 日
Hi. I am trying to fit a linear model Y= m*X. I wanted to get T test p values for individual regression coefficients. I have seen that the function regstat does provide the T test p values. The problem is that while performing regression , regstat adds a column of ones by itself to the feature set (X). I do not plan to include the column of ones as my model is simple Y=m*X instead of Y=m*X + c. Is there any way or any function I could use to compute the T test p values without including a column of ones in the feature set.
Thanks

採用された回答

Shahid
Shahid 2013 年 6 月 30 日
Hi. So I found a solution. There is this library posted by someone http://www.mathworks.com/matlabcentral/fileexchange/26169-regstats2
It is an improved version of original regstats function in matlab and also allows p values of coefficient for regression with intercept term.

その他の回答 (3 件)

Tom Lane
Tom Lane 2013 年 6 月 1 日
If you look at "help regstats" you will see that the default model is 'linear' and this includes the constant. But you will also see that there's a way to specify the terms you want directly. An identity matrix will provide what you need. Admittedly this is obscure, but try this:
>> x = rand(20,3);
>> y = x*[1;-2;3] + randn(20,1)/100;
>> s = regstats(y,x,'linear'); s.beta'
ans =
0.0117 0.9907 -2.0019 2.9866
>> s = regstats(y,x,eye(3)); s.beta'
ans =
0.9982 -1.9984 2.9977
I show the coefficient estimates, but the t statistics and p-values are in there as well.
If you have a recent release of MATLAB, consider
LinearModel.fit(x,y,'Intercept',false)

the cyclist
the cyclist 2013 年 6 月 1 日
I believe you could use the function nlinfit() from the Statistics Toolbox to do this.
Here is an example of the function:
rng(1)
% Here is an example of using nlinfit(). For simplicity, none of
% of the fitted parameters are actually nonlinear!
% Define the data to be fit
x=(0:1:10)'; % Explanatory variable
y = 5 + 3*x + 7*x.^2; % Response variable (if response were perfect)
y = y + 2*randn((size(x)));% Add some noise to response variable
% Define function that will be used to fit data
% (F is a vector of fitting parameters)
f = @(F,x) F(1) + F(2).*x + F(3).*x.^2;
F_fitted = nlinfit(x,y,f,[1 1 1]);
% Display fitted coefficients
disp(['F = ',num2str(F_fitted)])
% Plot the data and fit
figure
plot(x,y,'*',x,f(F_fitted,x),'g');
legend('data','fit')
My example only uses one explanatory variable, and does have an intercept term, but you should be able to adapt it to your model.

Shahid
Shahid 2013 年 6 月 1 日
Hi. Thanks for the answer. I actually am interested in getting the t-test P values of the coefficients as returned by REGSTATS function in form of stats.tstat
  1 件のコメント
the cyclist
the cyclist 2013 年 6 月 1 日
For your future reference, this "answer" would have been better placed as a comment on my answer.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeModel Building and Assessment についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by