Professional Documents
Culture Documents
R topics documented:
spuRs-package . . . bisection . . . . . . . tDistances . . . . . xedpoint . . . . . . xedpoint_show . . . kew . . . . . . . . . mean.transectHolder mean.trapTransect . . newtonraphson . . . newtonraphson_show . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 . 3 . 4 . 5 . 6 . 7 . 7 . 8 . 9 . 10
2 prime . . . . . . . . . primesieve . . . . . . . print.transectHolder . . print.trapTransect . . . sd.transectHolder . . . simulate.transectHolder transectHolder . . . . . trapTransect . . . . . . treeg . . . . . . . . . . trees . . . . . . . . . . ufc . . . . . . . . . . . ufc.plots . . . . . . . . vol.m3 . . . . . . . . . Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
spuRs-package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 12 13 14 15 16 17 18 19 20 21 22 23 25
spuRs-package
Description This package provides scripts, functions and datasets for the book "Introduction to Scientic Programming and Simulation Using R." Details Package: Type: Version: Date: License: LazyLoad: spuRs Package 1.0 2008-08-12 TBA yes
The datasets are: kew, treeg, trees, ufc.plots, and ufc. The main functions are: bisection, xedpoint, xedpoint\_show, newtonraphson, newtonraphson\_show, prime, primesieve, and vol.m3. We also provide functions relevant to the seedtrap case study: mean and print functions, an sd function, simulate, tDistances, and constructors. See Chapters 8 and 21 for more details. Type ?<object> to learn more about these objects, e.g. ?ufc Author(s) Owen Jones, Robert Maillardet, Andrew Robinson, Olga Borovkova, and Steve Carnie. Maintainer: Andrew Robinson <A.Robinson@ms.unimelb.edu.au>
bisection References
Jones, O.D., R.J. Maillardet, and A.P. Robinson. 2009. Introduction to Scientic Programming and Simulation Using R. Chapman And Hall/CRC.
bisection
Description Applies the bisection algorithm to nd x such that ftn(x) == x. Usage bisection(ftn, x.l, x.r, tol = 1e- 9) Arguments ftn x.l x.r tol Details We assume that ftn is a function of a single variable. Value Returns the value of x at which ftn(x) == x. If the function fails to converge within max.iter iterations, returns NULL. References Jones, O.D., R. Maillardet, and A.P. Robinson. 2009. An Introduction to Scientic Programming and Simulation, Using R. Chapman And Hall/CRC. See Also newtonraphson, fixedpoint Examples
ftn5 <- function(x) return(log(x)-exp(-x)) bisection(ftn5, 1, 2, tol = 1e-6)
the function. is the lower starting point. is the upper starting point. distance of successive iterations at which algorithm terminates.
tDistances
fitDistances
Description This function uses maximum likelihood to t a nominated probability density function to the data of a seedtrap transect holder.
Arguments x family an object of class transectHolder the nominated distribution, which must be one of those distributions that can be t by fitdistr of the MASS package.
Value The function returns the parameter estimates for the nominated family.
References Jones, O.D., R. Maillardet, and A.P. Robinson. 2009. An Introduction to Scientic Programming and Simulation, Using R. Chapman And Hall/CRC.
Examples
s1 <- trapTransect(distances = 1:4, seed.counts = c(4, 3, 2, allTraps <- transectHolder(s1, family="Weibull") fitDistances(allTraps, "exponential") ))
xedpoint
fixedpoint
Description Applies the xed point algorithm to nd x such that ftn(x) == x. Usage fixedpoint(ftn, x , tol = 1e- 9, max.iter = 1 ) Arguments ftn x tol max.iter Details We assume that ftn is a function of a single variable. Value Returns the value of x at which ftn(x) == x. If the function fails to converge within max.iter iterations, returns NULL. References Jones, O.D., R. Maillardet, and A.P. Robinson. 2009. An Introduction to Scientic Programming and Simulation, Using R. Chapman And Hall/CRC. See Also newtonraphson, bisection Examples
ftn1 <- function(x) return(exp(exp(-x))) fixedpoint(ftn1, 2, tol = 1e-6)
the function. is the initial guess at the xed point. distance of successive iterations at which algorithm terminates. maximum number of iterations.
xedpoint_show
fixedpoint_show
Description Applies the xed point algorithm to nd x such that ftn(x) == x, and plots the process.
Arguments ftn x xmin xmax the function. is the initial guess at the xed point. ~~Describe xmin here~~ ~~Describe xmax here~~
Value Returns the value of x at which ftn(x) == x. If the function fails to converge within max.iter iterations, returns NULL.
References Jones, O.D., R. Maillardet, and A.P. Robinson. 2009. An Introduction to Scientic Programming and Simulation, Using R. Chapman And Hall/CRC.
kew
kew
303 years of monthly rainfall data from Kew Gardens, London, U.K.
Description The monthly rainfall at Kew Gardens, London, U.K., from 1697 to 1999, in mm. Usage data(kew) Format A wide-format data frame with 303 observations. Each month has its own column. Source Data obtained from the U.S. National Climatic Data Centre, Global Historical Climatology Network data base (GHCN-Monthly Version 2) http://www.ncdc.noaa.gov/oa/climate/ghcn-monthly/. References Jones, O.D., R. Maillardet, and A.P. Robinson. 2009. An Introduction to Scientic Programming and Simulation, Using R. Chapman And Hall/CRC. Examples
data(kew)
mean.transectHolder
Function to compute the mean dispersal distance along a transect of seed traps.
Description This function computes the mean dispersal distance along a transect of seed traps. Usage ## S3 method for class transectHolder ## S3 method for class transectHolder mean(x, ...) Arguments x ... an object representing a transect of seed traps. further arguments passed to or from other methods.
mean.trapTransect
Jones, O.D., R. Maillardet, and A.P. Robinson. 2009. An Introduction to Scientic Programming and Simulation, Using R. Chapman And Hall/CRC. See Also transectHolder Examples
transect.1 <- trapTransect(distances = 1:4, seed.counts = c(4, 3, 2, )) transect.2 <- trapTransect(distances = 1:3, seed.counts = c(3, 2, 1)) transect.3 <- trapTransect(distances=(1:5)/2, seed.counts = c(3, 4, 2, 3, 1)) allTraps <- transectHolder(transect.1, transect.2, transect.3, family="Weibull") mean(allTraps)
mean.trapTransect
Function to compute the mean dispersal distance along a transect of seed traps.
Description This function computes the mean dispersal distance along a transect of seed traps. Usage ## S3 method for class trapTransect ## S3 method for class trapTransect mean(x, ...) Arguments x ... Value The mean seed dispersal distance is returned. an object representing a transect of seed traps. further arguments passed to or from other methods.
newtonraphson References
Jones, O.D., R. Maillardet, and A.P. Robinson. 2009. An Introduction to Scientic Programming and Simulation, Using R. Chapman And Hall/CRC. See Also trapTransect Examples
s1 <- trapTransect(distances = 1:4, seed.count = c(4, 3, 2, mean(s1) ))
newtonraphson
Description Applies the Newton-Raphson algorithm to nd x such that ftn(x)[1] == 0. Usage newtonraphson(ftn, x , tol = 1e- 9, max.iter = 1 ) Arguments ftn x tol max.iter Value Returns the value of x at which ftn(x)[1] == 0. If the function fails to converge within max.iter iterations, returns NULL. References Jones, O.D., R. Maillardet, and A.P. Robinson. 2009. An Introduction to Scientic Programming and Simulation, Using R. Chapman And Hall/CRC. See Also fixedpoint, bisection the function. is the initial guess at the xed point. distance of successive iterations at which algorithm terminates. maximum number of iterations.
10 Examples
ftn4 <- function(x) { # returns function value and its derivative at x fx <- log(x) - exp(-x) dfx <- 1/x + exp(-x) return(c(fx, dfx)) } newtonraphson(ftn4, 2, 1e-6)
newtonraphson_show
newtonraphson_show
Description Applies the Newton-Raphson algorithm to nd x such that ftn(x)[1] == 0, and plots the trace of the estimate. Usage newtonraphson_show(ftn, x , xmin = x - 1, xmax = x + 1) Arguments ftn x xmin xmax Value Returns the value of x at which ftn(x)[1] == 0. If the function fails to converge within max.iter iterations, returns NULL. References Jones, O.D., R. Maillardet, and A.P. Robinson. 2009. An Introduction to Scientic Programming and Simulation, Using R. Chapman And Hall/CRC. See Also newtonraphson the function. the initial guess of the xed point. lower limit for plotting. upper limit for plotting.
prime
11
prime
Usage prime(n)
Value The function returns a logical object that is TRUE if the integer is prime.
References Jones, O.D., R. Maillardet, and A.P. Robinson. 2009. An Introduction to Scientic Programming and Simulation, Using R. Chapman And Hall/CRC.
Examples
prime(1 ) prime(7)
12
primesieve
primesieve
Description This function uses the Sieve of Eratosthenes to nd all the primes less than or equal to a given integer. Usage primesieve(sieved, unsieved)
Arguments sieved unsieved Identied primes (empty vector for initialization) Candidate integers
Details The function assumes that unsieved is a vector of positive integers. Value Returns a vector of primes sieved (selected) from the input vector. References Jones, O.D., R. Maillardet, and A.P. Robinson. 2009. An Introduction to Scientic Programming and Simulation, Using R. Chapman And Hall/CRC. See Also prime
Examples
primesieve(c(), 2:2 )
print.transectHolder
13
print.transectHolder
Description This function prints the details of a transectHolder object. Usage ## S3 method for class transectHolder ## S3 method for class transectHolder print(x, ...) Arguments x ... Details The print function simply uses str on the transectHolder object. Value This function is called for its side-effect, which is to print the object informatively. References Jones, O.D., R. Maillardet, and A.P. Robinson. 2009. An Introduction to Scientic Programming and Simulation, Using R. Chapman And Hall/CRC. See Also transectHolder Examples
transect.1 <- trapTransect(distances = 1:4, seed.counts = c(4, 3, 2, )) transect.2 <- trapTransect(distances = 1:3, seed.counts = c(3, 2, 1)) transect.3 <- trapTransect(distances=(1:5)/2, seed.counts = c(3, 4, 2, 3, 1)) allTraps <- transectHolder(transect.1, transect.2, transect.3, family="Weibull") allTraps
An object representing a transect of seed traps. further arguments passed to or from other methods.
14
print.trapTransect
print.trapTransect
Description This function prints the details of a trapTransect object. Usage ## S3 method for class trapTransect ## S3 method for class trapTransect print(x, ...) Arguments x ... Details The print function simply uses str on the trapTransect object. Value This function is called for its side-effect, which is to print the object informatively. References Jones, O.D., R. Maillardet, and A.P. Robinson. 2009. An Introduction to Scientic Programming and Simulation, Using R. Chapman And Hall/CRC. See Also trapTransect Examples
s1 <- trapTransect(distances = 1:4, seed.count = c(4, 3, 2, s1 ))
An object representing a transect of seed traps. further arguments passed to or from other methods.
sd.transectHolder
15
sd.transectHolder
Description This function computes the standard deviation of the dispersal distances along a transect of seed traps. Usage sd.transectHolder(transectHolder) Arguments transectHolder an object representing a transect of seed traps. Value The standard deviation of the seed dispersal distances is returned. References Jones, O.D., R. Maillardet, and A.P. Robinson. 2009. An Introduction to Scientic Programming and Simulation, Using R. Chapman And Hall/CRC. See Also transectHolder Examples
transect.1 <- trapTransect(distances = 1:4, seed.counts = c(4, 3, 2, )) transect.2 <- trapTransect(distances = 1:3, seed.counts = c(3, 2, 1)) transect.3 <- trapTransect(distances=(1:5)/2, seed.counts = c(3, 4, 2, 3, 1)) allTraps <- transectHolder(transect.1, transect.2, transect.3, family="Weibull") mean(allTraps) sd.transectHolder(allTraps)
16
simulate.transectHolder
Description This function simulates a two-dimensional seed rain according to the model stored in a transectHolder object. The angle of the seed location from the parent plant is uniformly distributed on [0, 2 pi). Usage ## S3 method for class transectHolder ## S3 method for class transectHolder simulate(object, nsim=1, seed=NULL, ...) Arguments object nsim seed ... Value A dataframe with n rows with the following components: distances angles x y References Jones, O.D., R. Maillardet, and A.P. Robinson. 2009. An Introduction to Scientic Programming and Simulation, Using R. Chapman And Hall/CRC. See Also transectHolder seed distances to parent plant seed angles to parent plant, in radians x-location of seed y-location of seed the transectHolder object for simulation the number of seeds to simulate. if not NULL, set the seed to this value before simulation. additional optional arguments (ignored here).
transectHolder Examples
transect.1 <- trapTransect(distances = 1:4, seed.counts = c(4, 3, 2, )) transect.2 <- trapTransect(distances = 1:3, seed.counts = c(3, 2, 1)) transect.3 <- trapTransect(distances=(1:5)/2, seed.counts = c(3, 4, 2, 3, 1)) allTraps <- transectHolder(transect.1, transect.2, transect.3, family="Weibull") allTraps simulate(allTraps, nsim=5, seed=123)
17
transectHolder
Description This function constructs a transectHolder object given a collection of trapTransect objects and a nominated probability density function to t to the seed count prole. Usage transectHolder(..., family = "exponential") Arguments ... family Details This function is a constructor. The nominated distribution, which must be one of those distributions that can be t by fitdistr of the MASS package. Value A transectHolder object, which is a list comprising transects family parameters rng a list one or more trapTransect objects, the name of the distribution to which the transect data has been t, the estimated parameters for that distribution, the corresponding random number generator for simulations. one or more trapTransect objects the probability density function to t to the distance count proles.
18 References
trapTransect
Jones, O.D., R. Maillardet, and A.P. Robinson. 2009. An Introduction to Scientic Programming and Simulation, Using R. Chapman And Hall/CRC. See Also trapTransect Examples
transect.1 <- trapTransect(distances = 1:4, seed.counts = c(4, 3, 2, )) transect.2 <- trapTransect(distances = 1:3, seed.counts = c(3, 2, 1)) transect.3 <- trapTransect(distances=(1:5)/2, seed.counts = c(3, 4, 2, 3, 1)) allTraps <- transectHolder(transect.1, transect.2, transect.3, family="Weibull") allTraps
trapTransect
Description This function constructs a trapTransect object given a vector of trap distances from the parent plant, a vector of trap seed counts corresponding to the trap distances, and a single trap area. Usage trapTransect(distances, seed.counts, trap.area = . Arguments distances seed.counts trap.area Details This function is a constructor. Value A trapTransect object, which is a list comprising three objects: distances seed.counts trap.area A vector of trap distances from the parent plant. A vector of seed counts in each trap. The surface area of each trap. A vector of trap distances from the parent plant. A vector of seed counts in each trap. The surface area of each trap. 1)
treeg References
19
Jones, O.D., R. Maillardet, and A.P. Robinson. 2009. An Introduction to Scientic Programming and Simulation, Using R. Chapman And Hall/CRC. See Also mean.trapTransect, print.trapTransect Examples
s1 <- trapTransect(distances = 1:4, seed.counts = c(4, 3, 2, s1 mean(s1) ))
treeg
Grand r tree growth data from northern and central Idaho, USA.
Description A sample of 66 grand r (Abies grandis) trees was selected from national forests around northern and central Idaho. The trees were selected to be dominant in their environment, with no visible evidence of crown damage, forks, broken tops, etc. For each tree the habitat type and the national forest from which it came were recorded. We have data from nine national forests and six different habitat types. Usage data(treeg) Format A data frame with 542 observations on the following 6 variables. tree.ID Tree number. forest National forest number. habitat Habitat code (see Details). dbh.in Bole diameter at 1.37 m, in inches height.ft Tree height, in feet. age Age at which measurement was taken.
20 Details
trees
For each tree the height, diameter and age were measured (age is measured using tree rings), then the tree was split lengthways, which allows you to determine the height and diameter of the tree at any age. In this instance height and diameter were recorded for the age the tree was felled and then at ten year periods going back in time. The diameter of the tree was measured at a height of 1.37 m (46), which is called breast height in forestry. The height refers to the height of the main trunk only. The habitats corresponding to codes 1 through 5 are: Ts/Pach; Ts/Op; Th/Pach; AG/Pach and PA/Pach. These codes refer to the climax tree species, which is the most shade-tolerant species that can grow on the site, and the dominant understorey plant, respectively. Ts refers to Thuja plicata and Tsuga heterophylla, Th refers to just Thuja plicata, AG is Abies grandis, PA is Picea engelmanii and Abies lasiocarpa, Pach is Pachistima myrsinites, and Op is the nasty Oplopanaz horridurn. Grand r is considered a major climax species for AG/Pach, a major seral species for Th/Pach and PA/Pach, and a minor seral species for Ts/Pach and Ts/Op. Loosely speaking, a community is seral if there is evidence that at least some of the species are temporary, and climax if the community is self-regenerating (Daubenmire, 1952). Source These data were kindly supplied by Dr Al Stage, Principal Mensurationist (retired), USDA Forest Service Foresct Sciences Laboratory, Moscow, ID, USA. References R. Daubenmire, 1952. Forest Vegetation of Northern Idaho and Adjacent Washington, and Its Bearing on Concepts of Vegetation Classication, Ecological Monographs 22, 301330. A. R. Stage, 1963. A mathematical approach to polymorphic site index curves for grand r. Forest Science 9, 167180. Examples
data(treeg)
trees
Description These are a subset of the von Guttenberg data, a set of measurements on Norway spruce (Picea abies [L.] Karst) in several different locations and site categories. Usage data(trees)
ufc Format A data frame with 1200 observations on the following 3 variables. ID A factor identifying the tree by location, site, and tree number. Age The age at which the tree was measured. Vol The bole volume of the tree, in cubic dm. Source
21
These data were kindly provided by Professor Boris Zeide, University of Arkanasa, Monticello, AK, USA, and are further documented in Zeide (1993). References A.R. von Guttenberg. 1915. Growth and yield of spruce in Hochgebirge. Franz Deuticke, Wien. (In German) B. Zeide, 1993. Analysis of growth equations. Forest Science 39 594616. Examples
data(trees)
ufc
Description These are a subset of the tree measurement data from the Upper Flat Creek unit of the University of Idaho Experimental Forest, which was measured in 1991. Usage data(ufc) Format A data frame with 336 observations on the following 5 variables. plot plot label tree tree label species species kbd with levels DF, GF, WC, WL dbh.cm tree diameter at 1.37 m. from the ground, measured in centimetres. height.m tree height measured in metres
22 Details
ufc.plots
The inventory was based on variable radius plots with 6.43 sq. m. per ha. BAF (Basal Area Factor). The forest stand was 121.5 ha. This version of the data omits errors, trees with missing heights, and uncommon species. The four species are Douglas-r, grand r, western red cedar, and western larch. Source The data are provided courtesy of Harold Osborne and Ross Appelgren of the University of Idaho Experimental Forest. References Jones, O.D., R. Maillardet, and A.P. Robinson. 2009. An Introduction to Scientic Programming and Simulation, Using R. Chapman And Hall/CRC. See Also ufc.plots Examples
data(ufc)
ufc.plots
Description These are a subset of the plot measurement data from the Upper Flat Creek unit of the University of Idaho Experimental Forest, which was measured in 1991. Usage data(ufc.plots) Format A data frame with 144 observations on the following 6 variables. plot plot label north.n northerly plot count east.n easterly plot count north northerly coordinate east easterly coordinate vol.m3.ha total above-ground merchantable volume, in cubic metres per hectare.
vol.m3 Source
23
The data are provided courtesy of Harold Osborne and Ross Appelgren of the University of Idaho Experimental Forest. References Jones, O.D., R. Maillardet, and A.P. Robinson. 2009. An Introduction to Scientic Programming and Simulation, Using R. Chapman And Hall/CRC. See Also ufc Examples
data(ufc.plots)
vol.m3
Description This function computes the volume of a tree bole given its basal diameter and length, assuming that the bole is a frustum of a geometric solid. Usage vol.m3(dbh.cm, height.m, multiplier = .5) Arguments dbh.cm height.m multiplier Details Commonly-used shapes are: 1/3 conoid 1/2 second-degree parabaloid 1 cylinder Value The volume is returned, in units of cubic metres. basal diameter in cm. height in m. shape, expressed as a multiplier.
24 Examples
vol.m3(3 , 3 ) vol.m3(3 , 3 , 1)
vol.m3
Index
Topic datasets kew, 7 treeg, 19 trees, 20 ufc, 21 ufc.plots, 22 Topic data transectHolder, 17 trapTransect, 18 Topic distribution simulate.transectHolder, 16 Topic manip fitDistances, 4 prime, 11 primesieve, 12 vol.m3, 23 Topic optimize bisection, 3 fixedpoint, 5 fixedpoint_show, 6 newtonraphson, 9 newtonraphson_show, 10 Topic package spuRs-package, 2 Topic print print.transectHolder, 13 print.trapTransect, 14 Topic univar mean.transectHolder, 7 mean.trapTransect, 8 sd.transectHolder, 15 bisection, 3, 5, 9 fitDistances, 4 fitdistr, 4 fixedpoint, 3, 5, 6, 9 fixedpoint_show, 6 kew, 7 25 mean.transectHolder, 7 mean.trapTransect, 8, 19 newtonraphson, 3, 5, 9, 10 newtonraphson_show, 10 prime, 11, 12 primesieve, 11, 12 print.transectHolder, 13 print.trapTransect, 14, 19 sd.transectHolder, 15 simulate.transectHolder, 16 spuRs (spuRs-package), 2 spuRs-package, 2 transectHolder, 8, 13, 15, 16, 17 trapTransect, 4, 9, 14, 18, 18 treeg, 19 trees, 20 ufc, 21, 23 ufc.plots, 22, 22 vol.m3, 23