Chapter10
MakingTables
AH6
10.1 FrequencyTabulations
6.1
·
table
and
crosstabs
functions
10.2 Hmisc
summary.formula
Function
AH6.2
10.2.1 Introduction
The
summary.formula
function in Hmisc c is s used to o construct t statisticalsum-
maries ofa response variable ora matrix ofresponse variables stratified by
avarietyofothervariables.
summary.formula
canbeusedtomakeavarietyofnon-simpletables.
93
Convert pdf file to powerpoint online - application SDK tool:C# Create PDF from PowerPoint Library to convert pptx, ppt to PDF in C#.net, ASP.NET MVC, WinForms, WPF
Online C# Tutorial for Creating PDF from Microsoft PowerPoint Presentation
www.rasteredge.com
Convert pdf file to powerpoint online - application SDK tool:VB.NET Create PDF from PowerPoint Library to convert pptx, ppt to PDF in vb.net, ASP.NET MVC, WinForms, WPF
VB.NET Tutorial for Export PDF file from Microsoft Office PowerPoint
www.rasteredge.com
CHAPTER10. MAKINGTABLES
94
SFormulaLanguage
·
Wesawanexampleofusingastatisticalformulaasanargumenttotella
functionwhichdatatoprocess,insteadofavector,matrix,ordataframe—
spearman2
·
Usuallyastatisticalmodelorformulahastheform
response ∼ ∼ predictor1 1 + predictor2 2 + + ...
wherearesponsevariableistotheleftof
andoneormorepredictorsor
independentvariablesareontheright
·
Thepredictorssometimesconstitutestratificationvariables
·
Forregressionmodelsmoresyntaxisavailable;weignorethatforthiscourse
·
AnySfunctionwithaformulaasthefirstargumentallows
– a
data=
argumenttospecifyadataframetoanalyze
– a
subset=
to specifyalogicalexpressiondefiningwhichsubsetofthe
datatoprocess
Variablesinsidethisexpressioncanbeinsidethedataframepointedto
in
data
without
attach
ingthedataframe
ObjectOrientedFeaturesofSUsed
·
InS
summary
isagenericfunction
summary(vector)
producesdescriptivestatssimilarto
describe
forasin-
glevariable
summary(dataframe)
calls
summary.data.frame
to repeat the e calcula-
tionsforonevariableseparatelyforallvariablesinthethedataframe
application SDK tool:Online Convert PowerPoint to PDF file. Best free online export
Online Powerpoint to PDF Converter. Download Free Trial. Convert a PPTX/PPT File to PDF. Just upload your file by clicking on the blue
www.rasteredge.com
application SDK tool:C# HTML5 PDF Viewer SDK to convert and export PDF document to
Create PDF from PowerPoint. Create PDF from Tiff. Create PDF from Convert PDF to Png, Gif, Bitmap Images. File and Page Process. File: Merge, Append PDF Files. File
www.rasteredge.com
CHAPTER10. MAKINGTABLES
95
summary(regression.result)
summarizestheresultoffittingaregres-
sionmodel
·
summary(formula)
calls
summary.formula
·
summary.formula
getsthedataforallthevariablesnamedintheformula,
looksatoptionalarguments,anddoesthecalculations
·
summary.formula
createsanobjectwithaclassof
summary.formula.subclass
wherethevalueof
subclass
dependsonoptionsthatarepassedto
summary
,
as
summary.formula
createsthreedrasticallydifferenttypesofoutput
·
Theoutputcanberenderedusing
print
,
plot
,and
latex
methods
TypicalSequenceofCommands
attach(mydata)
s ← ← summary(response ∼ ∼ x1 1 + + x2 2 + + x3, options)
s
# invokes s print.summary.formula.subclass
print(s, options)
# to o print with non-default t options
plot(s, options)
# invokes s plot.summary.formula.subclass
latex(s, options)
# invokes s latex.summary.formula.subclass
# to o create e LaTeX code to make tables
s ← ← summary(formula, data=mydata)
# use e data= = if f don’t attach
print(s, options)
...
SpecifyingWhichSummaryStatisticstoCompute
·
Fortwoofthethreetypesofsummaries
summary.formula
candoyoucan
specifyanargument
fun
thatcontainsthedefinitionofafunctionthatcom-
putesoneoravectorofsummarystatistics.Thefunctiononlyneedcompute
itsresultsforasinglestratum.
application SDK tool:VB.NET PDF - Convert PDF Online with VB.NET HTML5 PDF Viewer
Create PDF from Excel. Create PDF from PowerPoint. Create PDF to Text. Convert PDF to JPEG. Convert PDF to Png Images. File & Page Process. File: Merge, Append PDF
www.rasteredge.com
application SDK tool:VB.NET PDF File Compress Library: Compress reduce PDF size in vb.
Convert smooth lines to curves. Detect and merge image fragments. Flatten visible layers. VB.NET Demo Code to Optimize An Exist PDF File in Visual C#.NET Project
www.rasteredge.com
CHAPTER10. MAKINGTABLES
96
·
NotetheinconsistencywithbuiltinSfunctionssuchas
tapply
whichuse
FUN
forthispurposeinsteadof
fun
·
Numberofnon-missingandmissingobservationsineachstratumarecom-
putedautomaticallyoutside
fun
·
Thedefaultcomputationisthemean(equivalenttosaying
fun=mean
)
a
·
summary.formula
removes
NA
sbeforeinvokingthisfunction,so
na.rm=T
is
notneeded
·
Specify
fun=median
tocomputethemedianresponseforeachstratum
·
Specify
fun=quantile
tocomputea5-numbersummary
·
Specify
fun=function(x) c(Mean=mean(x), Median=median(x))
tocomputeboththemeanandthemedian,andlabelthem
·
Possibilitiesarelimitlessonceyoulearnhowtowritesimplefunctions
·
Byspecifyingamatrixfortheresponsevariableyoucancomputecomplex
multivariatesummariesandallowforcensoreddata
·
Oftenwespecifyasthe
fun
argumentto
summary.formula
oneofthefunc-
tionsdescribedinSection9.1.2suchas
smean.cl.boot
or
smean.sd
a
Well,notexactly,asthedefaultcancomputethemeanofeachcolumnofamultivariate(matrix)responseseparately.
application SDK tool:C# PDF File Split Library: Split, seperate PDF into multiple files
SharePoint. C#.NET control for splitting PDF file into two or multiple files online. Support to break a large PDF file into smaller files.
www.rasteredge.com
application SDK tool:VB.NET PDF File Merge Library: Merge, append PDF files in vb.net
Merge Microsoft Office Word, Excel and PowerPoint data to PDF Append one PDF file to the end of another one in VB library download and VB.NET online source code
www.rasteredge.com
CHAPTER10. MAKINGTABLES
97
10.2.2 AutomaticStratificationofContinuousVariables
·
Whenuseacontinuousvariableasastratificationvariablewillautomatically
categorizethevariableintoquantileintervalsusing
cut2
·
Defaultisquartiles
·
Canspecify optional argument
g=k
to
summary.formula
touse
k
quantile
intervals
·
Thevalueof
g
isusedforallcontinuousstratifiers
·
Usercancontrolintervalsbyusing
cut2
onvariablesintheformula:
summary(y ∼ ∼ cut2(weight, g=5) + + cut2(pressure, g=4) +
cut2(age, c(21,65)))
Thiscut
weight
intoquintiles,
pressure
intoquartiles,and
age
into
age<21
,
21≤age<65
,
age≥65
10.2.3 ThreeTypesofSummarieswith
summary.formula
ResponseSummaries
·
Thedefault
·
Computesoneormoredescriptivestatisticsoftheresponsevariablestrati-
fied separatelybylevelsofindependentvariables
·
Forthistypeofsummaryyoucansurroundoneormoreoftheindependent
variableswith
stratify(...)
whichwillcreateanothermajorgroupinglevel
inatable
application SDK tool:C# PDF Convert to Jpeg SDK: Convert PDF to JPEG images in C#.net
NET library to batch convert PDF files to High quality jpeg file can be exported from PDF in Turn multiple pages PDF into single jpg files respectively online.
www.rasteredge.com
application SDK tool:XDoc.HTML5 Viewer for .NET, Zero Footprint AJAX Document Image
View, Convert, Edit, Sign Documents and Images. Choose file display mode. We are dedicated to provide powerful & profession imaging controls, PDF document, image
www.rasteredge.com
CHAPTER10. MAKINGTABLES
98
Cross-ClassifiedSummaries
·
Obtainedusingtheoption
method=’cross’
·
Cross-classifiesby2or3stratifiersandproducesstatisticalsummariesof
theresponsevariable(using
fun
)
·
Will put first t independent t variable e down n rows s of a table, second across
columns
·
TobeconsistentwiththerestofStheformulaforthistypeofoutputshould
havebeen
summary(y ∼ ∼ x1*x2, , method=’cross’)
butinsteadthefunctionusestheadditivenotation
summary(y ∼ ∼ x1+x2, , method=’cross’)
·
No
plot
method
ReverseSummaries
·
Obtainedusingtheoption
method=’reverse’
·
“Reverse”becausewereversetherolesoftheresponseandindependent
variables
·
Neededbecauseyoucan’tput
>1
responsevariableontheleftsideofthe
·
Responseisacategoricalvariable
CHAPTER10. MAKINGTABLES
99
·
Each right-hand-side variableisstratified separately by the left-hand-side
variable
·
Thisisthe typical“Table 1”fora randomizedclinicaltrialwhere columns
arefortreatmentsandeachrowisforabaselinevariablebeingstratifiedby
treatment
b
·
Defaultsummaryispercentsforcategoricalbaselinevariables(bydefault
onlyonepercentisprintedwhenthevariableisbinary)andthreequartiles
forcontinuousvariables
Examples
SeeAH6.2and
http://hesweb1.med.virginia.edu/biostat/s/doc/summary.
pdf
10.3
summarize
Function
·
Like
tapply
intermsofhavingavector(mainanalysisvariable)asfirstar-
gument
·
Alwayscross-classifies
·
Maycross-classifybyanynumberofvariables
·
Usermusttakecareof
NA
s(usuallybyspecifying
na.rm=T
asfinalargument
to
summarize
)
b
Itisnowgenerallythoughtthatsuchtablesthatarestratifiedbytreatmentcaneasilybemisinterpretedbytemptingresearchersdosomething
aboutapparentimbalancesinbaselinecharacteristicsacrosstreatments. Researchersoftendonotrealizethatthereisastronglikelihoodof
counter-imbalancesonpatientdescriptorsthatarenottabulated.
CHAPTER10. MAKINGTABLES
100
·
Doesnotautomaticallystratifycontinuousvariables;usermustuse
cut2
for
example
·
Use
llist
functiontoenclosemultiplestratifiers,togetautomaticnaming
·
Canspecifynew namestouseinside
llist
—usefulfortemporary
cut2
variables,etc.
set.seed(1)
n <- - 200
y <- - runif(n)
age
<- rnorm(n, 50, , 10)
sex
<- sample(c(’f’,’m’),n,T)
state <- - sample(c(’AL’,’AK’,’CA’), , n, , T)
# Get mean y y by y sex x x x state e categories
s <- - summarize(y, llist(sex,state), , mean)
options(digits=3)
s
# s s is s an n ordinary data frame
sex state
y
1
f
AK 0.470
2
f
AL 0.493
3
f
CA 0.485
4
m
AK 0.497
5
m
AL 0.464
6
m
CA 0.465
# mean and s.d. of f y y by y sex
summarize(y, sex, smean.sd)
sex
y
SD
1
f 0.483 0.320
2
m 0.478 0.295
# median n of f y y by y tertile e of age e and by y sex,
# new name for r categorized d age
summarize(y, llist(Age=cut2(age,g=3), sex), median)
Age sex
y
1 [21.0,45.0)
f 0.423
2 [21.0,45.0)
m 0.519
3 [45.0,53.8)
f 0.560
4 [45.0,53.8)
m 0.496
CHAPTER10. MAKINGTABLES
101
5 [53.8,77.0]
f 0.362
6 [53.8,77.0]
m 0.361
Chapter11
InsertingPlotsintoL
A
T
E
XReports
11.1 Background
·
Toputa graphic ona websiteor inadocumentagraphicfilehas tobe
created
·
Microsoft Office uses Windows Metafiles, a poorly documented Microsoft
formatthatdoesnotrendercertaingraphicalcomponentsfaithfully
·
Youcancopyand paste an S-P
LUS
graph intoWordorintothe S-P
LUS
Reportwindow(implicitlyusesWindowsMetafileformat),orexplicitlyexport
agraphtoWindowsMetafileformatandinsertitintoaWorddocument
·
Adobe Postscript formatprovides the most faithful rendering of graphics,
andPostscriptisauniversallyusedformat(PDFisaformofcompressed
Postscript)
·
APostscriptgraphiccanbeinsertedintoWorddocuments(
Insert ... . Picture
... From m File
)and willprintbeautifullyonaPostscriptprinteralthough
theydisplayasablankboxonthescreen
102
Documents you may be interested
Documents you may be interested