View
220
Download
3
Category
Tags:
Preview:
Citation preview
R_SimuSTAT_1
Prof. Ke-Sheng Cheng
Dept. of Bioenvironmental Systems Eng.
National Taiwan University
• Outline– Conducting random experiment using the
“sample” function.– Histograms of sample mean, median, and
standard deviation. – Calculation of sample quantiles.– Box-and-whisker plot.
04/10/23Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
2
• Key aspects of a random experiment– Conducted under uniform conditions– Unpredictable outcomes
04/10/23Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
3
Random experimen
t
Sample space
Event space
Probability space
Random experiment
• Using the “sample” function in R• “sample” takes a sample of the specified size
from the elements of x using either with or without replacement. [The default is sampling without replacement.]
• Simulation of lotto draw using the sample function.
04/10/23Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
4
04/10/23Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
5
04/10/23Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
6
• Calculation of the sample mean, median, and standard deviation.
• Assessing variation of the sample means (median, standard deviation) from different samples.
• Plot histograms of sample mean, median, and standard deviation.
• How about the maximum values of random samples?– Observe differences in histograms.
04/10/23Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
7
04/10/23Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
8
04/10/23Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
9
• hist(x, freq=FALSE, breaks=…)– breaks=• a vector giving the breakpoints between histogram
cells, • a single number giving the number of cells for the
histogram.
– freq=• If TRUE, the histogram graphic is a representation of
frequencies, the counts component of the result,• if FALSE, probability densities, component density, are
plotted (so that the histogram has a total area of one).
04/10/23Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
10
Sample quantiles
04/10/23Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
11
Linear interpolation
04/10/23Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
12
Not linear interpolation!
These three numbers define the box. Whiskers are defined differently.
The boxplot in R• boxplot(x,range=0)• boxplot(x) [Default, range=1.5]• boxplot(x,range=3)• A box-and-whisker plot includes two major parts – the
box and the whiskers.• The parameter range determines how far the plot whiskers extend out from the box. If range is positive, the whiskers extend to the most extreme data point which is no more than range times the interquartile range from the box. A value of zero causes the whiskers to extend to the data extremes.
04/10/23Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
13
•
04/10/23Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
14
04/10/23Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
15
• Comparison of multiple boxplots
04/10/23Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
16
04/10/23Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
17
Can also useboxplot(x1,x2,x3,names=c(“x1”, ”x2”, ”x3”))
Recommended