[R] Regression Problem for loop

David Winsemius dwinsemius at comcast.net
Thu Nov 27 15:49:12 CET 2008


Have you looked at results of str on a regression object? I would not  
think that there would be a single p.value associated with such a  
beast, but that there might be if you examined individual coefficients.

? coefficients
?coef

-- 
David Winsemius

On Nov 27, 2008, at 4:03 AM, ales grill wrote:

> 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.



More information about the R-help mailing list