How to find the row wise p values corresponding to each coefficient of linear regression?
이전 댓글 표시
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
Jeff Miller
2022년 6월 16일
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
2022년 6월 17일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Descriptive Statistics and Insights에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!