ShortCourseMalta

Detachpos2 see how to reference a contributed package

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: R. Must do for each new session. library( fields) library( evd) library( evdbayes) library( ismev) library( SpatialExtremes) R preliminaries See hierarchy of loaded packages: search() # Detach the ’SpatialExtremes’ package. detach(pos=2) See how to reference a contributed package: citation("fields") R preliminaries Simulate some random fields From the help file for the fields function sim.rf help( sim.rf) #Simulate a Gaussian random field with an exponential # covariance function, range parameter = 2.0 and the # domain is [0, 5] × [0, 5] evaluating the field at a 100 × 100 # grid. grid < − list( x= seq( 0,5„100), y= seq(0,5„100)) obj < − Exp.image.cov( grid=grid, theta=.5, setup=TRUE) look < − sim.rf( obj) # Now simulate another ... look2 < − sim.rf( obj) R preliminaries Plotting the simulated fields # setup the plotting device to have two plots side-by-side set.panel(2,1) # Image plot with a color scale. image.plot( grid$x, grid$y, look) title("simulated gaussian field") image.plot( grid$x, grid$y, look2) title("another (independent) realization ...") R preliminaries Basics of plotting in R: • First must open a device on which to plot. – Most plotting commands (e.g., plot) open a device (that you can see) if one is not already open. If a device is open, it will write over the current plot. – X11() will also open a device that you can see. – To create a file with the plot(s), use postscript, jpeg, png, or pdf (before calling the plotting routines. Use dev.off() to close the device and create the file. • plot and many other plotting functions use the par values to define various characteristics (e.g., margins, plotting symbols, character sizes, etc.). Type help( plot) and help( par) for more information. R preliminaries Simple plot example. plot( 1:10, z <- rnorm(10), type="l", xlab="", ylab="z", main="Std Normal Random Sample") points( 1:10, z, col="red", pch="s", cex=2) lines( 1:10, rnorm(10), col="blue", lwd=2, lty=2) # Make a standard normal qq-plot of ’z’. qqnorm( z) # Shut off the device. dev.off() Background on Extreme Value Analysis (EVA) Motivation Sums, averages and proportions (Normality) • Central Limit Theorem (CLT) • Limiting distribution of binomial distribution Extremes • Normal distribution inappropriate • Bulk of data may be misleading • Extremes are often rare, so often not enough data Background on Extreme Value Analysis (EVA) Simulations # Simulate a sample of 1000 from a Unif(0,1) distribution. U < − runif( 1000) hist( U) # Simulate a sample of 1000 from a N(0,1) distribution. Z < − rnorm( 1000) hist( Z) # Simulate a sample of 1000 from a Gumbel distribution. M < − rgev( 1000) hist( M) Background on Extreme Value Analysis (EVA) Simulations # Simulate 1000 maxima from samples of size 30 from # the normal distribution. Zmax < − matrix( NA, 30, 1000) dim( Zmax) for( i in 1:1000) Zmax[,i] < − rnorm( 30) Zmax < − apply( Zmax, 2, max) dim( Zmax) class( Zmax) length( Zmax) class( Zmax) hist( Zmax, breaks="...
View Full Document

Ask a homework question - tutors are online