Description Usage Arguments Details Value Note Author(s) Examples
Takes regression effect estimates and the corresponding standard errors, transforms to "human scale" if requested, calculates confidence-intervals and p-values, and exports a standard formatted summary table to a spreadsheet.
1 2 3 4 |
wb |
a |
sheet |
numeric or character: a worksheet name (character) or position (numeric) within |
betas |
numeric: a vector of point estimates, or a matrix containing estimates and standard errors in columns |
SE |
numeric: a vector of standard-error estimates for the effects. If |
varnames |
character: a vector of effect names (column 1 of output table). If |
colid |
integer: vector of indices for the columns containing the point estimates and SEs, respectively. Used only if |
transfun |
transformation function for |
title |
character: an optional overall title to the table. Default ( |
effname |
character: a string explaining what the effect stands for, e.g. "difference" (the default), "Odds Ratio", etc. |
alpha |
numeric, Type I error for CIs. Default 0.05 for 95% CIs. |
df |
numeric, residual degrees of freedom. If a finite value is provided, t-distribution p-value and CIs will be calculated; otherwise Normality is assumed. Default |
roundig |
numeric: how many digits (after the decimal point) to round the effect estimate to? |
pround |
numeric: how many digits (after the decimal point) to round the p-value to? P-values rounded down to zero will show up as "<" the smallest nonzero value, e.g. with the default |
row1, col1 |
numeric: the first row and column occupied by the table (title included if relevant). |
purge |
logical: should |
This function produces a standard scientific-article regression summary table, given the raw regression output. The resulting table has 4 columns: effect name, its (optionally transformed) magnitude, a probabilistically symmetric confidence interval (likewise transformed), and p-value. The formatted table is exported to sheet, and the file is immediately saved.
The input can be provided as separate vectors of point estimates (betas) and standard errors (SE), or as a single matrix for betas. In the latter case, as a default the effect names will be rownames(betas), unless a vector with more descriptive names is provided via varnames.
See the XLtwoWay help page, for behavior regarding new-sheet creation, overwriting, etc.
The function returns invisibly, after writing the data into sheet.
The default CI's are 95% and Normal. P-values are also derived from the Normal. If you run any regression whose intervals are calculated differently (e.g., linear regression with not-huge sample size), make sure to change both confac and pfun accordingly, as is shown in the example.
Assaf P. Oron <assaf.oron.at.seattlechildrens.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | book4<-XLwriteOpen("attenu.xls")
quakenames=c("Magnitude (Richter), per unit","Distance (log km), per x10")
# Ground acceleration as a function of magnitude and distance, all log scale.
quakemod1=summary(lm(log10(accel)~mag+log10(dist),data=attenu))
## Model-scale summaries; we don't care for the intercept.
# First (wrongly) using Normal distribution for inference/CIs
XLregresSummary(book4,"ModelScale",varnames=quakenames,
betas=quakemod1$coef[-1,1],SE=quakemod1$coef[-1,2],
,title="Log-Ground Acceleration Effects, Normal CIs")
# Now using t-distribution as befits linear regression
XLregresSummary(book4,"ModelScale",varnames=quakenames,
betas=quakemod1$coef[-1,1],SE=quakemod1$coef[-1,2],
,title="Log-Ground Acceleration Effects",df=quakemod1$df[2],col1=6)
## Same thing, but using matrix input; no need to provide SE and names.
## It is arguably still nicer to provide your own names - but could be a reproducibility risk.
## Also, increasing the p-value resolution by changing 'pround'.
XLregresSummary(book4,"ModelScale",betas=quakemod1$coef[-1,],
pround=6,title="Log-Ground Acceleration Effects",
,df=quakemod1$df[2],row1=8)
## Effects are arguably more meaningful as percent change.
## So... still same model, but different summaries.
## Also, note the combination of matrix input with names over-written via 'varnames':
XLregresSummary(book4,"PercentChange",varnames=quakenames,
betas=quakemod1$coef[-1,],
roundig=1,pround=6,title="Relative Ground Acceleration Effects",
transfun=function(x) 100*(10^x-1),
effname="Percent Change",df=quakemod1$df[2])
cat("Look for",paste(getwd(),"attenu.xls",sep='/'),"to see the results!\n")
### lm() does not take account of station or event level grouping.
### So we use a mixed model, losing 16 data points w/no station data:
### Run this on your own... and ask the authors of "lme4" about p-values at your own risk :)
# library(lme4)
# quakemod2=lmer(log10(accel)~mag+log10(dist)+(1|event)+(1|station),data=attenu)
#
# XLregresSummary(book4,"MixedModel",varnames=quakenames,betas=fixef(quakemod2)[-1],
# SE=sqrt(diag(vcov(quakemod2)))[-1],
# roundig=1,pround=6,
# title="Relative Ground Acceleration Effects",
# transfun=function(x) 100*(10^x-1),effname="Percent Change",df=160)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.