T test p values for regression coefficients
Show older comments
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
Accepted Answer
More Answers (3)
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
LinearModel.fit(x,y,'Intercept',false)
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:
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
on 1 Jun 2013
0 votes
1 Comment
the cyclist
on 1 Jun 2013
For your future reference, this "answer" would have been better placed as a comment on my answer.
Categories
Find more on Support Vector Machine Regression in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!