How to find the row wise p values corresponding to each coefficient of linear regression?
Show older comments
I have 3 matrices Y, x1, and x2 each having 3420 rows and 29 columns. I want the row wise linear regression p values of Y on x1, x2, and the interaction between x1 and x2 such that the p value term for each of them is of 3420 rows and 1 column.
I tried the following code:
nsample = 29;
nvar = 3420;
% sample data
y = rand(nsample, nvar);
x1 = rand(nsample, nvar);
x2 = rand(nsample, nvar);
xInt = x1.*x2;
intercept = ones(nsample, 1);
beta = zeros(nvar, 4);
for i = 1:nvar
desMat = [intercept, x1(:, i), x2(:, i), xInt(:, i)];
beta(i, :) = regress(y(:, i), desMat);
end
But beta only gives the linear regression coefficients. I want the p values.
How to get the p values corresponding to the linear regression coefficients of Y on x1, x2, and interaction between x1, x2 as a 3420 rows and 1 column array?
2 Comments
Jeff Miller
on 16 Jun 2022
Do you want the p value of each predictor based on its Type I, II, or III sum of squares (e.g., intro to sums of squares types)?
Abhishek Chakraborty
on 17 Jun 2022
Accepted Answer
More Answers (0)
Categories
Find more on Descriptive Statistics and Insights 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!