R summary Function


summary() function is a generic function used to produce result summaries of the results of various model fitting functions. The function invokes particular methods which depend on the class of the first argument.

summary(object, ...)
## Default S3 method:
summary(object, ..., digits = max(3, getOption("digits")-3))
## S3 method for class 'data.frame'
summary(object, maxsum = 7,
digits = max(3, getOption("digits")-3), ...)
## S3 method for class 'factor'
summary(object, maxsum = 100, ...)
## S3 method for class 'matrix'
summary(object, ...)


object: R object
maxsum: interger, indicating how many levels should be shown for factors
digits: integer, used for number formatting with signif() (for summary.default) or format() (for summary.data.frame)

> x <- c("green","red","blue")
> summary(x)

Length Class Mode
3 character character

Let summary a factor:

> state.region
 [1] South         West          West          South         West
[6] West          Northeast     South         South         South
[11] West          West          North Central North Central North Central
[16] North Central South         South         Northeast     South
[21] Northeast     North Central North Central South         North Central
[26] West          North Central West          Northeast     Northeast
[31] West          Northeast     South         North Central North Central
[36] South         West          Northeast     Northeast     South
[41] North Central South         South         West          Northeast
[46] South         West          South         North Central West
Levels: Northeast South North Central West
> summary(state.region)
    Northeast         South North Central          West
9            16            12            13
> summary(state.region, maxsum=2)
  South (Other)
16      34


Summary a data.frame:

> summary(BOD)

Time demand
Min. :1.000 Min. : 8.30
1st Qu.:2.250 1st Qu.:11.62
Median :3.500 Median :15.80
Mean :3.667 Mean :14.83
3rd Qu.:4.750 3rd Qu.:18.25
Max. :7.000 Max. :19.80

summary() is widely used to check statistics analysis results:

>x <- c(rep(1:20))
>y <- x * 2
>f <- lm(x ~ y)
>f
Call:
lm(formula = x ~ y)
Coefficients:
(Intercept) y
-4.766e-15 5.000e-01
>summary(f)

Call:
lm(formula = x ~ y)
Residuals:
Min 1Q Median 3Q Max
-6.208e-15 8.400e-18 3.526e-16 6.074e-16 2.038e-15
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -4.766e-15 7.696e-16 -6.193e+00 7.6e-06 ***
y 5.000e-01 3.212e-17 1.557e+16 < 2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 1.657e-15 on 18 degrees of freedom
Multiple R-squared: 1, Adjusted R-squared: 1
F-statistic: 2.423e+32 on 1 and 18 DF, p-value: < 2.2e-16


Summary large data set:

> x <- stats::rnorm(100)
> x
[1] -0.154103462 0.271704132 -0.234160855 0.764474679 0.438237645
[6] -0.763854668 1.303402711 0.051660328 1.064258570 0.079144697
...
> c <- cut(x,breaks=-5:5)
> c
[1] (-1,0] (0,1] (-1,0] (0,1] (0,1] (-1,0] (1,2] (0,1] (1,2]
[10] (0,1] (-1,0] (2,3] (-1,0] (0,1] (-1,0] (0,1] (0,1] (-1,0]
...
> summary(c)
c
(-5,-4] (-4,-3] (-3,-2] (-2,-1] (-1,0] (0,1] (1,2] (2,3] (3,4] (4,5]
0 0 2 14 35 38 10 1 0 0


endmemo.com © 2024  | Terms of Use | Privacy | Home