Skip to contents

rockchalk::summarize does the numerical calculations

Usage

descriptiveTable(
  object,
  stats = c("mean", "sd", "min", "max"),
  digits = 4,
  probs = c(0, 0.5, 1),
  varLabels,
  ...
)

Arguments

object

A fitted regression or an R data.frame, or any other object type that does not fail in codemodel.frame(object).

stats

Default is a vector c("mean", "sd", "min", "max"). Other stats reported by rockchalk::summarize should work fine as well

digits

2 decimal points is default

probs

Probability cut points to be used in the calculation of summaries of numeric variables. Default is c(0, 0.5, 1), meaning min, median, max.

varLabels

A named vector of variables labels, as in outreg function. Format is c("oldname"="newlabel").

...

Other arguments passed to rockchalk::summarizeNumerics and summarizeFactors.

Value

a character matrix

Details

This is, roughly speaking, doing the right thing, but not in a clever way. For the categorical variables, the only summary is proportions.

Author

Paul Johnson pauljohn@ku.edu

Examples

dat <- genCorrelatedData2(1000, means=c(10, 10, 10), sds = 3, 
                          stde = 3, beta = c(1, 1, -1, 0.5))
#> [1] "The equation that was calculated was"
#> y = 1 + 1*x1 + -1*x2 + 0.5*x3 
#>  + 0*x1*x1 + 0*x2*x1 + 0*x3*x1 
#>  + 0*x1*x2 + 0*x2*x2 + 0*x3*x2 
#>  + 0*x1*x3 + 0*x2*x3 + 0*x3*x3 
#>  + N(0,3) random error 
dat$xcat1 <- factor(sample(c("a", "b", "c", "d"), 1000, replace=TRUE))
dat$xcat2 <- factor(sample(c("M", "F"), 1000, replace=TRUE), levels = c("M", "F"),
labels = c("Male", "Female"))
dat$y <- dat$y + contrasts(dat$xcat1)[dat$xcat1, ] %*% c(0.1, 0.2, 0.3)
m4 <- lm(y ~ x1 + x2  + x3 + xcat1 + xcat2, dat)
m4.desc <- descriptiveTable(m4)
m4.desc
#>    variable  mean    sd    min   max
#> 1         y 6.387 5.388 -10.16 26.43
#> 2        x1 10.09 2.974  1.136 19.93
#> 3        x2 9.911 2.969 0.7742 19.65
#> 4        x3 9.988 2.906 0.4451 19.18
#> 5     xcat1                         
#> 6         a 0.245                   
#> 7         b 0.241                   
#> 8         c 0.252                   
#> 9         d 0.262                   
#> 10    xcat2                         
#> 11     Male 0.478                   
#> 12   Female 0.522                   
## Following may cause scientific notation, want to avoid.
dat <- genCorrelatedData2(1000, means=c(10, 100, 400), 
                 sds = c(3, 10, 20), stde = 3, beta = c(1, 1, -1, 0.5))
#> [1] "The equation that was calculated was"
#> y = 1 + 1*x1 + -1*x2 + 0.5*x3 
#>  + 0*x1*x1 + 0*x2*x1 + 0*x3*x1 
#>  + 0*x1*x2 + 0*x2*x2 + 0*x3*x2 
#>  + 0*x1*x3 + 0*x2*x3 + 0*x3*x3 
#>  + N(0,3) random error 
m5 <- lm(y ~ x1 + x2  + x3, dat)
m5.desc <- descriptiveTable(m5, digits = 4)
m5.desc
#>    variable  mean    sd    min   max
#> y         y 110.7 15.53  63.86 154.4
#> x1       x1 10.15 3.028 -0.182  19.1
#> x2       x2 100.4 10.31  68.54   134
#> x3       x3 400.1 20.55  334.3 461.2