Fundamental Graphics in R Prof. Ke-Sheng Cheng Dept. of Bioenvironmental Systems Eng. National Taiwan University.

Slides:



Advertisements
Similar presentations
STATISTICS Joint and Conditional Distributions
Advertisements

STATISTICS Sampling and Sampling Distributions
STATISTICS HYPOTHESES TEST (III) Nonparametric Goodness-of-fit (GOF) tests Professor Ke-Sheng Cheng Department of Bioenvironmental Systems Engineering.
STATISTICS POINT ESTIMATION Professor Ke-Sheng Cheng Department of Bioenvironmental Systems Engineering National Taiwan University.
RSLAB-NTU Lab for Remote Sensing Hydrology and Spatial Modeling 1 An Introduction to R Pseudo Random Number Generation (PRNG) Prof. Ke-Sheng Cheng Dept.
Dept of Bioenvironmental Systems Engineering National Taiwan University Lab for Remote Sensing Hydrology and Spatial Modeling STATISTICS Hypotheses Test.
STATISTICS Univariate Distributions
STATISTICS Joint and Conditional Distributions
Dept of Bioenvironmental Systems Engineering National Taiwan University Lab for Remote Sensing Hydrology and Spatial Modeling STATISTICS Hypotheses Test.
R_SimuSTAT_1 Prof. Ke-Sheng Cheng Dept. of Bioenvironmental Systems Eng. National Taiwan University.
R_SimuSTAT_2 Prof. Ke-Sheng Cheng Dept. of Bioenvironmental Systems Eng. National Taiwan University.
STATISTICS Random Variables and Distribution Functions
Exercise session # 1 Random data generation Jan Matuska November, 2006 Labor Economics.
FINDING A PROPER STATISTICAL DISTRIBUTION FOR DATASET
Simulation Modeling and Analysis
CS 351/ IT 351 Modelling and Simulation Technologies Random Variates Dr. Jim Holten.
Measures of Relative Standing and Boxplots
Starter 1.Find the median of Find the median of Calculate the range of Calculate the mode.
Frequency Distributions and Their Graphs
Probability Distributions 2014/04/07 Maiko Narahara
STATISTICS HYPOTHESES TEST (I) Professor Ke-Sheng Cheng Department of Bioenvironmental Systems Engineering National Taiwan University.
Topic 4 - Continuous distributions
Dept of Bioenvironmental Systems Engineering National Taiwan University Lab for Remote Sensing Hydrology and Spatial Modeling STATISTICS Random Variables.
Continuous Probability Distributions  Continuous Random Variable  A random variable whose space (set of possible values) is an entire interval of numbers.
Kinds of data 10 red 15 blue 5 green 160cm 172cm 181cm 4 bedroomed 3 bedroomed 2 bedroomed size 12 size 14 size 16 size 18 fred lissy max jack callum zoe.
Quantitative Skills 1: Graphing
1 Statistical Distribution Fitting Dr. Jason Merrick.
STATISTICS INTERVAL ESTIMATION Professor Ke-Sheng Cheng Department of Bioenvironmental Systems Engineering National Taiwan University.
Dept of Bioenvironmental Systems Engineering National Taiwan University Lab for Remote Sensing Hydrology and Spatial Modeling STATISTICS Interval Estimation.
STOCHASTIC HYDROLOGY Stochastic Simulation (I) Univariate simulation Professor Ke-Sheng Cheng Department of Bioenvironmental Systems Engineering National.
Distributions, Iteration, Simulation Why R will rock your world (if it hasn’t already)
Simulations and programming in R. Why to simulate and program in R at all? ADVANTAGES –All R facilities can be used in the simulations Random number generators.
STATISTICS Univariate Distributions Professor Ke-Sheng Cheng Department of Bioenvironmental Systems Engineering National Taiwan University.
STATISTICS Joint and Conditional Distributions Professor Ke-Sheng Cheng Department of Bioenvironmental Systems Engineering National Taiwan University.
Analysis of RT distributions with R Emil Ratko-Dehnert WS 2010/ 2011 Session 08 –
STOCHASTIC HYDROLOGY Stochastic Simulation of Bivariate Distributions Professor Ke-Sheng Cheng Department of Bioenvironmental Systems Engineering National.
Lab for Remote Sensing Hydrology and Spatial Modeling Dept of Bioenvironmental Systems Engineering National Taiwan University 1/45 GEOSTATISTICS INTRODUCTION.
Cumulative frequency Cumulative frequency graph
Stochastic Hydrology Random Field Simulation Professor Ke-Sheng Cheng Department of Bioenvironmental Systems Engineering National Taiwan University.
Stats Lab #3.
Modeling and Simulation CS 313
STATISTICS Exploratory Data Analysis and Probability
Box and Whisker Plots.
STATISTICS HYPOTHESES TEST (I)
BAE 5333 Applied Water Resources Statistics
REMOTE SENSING Digital Image Processing Radiometric Enhancement Geometric Enhancement Reference: Chapters 4 and 5, Remote Sensing Digital Image Analysis.
STATISTICS POINT ESTIMATION
Probability Model Fitting Steps
Modeling and Simulation CS 313
STATISTICS Joint and Conditional Distributions
STOCHASTIC HYDROLOGY Stochastic Simulation (I) Univariate simulation
STATISTICS Random Variables and Distribution Functions
STATISTICS Univariate Distributions
Stochastic Hydrology Hydrological Frequency Analysis (II) LMRD-based GOF tests Prof. Ke-Sheng Cheng Department of Bioenvironmental Systems Engineering.
Stochastic Hydrology Random Field Simulation
STATISTICS INTERVAL ESTIMATION
Stochastic Hydrology Hydrological Frequency Analysis (I) Fundamentals of HFA Prof. Ke-Sheng Cheng Department of Bioenvironmental Systems Engineering.
Fundamental Graphics in R
QQ Plot Quantile to Quantile Plot Quantile: QQ Plot:
Stochastic Storm Rainfall Simulation
STOCHASTIC HYDROLOGY Random Processes
STATISTICS Exploratory Data Analysis and Probability
Advanced Algebra Unit 1 Vocabulary
Stochastic Simulation and Frequency Analysis of the Concurrent Occurrences of Multi-site Extreme Rainfalls Prof. Ke-Sheng Cheng Department of Bioenvironmental.
Professor Ke-sheng Cheng
STATISTICS HYPOTHESES TEST (I)
STATISTICS Univariate Distributions
Introductory Statistics
Professor Ke-Sheng Cheng
Presentation transcript:

