On Nov 27, 2008, at 9:49 AM, David Winsemius wrote:

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

That wasn't on as on point as I thought. Take a look at this screen dialog:

> x <- 1:5; coef(lm(c(1:3,7,6) ~ x))
(Intercept)           x
       -0.7         1.5

> str(coef(lm(c(1:3,7,6) ~ x)))
 Named num [1:2] -0.7 1.5
 - attr(*, "names")= chr [1:2] "(Intercept)" "x"
> anova(lm(c(1:3,7,6) ~ x))
Analysis of Variance Table

Response: c(1:3, 7, 6)
          Df  Sum Sq Mean Sq F value  Pr(>F)
x          1 22.5000 22.5000  15.698 0.02872 *
Residuals  3  4.3000  1.4333
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> str(anova(lm(c(1:3,7,6) ~ x)))
Classes ‘anova’ and 'data.frame':       2 obs. of  5 variables:
 $ Df     : int  1 3
 $ Sum Sq : num  22.5 4.3
 $ Mean Sq: num  22.5 1.43
 $ F value: num  15.7 NA
 $ Pr(>F) : num  0.0287 NA
- attr(*, "heading")= chr "Analysis of Variance Table\n" "Response: c(1:3, 7, 6)"
> anova(lm(c(1:3,7,6) ~ x))$"Pr(>F)"
[1] 0.02871561         NA
> anova(lm(c(1:3,7,6) ~ x))$"Pr(>F)"[1]
[1] 0.02871561



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

______________________________________________
R-help@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.

______________________________________________
R-help@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.

Reply via email to