zhijie zhang
2006-Aug-20 06:46 UTC
[R] how to the p-values or t-values from the lm's results
Dear friends,
After running the lm() model, we can get summary resluts like the
following:
Coefficients:
Estimate Std. Error t value Pr(>|t|)
x1 0.11562 0.10994 1.052 0.2957
x2 -0.13879 0.09674 -1.435 0.1548
x3 0.01051 0.09862 0.107 0.9153
x4 0.14183 0.08471 1.674 0.0975 .
x5 0.18995 0.10482 1.812 0.0732 .
x6 0.24832 0.10059 2.469 0.0154 *
x7 -0.04425 0.11008 -0.402 0.6886
x8 0.05146 0.10290 0.500 0.6182
-------------------------------------------------------------
**the program maybe :
data<-matrix(rnorm(900),ncol=9) #9variables,1dependent var,8independent
data<-data.frame(data)
names(data)<-c('y','x1','x2','x3','x4','x5','x6','x7','x8')
logr<-lm(y~x1+x2+x3+x4+x5+x6+x7+x8-1,data)
a<-summary(logr)
------------------------------------------------------------------------------------------------------------------------
Could i extract the p-values or t-values from the a$Coefficients, i searched
the attributes(a), but don't find the options,how to do that?
Thanks very much!
--
Kind Regards,
Zhi Jie,Zhang ,
[[alternative HTML version deleted]]
Sean O'Riordain
2006-Aug-20 07:34 UTC
[R] how to the p-values or t-values from the lm's results
Hi there Zhang, While there might be a better way... an ugly but generic way of accessing this type of information is to use str() and a little experimentation... here is a little history() of what I did to find it... a str(a) str(logr) a[[1]] a[[2]] a[[3]] a[[4]] a[[4]][[1]] a[[4]][1,] a[[4]][,4] and hey presto... we have it... :-) now if I actually understood what was going on here I'd probably be faster... but it is pretty generic and you can almost always get at those things using this technique... no doubt somebody with more knowledge will explain why it works :-) cheers, Sean On 20/08/06, zhijie zhang <epistat at gmail.com> wrote:> Dear friends, > After running the lm() model, we can get summary resluts like the > following: > Coefficients: > Estimate Std. Error t value Pr(>|t|) > x1 0.11562 0.10994 1.052 0.2957 > x2 -0.13879 0.09674 -1.435 0.1548 > x3 0.01051 0.09862 0.107 0.9153 > x4 0.14183 0.08471 1.674 0.0975 . > x5 0.18995 0.10482 1.812 0.0732 . > x6 0.24832 0.10059 2.469 0.0154 * > x7 -0.04425 0.11008 -0.402 0.6886 > x8 0.05146 0.10290 0.500 0.6182 > ------------------------------------------------------------- > **the program maybe : > data<-matrix(rnorm(900),ncol=9) #9variables,1dependent var,8independent > data<-data.frame(data) > names(data)<-c('y','x1','x2','x3','x4','x5','x6','x7','x8') > logr<-lm(y~x1+x2+x3+x4+x5+x6+x7+x8-1,data) > a<-summary(logr) > ------------------------------------------------------------------------------------------------------------------------ > Could i extract the p-values or t-values from the a$Coefficients, i searched > the attributes(a), but don't find the options,how to do that? > Thanks very much! > > -- > Kind Regards, > Zhi Jie,Zhang , > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >
Dimitrios Rizopoulos
2006-Aug-20 08:34 UTC
[R] how to the p-values or t-values from the lm's results
try the following:
data <- data.frame(matrix(rnorm(900), ncol = 9))
names(data) <- c("y", paste("x", 1:8, sep =
""))
logr <- lm(y ~ . - 1, data)
a <- summary(logr)
coef(a)
coef(a)[, 3:4]
coef(a)[, "t value"]
coef(a)[, "Pr(>|t|)"]
I hope it helps.
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm
Quoting zhijie zhang <epistat at gmail.com>:
> Dear friends,
> After running the lm() model, we can get summary resluts like the
> following:
> Coefficients:
> Estimate Std. Error t value Pr(>|t|)
> x1 0.11562 0.10994 1.052 0.2957
> x2 -0.13879 0.09674 -1.435 0.1548
> x3 0.01051 0.09862 0.107 0.9153
> x4 0.14183 0.08471 1.674 0.0975 .
> x5 0.18995 0.10482 1.812 0.0732 .
> x6 0.24832 0.10059 2.469 0.0154 *
> x7 -0.04425 0.11008 -0.402 0.6886
> x8 0.05146 0.10290 0.500 0.6182
> -------------------------------------------------------------
> **the program maybe :
> data<-matrix(rnorm(900),ncol=9) #9variables,1dependent var,8independent
> data<-data.frame(data)
>
names(data)<-c('y','x1','x2','x3','x4','x5','x6','x7','x8')
> logr<-lm(y~x1+x2+x3+x4+x5+x6+x7+x8-1,data)
> a<-summary(logr)
>
------------------------------------------------------------------------------------------------------------------------
> Could i extract the p-values or t-values from the a$Coefficients, i
searched
> the attributes(a), but don't find the options,how to do that?
> Thanks very much!
>
> --
> Kind Regards,
> Zhi Jie,Zhang ,
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>
>
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm