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.
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.
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
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 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.