How to find the row wise p values corresponding to each coefficient of linear regression?
Afficher commentaires plus anciens
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 commentaires
Jeff Miller
le 16 Juin 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
le 17 Juin 2022
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Descriptive Statistics and Insights dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!