[R] Regression Problem for loop

From: ales grill <alesgrill_at_gmail.com>
Date: Thu, 27 Nov 2008 10:03:44 +0100


Dear all,

                 I have wrote a code for a linear regression. I want to
write a loop for so, that I can get estimate for pavlues for six predictors. But I am getting for estmate for only last one. How can I get pvalues for all my predictors in a loop??

Anticipating your help
Thanks
Ales

> mat<-matrix(rnorm(36),nrow=6)
> mat

            [,1]              [,2]           [,3]               [,4]
   [,5]            [,6]
[1,]  1.10536338 -0.7613770 -1.7100569 -1.8762241 -0.36579280  0.6465219
[2,] -1.34836804 -0.2174270 -0.1153477 -0.1727683 -1.88406206  1.7484955
[3,]  0.96814418 -2.1483727  0.5839668 -1.2361659  0.04592844  1.9937995
[4,]  0.01960219 -1.2339691  0.8290761  0.1002795 -0.15952881  0.3969251
[5,] 1.62343073 1.3741222 -1.2045854 0.4180127 -0.09898615 1.3575119 [6,] -0.95260509 -0.1522824 -1.4257526 1.0057412 -1.20068336 -0.4306761
> res<-rnorm(6)
> res

[1] 0.2045252 -0.9824761 0.7727004 0.6439993 1.8005737 1.0167214
>
> pval<-NULL
>
> for(i in c(1:6))
+ {
+ reg<-lm(res~mat[,i])
+ reg
+ pval[i]<-reg$p.value
+ }

> pval

NULL
> reg

Call:
lm(formula = res ~ mat[, i])
Coefficients:

(Intercept)     mat[, i]
     0.8195      -0.2557

	[[alternative HTML version deleted]]

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu 27 Nov 2008 - 09:27:07 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 27 Nov 2008 - 21:30:27 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive