﻿
CHAPTER8. OPERATINGINS
83
8.7 AdvancedDataManipulationExamples
AH4.2.5-8
Seetextfor
·
mergingdataframesbysubjectID(e.g.,baseline+serialfollow-updata)
·
mergingbaselinedatawithone-numbersummariesofserialfollow-updata
·
reshapingserialdatafromrowstocolumnsandvice-versa
·
computingchangesinserialobservations
8.8 RecodingVariablesandCreatingDerivedVariables
AH4.3
8.8.1 RecodingOneVariable
UsingArithmeticor
ifelse
·
Almostalwaysuse
cut2
tomakeonecontinuousvariableintointervals(asa
factor
)
·
Torecodeanarbitrarynumericvariableintoothernumericcodes,usecode
suchas
x2 ← 1*(x==10)+2*(x > > 10 0 & & x x < 20)+3*(x >= = 20)
Thisresultsin0if
x < 10
,3if
x >= 20
.
·
The
ifelse
functionprovidesageneralsolutioninwhichyoucanalsohave
thecomputationresultincharacterstrings:
x2 ← ifelse(x < 10, ’x<10’,
ifelse(x==10, ’x=10’,
Convert pdf to powerpoint slide - software Library dll: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 to powerpoint slide - software Library dll: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
CHAPTER8. OPERATINGINS
84
ifelse(x > > 10 0 & & x x < < 20, , ’x in n (11,19)’,
’x>=20’)))
ifelse(a,b,c)
resultsin
b
when
a
is
TRUE
and
c
when
a
is
FALSE
.Itdoes
computationsinaparallelfashionacrossvectorssothatelementsof
b
or
c
areusedcorrespondingtoelementsof
a
.
a
isalmostalwaysavector.When
b
or
c
arescalars,thescalarvalueisusedforallelementsof
a
.
·
Anotherexample:divide
height
by1.2formales,1.1forfemales
height.adjusted ← ← ifelse(sex==’female’, height/1.1, , height/1.2)
# or
height.adjusted ← ← height/ifelse(sex==’female’, , 1.1, 1.2)
·
ifelse
canuseany expressions for
b
and
c
so it can reference multiple
variablestoo
Recoding
factor
Variables
·
Canuse
upData
ifvariableisinadataframethatisnotattached
·
Otherwisemostelegantmethodistoimplicitlycallthe
merge.levels
function
usingcodesuchasthefollowing
> x x ← factor(c(’cat’,’dog’,’giraffe’,’dog’))
> levels(x) ← ← list(domestic=c(’cat’,’dog’), wild=’giraffe’)
> x
[1] domestic domestic c wild domestic
Torecodelevelsonaone:onebasisusee.g.
levels(x) ← ← list(’newlevel’=’oldlevel’,’newlevel2’=’old2’)
Youdon’tneedtoenclose
’newlevel’
or
’newlevel2’
inquotesiftheseare
legalSnames.
software Library dll:VB.NET PowerPoint: Read, Edit and Process PPTX File
to convert PowerPoint to PDF, render PowerPoint PowerPoint to TIFF and convert PowerPoint to raster desired watermark on source PowerPoint slide at specified
www.rasteredge.com
software Library dll:VB.NET PowerPoint: Process & Manipulate PPT (.pptx) Slide(s)
Suitable for Processing PowerPoint Slide(s) in both Web & SDK, this VB.NET PowerPoint processing control add & profession imaging controls, PDF document, image
www.rasteredge.com
CHAPTER8. OPERATINGINS
85
Ifyouwanttorecodecategoriesandthevariableisnotalreadya
factor
,
ﬁrstmakeita
factor
usinge.g.
x←factor(x)
8.8.2 CombiningMultipleVariablesintoOne
·
Canusearithmeticstatementor
ifelse
asabove
·
score.binary
inHmisccanscoreanautomaticallylabelcategoriesfroma
seriesofinputexpressions
– Canproducemanytypesofscores(e.g.,additive)butdefaultishierar-
chical
– Example: readingfromlefttoright, , categorizeanobservationintothe
lastexpressionthatistrue
myscale ← ← score.binary(age>70, previous.disease, current.severe.disease)
Thisassumesthat
previous.disease
and
current.severe.disease
are
logicalor0/1;
Conditionsonrightoverrideconditionsonleft,i.e.,ifasubjectcurrently
hasa severe disease, whetheror not
age>70
or
previous.disease
is
presentisignoredinthatcase.
Resultisafactorwithlevels
’none’, ’age>70’, ’previous.disease’, , ’current.severe.disease’
8.8.3 WheretoDeriveVariables
AH4.3.3
·
Ingeneral,badideatostorederivedvariablesaspermanentvectorsasthey
willnotthenbeupdatedifthesourcedatachange
·
Besttopermanentlystoretheformulasforcomputingthem
·
Ascriptﬁlethatcomputesderivedvariablesondemandworkswell
software Library dll:C# PowerPoint - How to Process PowerPoint
Visual C# Codes to Process PowerPoint Slide; PowerPoint C#.NET Processor. C#.NET PowerPoint: Process and Edit PowerPoint Slide(s).
www.rasteredge.com
software Library dll:VB.NET PowerPoint: Read & Scan Barcode Image from PPT Slide
VB.NET PPT PDF-417 barcode scanning SDK to detect PDF-417 barcode image from PowerPoint slide. VB.NET APIs to detect and decode
www.rasteredge.com
CHAPTER8. OPERATINGINS
86
8.9 ReviewofDataCreation,Annotation,andAnalysisSteps
AH4.4
·
Payattentionofsuggestedorderofsteps
1.Importexternaldata, often deﬁningﬁeld namesinstead ofusing non-
informativedefaultssuchas
V1, V2, , ...
2.Use
upData
to change variablenames, add/change labels and levels,
recode,dropunneededvariables
3.Runanalysesthatdonotneedthedataframetobeattached
– functionstakingawholedata frameasan argument(
datadensity
,
summary
,
describe
,
hist.data.frame
,etc.)
– simpleanalysesondataframe-preﬁxedvariables
– analysesspeciﬁedbystatisticalformulas,with data framespeciﬁed
using
data=dataframename
4.Attachdataframeifneedtoreferenceseveralindividualvariablesoutside
the
data=
mechanism
·
SeealsotheHmiscLibraryReferenceCard
8.10 SimpleMissingValueImputation
AH4.5
·
Imputingof
NA
susedtopreventincompletedatafrombeingtotallydeleted
fromananalysisofmultiplevariables
·
Ifamountofmissingdataisverysmall,canuseverysimpleﬁll-inmethods
asimplementedinHmisc’s
impute
function
> x x ← c(1,2,NA,4)
> impute(x)
# impute NA with median n (mode for categorical l var)
1 2 2 3 3 4
1 2 2* 4
# * printed after imputed values
software Library dll:VB.NET PowerPoint: Convert & Render PPT into PDF Document
How to Convert PowerPoint Slide to PDF Using VB.NET Code in .NET. What VB.NET APIs can I use to convert PowerPoint slide to PDF document file?
www.rasteredge.com
software Library dll:VB.NET PowerPoint: Edit PowerPoint Slide; Insert, Add or Delete
To view more VB.NET PowerPoint slide processing functions read VB.NET PPT (.pptx) slide processing guide page & profession imaging controls, PDF document, image
www.rasteredge.com
CHAPTER8. OPERATINGINS
87
> impute(x, median) ) # # same as s default t here
1 2 2 3 3 4
1 2 2* 4
> impute(x, 2.1)
# impute with h a a constant
1
2
3
4
1.0 2.0 2.1* 4.0
> impute(x, mean)
1
2
3
4
1.000000 2.000000 2.333333* 4.000000
> impute(x,’random’) # # impute by randomly drawing g from non-NAs
1 2 2 3 3 4
1 2 4* 4
> impute(x,’random’)
1 2 2 3 3 4
1 2 4* 4
> impute(x,’random’)
1 2 2 3 3 4
1 2 2* 4
> x x ← impute(x)
> is.imputed(x)
# tells which h obs. imputed
[1] F F F F T F
> attributes(x)
\$names:
[1] "1" "2" " "3" "4"
\$class:
[1] "impute"
\$imputed:
[1] 3
# third observation n imputed
·
Notethatimputedvaluesareﬂaggedbysavingtheirsubscriptsinanattribute
called
’imputed’
·
Ifmuchmissingdata,simpleﬁll-inmethodsresultinbiases,especiallyover-
conﬁdenceinprecisionofstatisticalestimatescomputedonﬁlled-indata
software Library dll:VB.NET PowerPoint: Extract & Collect PPT Slide(s) Using VB Sample
PowerPoint image insertion, please read this VB.NET PowerPoint slide processing tutorial to provide powerful & profession imaging controls, PDF document, image
www.rasteredge.com
software Library dll:VB.NET PowerPoint: VB Code to Draw and Create Annotation on PPT
is used to note or comment PowerPoint (.pptx) slide as a kind of compensation for limitations (other documents are compatible, including PDF, TIFF, MS Word and
www.rasteredge.com
Chapter9
ProbabilityandStatisticalFunctions
AH5,UG9
9.1 StatisticalSummaries
AH5.1,KO7.1
9.1.1 Basic
·
describe
·
table(rowvar,colvar)
—frequencytables
·
summary.formula
—usedtocomputeandtableorplotgeneralstratiﬁedstatis-
tics(coveredinnextchapter)
9.1.2 Inferential
·
Coverageintervals(mean
±
SD,quantiles)andconﬁdencelimitsforstatistical
estimatessuchasthemean
·
ManyfunctionsbundledwithHmisc
summary.formula
function
88
software Library dll:VB.NET PowerPoint: How to Convert PowerPoint Document to TIFF in
PowerPoint is often used by programmers in many applications formats, such as JPEG, GIF and PDF, by using is designed by our programmers to convert PPT document
www.rasteredge.com
software Library dll:VB.NET PowerPoint: Render PowerPoint to REImage for Further
Doc Conversion Library can be used to convert PPT document or image pages, including but not limited to PowerPoint document slide/page, PDF file page and
www.rasteredge.com
CHAPTER9. PROBABILITYANDSTATISTICALFUNCTIONS
89
·
Mostofthesearesetupsothatthevectorofstatisticstheyreturncanbe
usedascellsinatableorascentralvalueswitherrorbarsorbandsinhigh-
levelplotsusingtheHmisc
xYplot
a
function
Function
Purpose
smean.sd
meanandSD
smean.sdl
mean,mean
−k×
SD,mean
+k×
SD
default
k
is2
smean.cl.boot
meanandlowerandupper
nonparametricbootstrap
conﬁdencelimitsformean
smean.cl.normal
meanandparametric
t
-based
conﬁdencelimitsassuming
normalityofdata
smedian.hilow
medianandlowerandupper
quantiles(defaultis0.025and0.975)
Togetmedianandlowerandupperquartilesuse
smedian.hilow(x, conf.int=.5)
9.2 ProbabilityDistributions
AH5.2,KO7.3
9.2.1 DistributionsofSampledData
·
quantile
·
summary
·
smedian.hilow
·
varioushistogramandone-dimensionalscatterplots(
scat1d
,
rug
,
histSpike
)
·
variousboxplotfunctions
a
Inthelatteruses,thestatisticalsummaryfunctionoutputs3numbers:thestatistic,andvariablesnamed
Lower
and
Upper
.
CHAPTER9. PROBABILITYANDSTATISTICALFUNCTIONS
90
·
Hmisc
ecdf
forplottingempiricalcumulativedistributionfunctions
9.2.2 TheoreticalDistributions
SeeBarryBrown’sSCheatsheetinChapter5
> pbinom(3, 10, .5)
# prob of f <=3 heads in n 10 tosses, , fair coin
[1] 0.171875
> dbinom(3, 10, .5)
# prob of f exactly y 3 3 heads
[1] 0.1171875
> sum(dbinom(0:3, , 10, , .5)) ) # # another r way to o get cumulative prob
[1] 0.171875
> pnorm(1.96)
# Prob(normal l <= = 1.96)
[1] 0.9750021
> pt(1.96,4000)
# Prob(T with h 4000 d.f. <= = 1.96)
[1] 0.9749674
> 2*(1-pt(1.96,4000))
# Prob(|T T 4000| | <= = 1.96)
[1] 0.05006512
> 1-pchi(3.84,1)
# Prob(chi-sq q on n 1 1 d.f. > > 3.84)
[1] 0.05004352
> qnorm(.975)
# Find critical value for normal
[1] 1.959964
# =0.95 quantile of f normal(0,1)
# or r z z such that Prob(Z<=z)=.95
9.2.3 ConﬁdenceLimitsforBinomialProportions
·
Simplerandomsamplingofbinary(Bernoullidistribution)responses;count
numberofsuccessesorevents(
x
)outof
n
trials
·
Togetvarious0.95conﬁdencelimitsfortheunknownpopulationprobability
ofaneventusetheHmisc
binconf
function(here
n=10,x=3
):
> binconf(3,10,alpha=.05)
Lower
Upper
Exact 0.06673951 1 0.6524529
Wilson 0.10779127 7 0.6032219
CHAPTER9. PROBABILITYANDSTATISTICALFUNCTIONS
91
Wilsonintervalsaregenerallymoreaccurateandnarrowerthanso-called
“exact”conﬁdenceintervalsbasedonthe
β
or
F
distribution,assumingyou
don’trequiretheinterval’scoveragetobe
≥0.95
9.3 HmiscFunctionsforPowerandSampleSizeCalculations
AH5.3
·
bpower
: powerofcomparisonof2proportionsusingagoodapproximation
forprobabilities
·
bpower.sim
:computepowerlike
bpower
butdoitexactlythroughsimulation
·
bsamsize
:solveforsamplesizetosatisfyagivenpower
9.4 StatisticalTests
KO7.4
Ingeneral,speciﬁctestsarespecialcasesofcertainmodels,sohavingseparate
functionsforthesespecialcasescanbemoreconfusingthanhelpful.
9.4.1 NonparametricTests
5.4.1
·
Spearman
ρ
rankcorrelationtesttestswhethertwovariablesareindepen-
dentvs.theirbeingmonotonicallyassociatedwitheachother
·
Wilcoxontwo-samplerank-sumtestfortestwhethertwogroupscomefrom
thesamedistributionisaspecialcaseoftheSpearmantestwhereoneof
thetwovariablesisbinary
·
Spearmantestcanbeextendedtotestwhetheranyofasetofvariablesis
correlatedwithacontinuousresponsevariable