Fundamental Graphics in R Prof. Ke-Sheng Cheng Dept. of Bioenvironmental Systems Eng. National Taiwan University

Histogram 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). 9/9/2015 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ. 2

9/9/2015 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ. 3

Empirical CDF, ecdf 9/9/ Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.

The ecdf in R is a function. 9/9/ Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.

9/9/ Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.

9/9/ Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.

Sample quantiles 9/9/2015 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ. 8 Linear interpolation

Using the quantile function to calculate sample quantiles 9/9/2015 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ. 9

9/9/2015 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ. 10

9/9/2015 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ. 11

9/9/2015 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ. 12

9/9/2015 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ. 13 Not linear interpolation! These three numbers define the box. Whiskers are defined differently.

The QQ plots The quantile-quantile plots are a type of scatter plot used to compare distributions of two groups or to compare a sample with a reference distribution. When the groups are of different sizes, R reduces the size of the larger group to the size of the smaller one by keeping the minimum and maximum values, and choosing equally spaced quantiles between. 9/9/2015 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ. 14

9/9/2015 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ. 15

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. 9/9/2015 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ. 16

9/9/2015 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ. 17

9/9/2015 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ. 18

Comparison of multiple boxplots 9/9/2015 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ. 19 Can also use boxplot(x1,x2,x3,names=c(“x1”, ”x2”, ”x3”))

Comparison of multiple boxplots 9/9/2015 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ. 20

Low-level graphics In R graphics, the display is divided into: – The plot region where data will be drawn – Four margin areas, numbered clockwise from 1 to 4, starting at the bottom. After establishing the plot region and margins, we can start adding points, lines, polygons, and symbols to the plot region. 9/9/2015 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ. 21

9/9/2015 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ. 22

Graphic components – points(x,y, …) – lines(x,y, …) – text(x,y, labels, …) – abline(a,b, …) # adds the line y=a+bx – abline(h=y, …) – abline(v=x, …) – polygon(x,y, …) – segments(x0,y0,x1,y1, …) – arrows(x0,y0,x1,y1, …) – symbols(x,y, …) – legend(x,y, legend, …) 9/9/2015 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ. 23

9/9/2015 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ. 24

9/9/2015 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ. 25

Saving Graphs to Files The R graphics display can consists of various graphics devices. The default device is the screen. However, it is also possible to save a graph to a file by assigning other graphics devices. 9/9/2015 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ. 26

Assigning R graphics device – a pdf file 9/9/2015 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ. 27 Use > jpg(“filename.jpg”), if you want to save a graph to a jpeg file.

Random number generation in R R commands for stochastic simulation (for normal distribution – pnorm – cumulative probability – qnorm – quantile function – rnorm – generating a random sample of a specific sample size – dnorm – probability density function For other distributions, simply change the distribution names. For examples, (punif, qunif, runif, and dunif) for uniform distribution and (ppois, qpois, rpois, and dpois) for Poisson distribution. 9/9/ Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.

Approximation of the Poisson distribution by normal distribution Demonstration using stochastic simulation Using R. Estimated by normal approximation of Poisson distribution 9/9/ Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.

Poisson CDF by stochastic simulation Estimated by stochastic simulation of Poisson distribution Direct calculation using theoretical CDF of Poisson distribution. 9/9/ Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.

Approximation by normal distribution Poisson CDF by stochastic simulation 9/9/ Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.

3-D Graphics 9/9/2015 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ. 32