astudent’s guide to r 31
0 | 3
0 | 567
1 | 3
1 | 555589999
2 | 123344
2 | 66889999
3 | 0000233334444
3 | 5556666777888899999
4 | 00011112222334
4 | 555666777889
5 | 011122222333444
5 | 67788
6 | 0
Subsets can also be generated and used “on the fly"
(this time including an overlaid normal density):
> histogram(~ cesd, fit="normal",
data=filter(HELPrct, sex=='female'))
cesd
Density
0.000
0.005
0.010
0.015
0.020
0.025
0.030
0
20
40
60
Alternatively, we can make side-by-side plots to com-
pare multiple subsets.
> histogram(~ cesd | sex, data=HELPrct)
Export pdf into powerpoint - application control utility: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
Export pdf into powerpoint - application control utility: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
32 horton, kaplan, pruim
cesd
Density
0.00
0.01
0.02
0.03
0.04
0
20
40
60
female
0
20
40
60
male
The layout can be rearranged.
> histogram(~ cesd | sex, layout=c(12), data=HELPrct)
cesd
Density
0.00
0.01
0.02
0.03
0.04
0
20
40
60
female
0.00
0.01
0.02
0.03
0.04
male
We can control the number of bins in a number of ways.
These can be specified as the total number.
> histogram(~ cesd, nint=20data=female)
application control utility:Online Convert PowerPoint to PDF file. Best free online export
By integrating XDoc.PDF SDK into your C#.NET project, Microsoft Office like Word, Excel, and PowerPoint can be converted to PDF document.
www.rasteredge.com
application control utility:C# PDF insert text Library: insert text into PDF content in C#.net
Parameters: Name, Description, Valid Value. value, The char wil be added into PDF page, 0
www.rasteredge.com
astudent’s guide to r 33
cesd
Density
0.00
0.01
0.02
0.03
0
10
20
30
40
50
60
The width of the bins can be specified.
> histogram(~ cesd, width=2data=female)
cesd
Density
0.00
0.01
0.02
0.03
0.04
0
10
20
30
40
50
60
The
dotPlot()
function is used to create a dotplot for
asmaller subset of subjects (homeless females). We also
demonstrate how to change the x-axis label.
> dotPlot(~ cesd, xlab="CESD score",
data=filter(HELPrct, (sex=="female") & (homeless=="homeless")))
CESD score
Count
0
5
10
20
40
60
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
application control utility:VB.NET PDF Converter Library SDK to convert PDF to other file
PDF ›› VB.NET PDF: PDF Export. You may directly copy and paste it into your vb.net testing project. Conversion of PDF to Jpeg. Conversion of MS Office to PDF.
www.rasteredge.com
application control utility:C# PDF Converter Library SDK to convert PDF to other file formats
Able to export PDF document to HTML file. It's easy to be integrated into your C# program and convert PDF to .txt file with original PDF layout.
www.rasteredge.com
34 horton, kaplan, pruim
3.3 Density curves
Density plots are also sensi-
tive to certain choices. If your
density plot is too jagged or
too smooth, try changing the
adjust
argument: larger than 1
for smoother plots, less than 1
for more jagged plots.
One disadvantage of histograms is that they can be sensi-
tive to the choice of the number of bins. Another display
to consider is a density curve.
Here we adorn a density plot with some additions to
demonstrate how to build up a graphic for pedagogical
purposes. We add some text, a superimposed normal
density as well as a vertical line. A variety of line types
and colors can be specified, as well as line widths.
Digging Deeper
The
plotFun()
function can
also be used to annotate plots
(see section 10.2.1).
> densityplot(~ cesd, data=female)
> ladd(grid.text(x=0.2y=0.8'only females'))
> ladd(panel.mathdensity(args=list(mean=mean(cesd),
sd=sd(cesd)), col="red"), data=female)
> ladd(panel.abline(v=60lty=2lwd=2col="grey"))
cesd
Density
0.000
0.005
0.010
0.015
0.020
0.025
0.030
0
20
40
60
l
l
l
l l
l
l
l
l
l
l
l l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
ll
l
l
l l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
ll
l
l
l
l
l
l
l
l
ll
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
only females
3.4 Frequency polygons
Athird option is a frequency polygon, where the graph is
created by joining the midpoints of the top of the bars of
ahistogram.
application control utility:C# PDF insert image Library: insert images into PDF in C#.net, ASP
Import graphic picture, digital photo, signature and logo into PDF document. Merge several images into PDF. Insert images into PDF form field.
www.rasteredge.com
application control utility:VB.NET PDF insert image library: insert images into PDF in vb.net
project. Import graphic picture, digital photo, signature and logo into PDF document. Add file. Insert images into PDF form field in VB.NET. An
www.rasteredge.com
astudent’s guide to r 35
> freqpolygon(~ cesd, data=female)
cesd
Density
0.01
0.02
0.03
10
20
30
40
50
60
3.5 Normal distributions
x
is for eXtra.
The most famous density curve is a normal distribution.
The
xpnorm()
function displays the probability that a ran-
dom variable is less than the first argument, for a normal
distribution with mean given by the second argument
and standard deviation by the third. More information
about probability distributions can be found in section 11.
> xpnorm(1.96mean=0sd=1)
If X ~ N(0,1), then
P(X <= 1.96) = P(Z <= 1.96) = 0.975
P(X >
1.96) = P(Z >
1.96) = 0.025
[1] 0.975
density
0.1
0.2
0.3
0.4
0.5
−2
0
2
1.96
(z=1.96)
0.975 
0.025
application control utility:C# PDF File Split Library: Split, seperate PDF into multiple files
Divide PDF File into Two Using C#. This is an C# example of splitting a PDF to two new PDF files. Split PDF Document into Multiple PDF Files in C#.
www.rasteredge.com
application control utility:C# PDF Page Insert Library: insert pages into PDF file in C#.net
from the ability to inserting a new PDF page into existing PDF or pages from various file formats, such as PDF, Tiff, Word, Excel, PowerPoint, Bmp, Jpeg
www.rasteredge.com
36 horton, kaplan, pruim
3.6 Inference for a single sample
We can calculate a 95% confidence interval for the mean
CESD score for females by using a t-test:
> t.test(~ cesd, data=female)
One Sample t-test
data:
data$cesd
t = 30, df = 100, p-value <2e-16
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
34.4 39.4
sample estimates:
mean of x
36.9
> confint(t.test(~ cesd, data=female))
mean of x lower upper level
1
36.9
34.4
39.4
0.95
Digging Deeper
More details and examples can
be found in the
mosaic
package
Resampling Vignette.
But it’s also straightforward to calculate this using a
bootstrap. The statistic that we want to resample is the
mean.
> mean(~ cesd, data=female)
[1] 36.9
One resampling trial can be carried out:
Here we sample with re-
placement from the original
dataframe, creating a resam-
pled dataframe with the same
number of rows.
> mean(~ cesd, data=resample(female))
[1] 37.7
Even though a single trial is
of little use, it’s smart having
students do the calculation to
show that they are (usually!)
getting a different result than
without resampling.
Another will yield different results:
> mean(~ cesd, data=resample(female))
[1] 34.9
astudent’s guide to r 37
Now conduct 1000 resampling trials, saving the results
in an object called
trials
:
> trials <- do(1000)
*
mean(~ cesd, data=resample(female))
> head(trials, 3)
mean
1 36.7
2 35.5
3 35.9
> qdata(~ mean, c(.025.975), data=trials)
quantile
p
2.5%
34.3 0.025
97.5%
39.4 0.975
4
One Categorical Variable
4.1 Numerical summaries
Digging Deeper
The Start Teaching with R com-
panion book introduces the for-
mula notation used throughout
this book. See also Start Teach-
ing with R for the connections to
statistical modeling.
The
tally()
function can be used to calculate counts,
percentages and proportions for a categorical variable.
> tally(~ homeless, data=HELPrct)
homeless
housed
209
244
> tally(~ homeless, margins=TRUEdata=HELPrct)
homeless
housed
Total
209
244
453
> tally(~ homeless, format="percent"data=HELPrct)
homeless
housed
46.1
53.9
> tally(~ homeless, format="proportion"data=HELPrct)
homeless
housed
0.461
0.539
40 horton, kaplan, pruim
4.2 The binomial test
An exact confidence interval for a proportion (as well as
atest of the null hypothesis that the population propor-
tion is equal to a particular value [by default 0.5]) can be
calculated using the
binom.test()
function. The standard
binom.test()
requires us to tabulate.
> binom.test(209209 + 244)
data:
209 out of 209 + 244
number of successes = 200, number of trials = 500, p-value =
0.1
alternative hypothesis: true probability of success is not equal to 0.5
95 percent confidence interval:
0.415 0.509
sample estimates:
probability of success
0.461
The
mosaic
package provides a formula interface that
avoids the need to pre-tally the data.
> result <- binom.test(~ (homeless=="homeless"), data=HELPrct)
> result
data:
HELPrct$(homeless == "homeless")
[with success = TRUE]
number of successes = 200, number of trials = 500, p-value =
0.1
alternative hypothesis: true probability of success is not equal to 0.5
95 percent confidence interval:
0.415 0.509
sample estimates:
probability of success
0.461
As is generally the case with commands of this sort,
there are a number of useful quantities available from the
object returned by the function.
Documents you may be interested
Documents you may be interested