Tino Schöllhorn
2010-May-13 16:58 UTC
[R] Help with reading information of "summary"-Object
Hi,
I am quite new to R - but quite expierience in programming. Nonetheless
I have some problemes in accessing information of the "summary"
object.
Here is what I do:
model <- lm ( y ~ myVariable )
"summary(model)" gives me an object which has a lot of information
about
the regression. Now I'd like to access programmatically the level of
significance which is marked with "***" and ("**") according
to its
confidence-interval. As I can access all information of the coefficients
via
summary(model)$coeff["myVariable"]
I am now struggling to access the information of the level of significance.
Does anyone has an idea how I could achieve that? Or where I could find
a similar example?
Thanks in advance for any hint,
Tino
--
Tino Sch?llhorn
Wittelsbachstr. 7
67061 Ludwigshafen
Tel: 0621-4255570
E-Mail: t.schoellhorn at gmx.de
Hello, Tino Sch?llhorn wrote:> Hi, > > I am quite new to R - but quite expierience in programming.Welcome to R! It's easiest if you give reproducible examples so we can help you. You can include code to create objects, or use the ?dput function.> Nonetheles > I have some problemes in accessing information of the "summary" object. > Here is what I do: > > model <- lm ( y ~ myVariable ) > > "summary(model)" gives me an object which has a lot of information about > the regression. Now I'd like to access programmatically the level of > significance which is marked with "***" and ("**") according to its > confidence-interval. As I can access all information of the coefficients > via > > summary(model)$coeff["myVariable"]Use the ?coef function for this.> > I am now struggling to access the information of the level of significance. > > Does anyone has an idea how I could achieve that? Or where I could find > a similar example? >In this case, you need to know one of the most important R functions, str, which tells you the structure of any object. This will let you know what is available in your objects. Assign your summary object to a variable, say summary.model, and then do: > str(coef(summary(model))) You can then get at the p.values through the usual indexing techniques, by name or by row, column numbering. From the statistical point of view, we're not sure what you're working on, but there are many considerations to take into account if you're using p-values from regression fits as some sort of screening tool.
Tino -
When you call summary for an lm object, the function
that actually gets called is "summary.lm". This function
has a help page, and, if you type
?summary.lm
and look at the "Value" section, you'll see the following:
coefficients: a p x 4 matrix with columns for the estimated
coefficient, its standard error, t-statistic and
corresponding (two-sided) p-value. Aliased coefficients are
omitted.
Here's an example of how you could extract the probabilities:
> set.seed(12)
> df = data.frame(y=rnorm(100),x1=rnorm(100),x2=rnorm(100))
> df.lm = lm(y~x1+x2,df)
> sdf.lm = summary(df.lm)
> sdf.lm$coefficients[,4]
(Intercept) x1 x2
0.7445605 0.8081874 0.2535098
or
> sdf.lm$coefficients[,"Pr(>|t|)"]
(Intercept) x1 x2
0.7445605 0.8081874 0.2535098
Hope this helps
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
spector at stat.berkeley.edu
On Thu, 13 May 2010, Tino Sch?llhorn wrote:
> Hi,
>
> I am quite new to R - but quite expierience in programming. Nonetheless I
> have some problemes in accessing information of the "summary"
object. Here is
> what I do:
>
> model <- lm ( y ~ myVariable )
>
> "summary(model)" gives me an object which has a lot of
information about the
> regression. Now I'd like to access programmatically the level of
significance
> which is marked with "***" and ("**") according to its
confidence-interval.
> As I can access all information of the coefficients via
>
> summary(model)$coeff["myVariable"]
>
> I am now struggling to access the information of the level of significance.
>
> Does anyone has an idea how I could achieve that? Or where I could find a
> similar example?
>
> Thanks in advance for any hint,
> Tino
>
> --
> Tino Sch?llhorn
> Wittelsbachstr. 7
> 67061 Ludwigshafen
>
> Tel: 0621-4255570
> E-Mail: t.schoellhorn at gmx.de
>
> ______________________________________________
> 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.
>