MATLAB Answers


T test p values for regression coefficients

Asked by Shahid
on 1 Jun 2013

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.




No products are associated with this question.

4 Answers

Answer by Shahid
on 30 Jun 2013
 Accepted answer

Hi. So I found a solution. There is this library posted by someone

It is an improved version of original regstats function in matlab and also allows p values of coefficient for regression with intercept term.


Answer by Tom Lane
on 1 Jun 2013

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,y,'Intercept',false)


Answer by the cyclist
on 1 Jun 2013

I believe you could use the function nlinfit() from the Statistics Toolbox to do this.

Here is an example of the function:

% 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

My example only uses one explanatory variable, and does have an intercept term, but you should be able to adapt it to your model.


Answer by Shahid
on 1 Jun 2013

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 Comment

For your future reference, this "answer" would have been better placed as a comment on my answer.

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!