How to obtain trend p-values for each cell of a matrix?

조회 수: 5 (최근 30일)
Anna
Anna 2013년 4월 11일
Hello,
I am trying to output the regression p-values for each cell separately. I've successfully calculated the regression coefficients for each cell using polyfit:
for i=1:695
for j=1:822
summer_trend(1:2,i,j)=polyfit(year,summer(:,i,j),1);
end
end
However, I would now like to obtain the p-values for the coefficients cell-by-cell. Normally, I would use regstats and select tstat.pval but I'm not sure how to apply this over a matrix. I've tried for example the following code but the problem I have is the functions I've found always return a structure (which is no good when I have a matrix instead of vector...):
for i=1:695
for j=1:822
summer_pval=regstats(summer(:,i,j),year, 'linear',{'tstat'});
end
end
Any ideas how I could do this? Many thanks!

답변 (1개)

Tom Lane
Tom Lane 2013년 4월 12일
You are right that regstats returns a structure, but it contains numeric values that you can assign into a matrix. For example, something like this:
s = regstats(pop,cdate,'linear');
coefmat(1:2,1) = s.tstat.beta;
pvalmat(1:2,1) = s.tstat.pval;
  댓글 수: 2
Anna
Anna 2013년 4월 12일
Hi Tom, Thanks for your reply. However, I'm still not sure how to apply this over a matrix. I can't use my [695X822] matrix as the y input of regstats(y,x), as in your example, as that returns the error "RESPONSES must have a single column".
The loop above that I tried using on the other hand returns the error "The design matrix has more predictor variables than observations".
Would you be able to explain how this can be done cell-by-cell using a matrix (as opposed to a vector column) as the y variable? Thanks
Tom Lane
Tom Lane 2013년 4월 13일
I had in mind this modification of your code:
for i=1:695
for j=1:822
s = regstats(summer(:,i,j),year);
summer_trend(1:2,i,j) = s.tstat.beta;
summer_pval(1:2,i,j) = s.tstat.pval;
end
end

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by