Title: | Predicting Totals and Weighted Sums from Spatial Data |
---|---|
Description: | Performs predictions of totals and weighted sums, or finite population block kriging, on spatial data using the methods in Ver Hoef (2008) <doi:10.1007/s10651-007-0035-y>. The primary outputs are an estimate of the total, mean, or weighted sum in the region, an estimated prediction variance, and a plot of the predicted and observed values. This is useful primarily to users with ecological data that are counts or densities measured on some sites in a finite area of interest. Spatial prediction for the total count or average density in the entire region can then be done using the functions in this package. |
Authors: | Matt Higham [cre, aut], Jay Ver Hoef [aut], Bryce Frank [aut], Michael Dumelle [aut] |
Maintainer: | Matt Higham <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.0.1 |
Built: | 2024-11-07 05:28:29 UTC |
Source: | https://github.com/highamm/sptotal |
slmfit
object for comparing models.Extract the AIC from a slmfit
object for comparing models.
## S3 method for class 'slmfit' AIC(object, ...)
## S3 method for class 'slmfit' AIC(object, ...)
object |
a |
... |
further arguments passed to or from other methods. |
The AIC value of the slmfit object. Here, AIC is computed as 2 times the negative log-likelihood plus 2 times the number of model parameters for Maximum Likelihood (ML) and 2 times the negative log-likelihood for REML. For REML, AIC should only be used to compare two models with the same covariates but different spatial covariance structures.
data(exampledataset) ## load a toy data set slmobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset, xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') AIC(slmobj)
data(exampledataset) ## load a toy data set slmobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset, xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') AIC(slmobj)
A data set that can be used with the sptotal
package. In
this example, the counts are of moose on 860 sites of equal area.
AKmoose_df
AKmoose_df
A dataframe object. The data frame AKmoose_df
contains 860 rows and 8 columns:
The mean elevation for each sitefor each site
A stratification variable (either L or M)
Assigned a 1 if the site was surveyed and a 0 otherwise
The total moose count on each site (NA
if the site was not surveyed)
the x-coordinate centroid of the site (TM)
the y-coordinate centroid of the site (TM)
the longitudinal centroid of the site
the latitudinal centroid of the site
Alaska Department of Fish and Game, Division of Wildlife Conservation has released this data set under the CC0 (creative commons) license. To the extent possible under law, Alaska Department of Fish and Game, Division of Wildlife Conservation waives all copyright and related or neighboring rights to An Alaskan GSPE (Geospatial Population Estimator) Survey of Moose, AKmoose_df.rda. This work is published from: United States.
data(AKmoose_df) names(AKmoose_df) summary(AKmoose_df)
data(AKmoose_df) names(AKmoose_df) summary(AKmoose_df)
check.variogram()
has been deprecated:
use plot.slmfit()
instead. Plots an empirical
semi-variogram of the residuals from the spatial linear model
with the fitted parametric model as a curve overtop of the
binned points. By default, the empirical semi-variogram only
shows distances that are less than or equal to the maximum
distance in the data set divided by 2. Therefore, it's possible
that the REML-fitted model will not "fit" the points perfectly.
check.variogram(object)
check.variogram(object)
object |
is an object of class |
a plot of the empirical semi-variogram with the fitted model overlayed.
data(exampledataset) ## load a toy data set slmobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset, xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') ## Not Run ## check.variogram(slmobj)
data(exampledataset) ## load a toy data set slmobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset, xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') ## Not Run ## check.variogram(slmobj)
slmfit
objectExtract Model Coefficients from a slmfit
object
## S3 method for class 'slmfit' coef(object, ...)
## S3 method for class 'slmfit' coef(object, ...)
object |
a |
... |
further arguments passed to or from other methods. |
a vector of fitted model coefficients.
data(exampledataset) ## load a toy data set slmobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset, xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') coef(slmobj)
data(exampledataset) ## load a toy data set slmobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset, xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') coef(slmobj)
Note that, currently, only three of these models are implemented
in the sptotal
package: corModelExponential()
,
corModelGaussian()
, and corModelSpherical()
.
corModelExponential(distance.matrix, range) corModelGaussian(distance.matrix, range) corModelSpherical(distance.matrix, range)
corModelExponential(distance.matrix, range) corModelGaussian(distance.matrix, range) corModelSpherical(distance.matrix, range)
distance.matrix |
The distance matrix for sampled sites |
range |
The range that determines how quickly covariance among sites tapers |
Correlation Matrix
corModelExponential()
: Exponential Correlation Structure
corModelGaussian()
: Gaussian Correlation Structure
corModelSpherical()
: Spherical Correlation Structure
A toy data set that can be used with the sptotal
package. In
this example, the true counts are actually uncorrelated, the covariates are
generated as uniform random variables, and the sites fall on a
regular grid.
exampledataset
exampledataset
A data frame with 40 rows and 7 variables:
counts, with NA values for unsampled sites
a possible predictor
a second possible predictor
coordinates on the x-axis
coordinates on the y-axis
an extra variable
Variable for the area of each plot
...
slmfit
object.Extract Fitted Values from an slmfit
object.
## S3 method for class 'slmfit' fitted(object, ...)
## S3 method for class 'slmfit' fitted(object, ...)
object |
a |
... |
further arguments passed to or from other methods. |
a vector of fitted values (estimated means)
data(exampledataset) ## load a toy data set slmobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset, xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') fitted(slmobj)
data(exampledataset) ## load a toy data set slmobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset, xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') fitted(slmobj)
Spatially correlated data are simulated assuming a multivariate normal
random error vector. For simplicity, only "Exponential"
and
"Spherical"
simulation options are given here.
geostatSim( loc.data, xcol = "x", ycol = "y", parsil = 1, range = 1, nugget = 0, minorp = 1, rotate = 90, extrap = NULL, CorModel = "Exponential" )
geostatSim( loc.data, xcol = "x", ycol = "y", parsil = 1, range = 1, nugget = 0, minorp = 1, rotate = 90, extrap = NULL, CorModel = "Exponential" )
loc.data |
data.frame with x- and y-coordinates of locations for simulated data |
xcol |
name of the column in loc.data with x-coordinates, default is "x" |
ycol |
name of the column loc.data with y-coordinates, default is "y" |
parsil |
partial sill of autocorrelation model, default = 1 |
range |
range of autocorrelation model, default = 1 |
nugget |
range of autocorrelation model, default = 0 |
minorp |
proportion of range in x direction to that of y direction for unrotated anisotropic model, default = 1 |
rotate |
rotation of anisotropic axes, default = 90 |
extrap |
extra covariance parameter |
CorModel |
autocorrelation model, default = "Exponential". Other possibilities are "Spherical". |
data.frame of three columns, the original location data appended with a 3rd column of simulated geostatistical data
Jay Ver Hoef
locations <- expand.grid(1:10, 1:10) geostatSim(locations, xcol = "Var1", ycol = "Var2", parsil = 4, range = 20, nugget = 1, CorModel = "Exponential")
locations <- expand.grid(1:10, 1:10) geostatSim(locations, xcol = "Var1", ycol = "Var2", parsil = 4, range = 20, nugget = 1, CorModel = "Exponential")
get.predinfo()
has been deprecated. Information given
is now provided in the basic print of a
predict.slmfit()
object. Creates a list of tables
that shows the prediction, standard error, and
confidence interval for the prediction, as well as some summary
information about the sample.
get.predinfo(x, conf_level = 0.9)
get.predinfo(x, conf_level = 0.9)
x |
the output of the |
conf_level |
is the confidence level for a normal-based confidence interval (default = 0.90). |
a list of three tables, including
simptab
, which contains the prediction and its
standard error,
confbounds
, which contains a confidence interval
for the prediction, and
outptmat
, a table of sampling information,
including the number of sites sampled, the total number of sites,
the total observed response, and the
observed average density (equal to the average response if all
site areas are equal).
data(exampledataset) ## load a toy data set slmobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset, xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') predobj <- predict(slmobj) ## Not Run ## get.predinfo(predobj)
data(exampledataset) ## load a toy data set slmobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset, xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') predobj <- predict(slmobj) ## Not Run ## get.predinfo(predobj)
Creates a default map for the predictions of unobserved sites.
Note that all predictions are stored in a data frame in the output of
predict.slmfit()
. Therefore, if a user
would like to create his or her own plot, he or she can easily do so using
this data frame.
get.predplot(x)
get.predplot(x)
x |
the output of the |
a plot with x-coordinates on the x-axis and y-coordinates on the y-axis that is coloured by predictions, with points with an X denoting that a site was sampled and filled circles denoting unsampled sites.
data(exampledataset) ## load a toy data set slmobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset, xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') predobj <- predict(slmobj) ## Not Run ## get.predplot(predobj)
data(exampledataset) ## load a toy data set slmobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset, xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') predobj <- predict(slmobj) ## Not Run ## get.predplot(predobj)
Computes the Generalized R-squared.
GR2(object)
GR2(object)
object |
is an object of class |
the value for generalized R-squared
data(exampledataset) ## load a toy data set slmobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset, xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') GR2(slmobj)
data(exampledataset) ## load a toy data set slmobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset, xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') GR2(slmobj)
Latitude and Longitude coordinates are converted to TM projection coordinates with a user-defined central meridian. The resulting units from applying the function are kilometers.
LLtoTM(cm, lat, lon, xcol = "x", ycol = "y", minx = NULL, miny = NULL)
LLtoTM(cm, lat, lon, xcol = "x", ycol = "y", minx = NULL, miny = NULL)
cm |
is the user defined central median. A common choice is the mean of the longitude values in your data set |
lat |
is the vector of latitudes |
lon |
is the vector of longitudes |
xcol |
is the name of the output TM column of x coordinates |
ycol |
is the name of the output TM column of y coordinates |
minx |
is 'NULL' by default and sets the minimum x-coordinate value to 0. This is an optional minimum value for the x-coordinate vector. |
miny |
is 'NULL' by default and sets the minimum y-coordinate value to 0. This is an optional minimum value for the y-coordinate vector. |
This function only should only be used if the coordinates supplied by the user are latitude and longitude. The default TM projection here specifies that both the minimum x and y-coordinate values are 0 scaled to 1 km.
A list with the TM coordinates as the first component of the list.
The first component of the list contains x coordinates in the first
column and y coordinates in the second column. The remaining elements of
the list are the cm
, minx
, and miny
values that
were input.
## Add transverse Mercator x and y coordinates to a data frame with ## latitude/longitude coordinates. exampledataset$xc_TM_ <- LLtoTM(cm = base::mean(exampledataset[ ,"xcoords"]), lat = exampledataset[ ,"ycoords"], lon = exampledataset[ ,"xcoords"])$xy[ ,1] exampledataset$yc_TM_ <- LLtoTM(cm = base::mean(exampledataset[ ,"xcoords"]), lat = exampledataset[ ,"ycoords"], lon = exampledataset[ ,"xcoords"])$xy[ ,2]
## Add transverse Mercator x and y coordinates to a data frame with ## latitude/longitude coordinates. exampledataset$xc_TM_ <- LLtoTM(cm = base::mean(exampledataset[ ,"xcoords"]), lat = exampledataset[ ,"ycoords"], lon = exampledataset[ ,"xcoords"])$xy[ ,1] exampledataset$yc_TM_ <- LLtoTM(cm = base::mean(exampledataset[ ,"xcoords"]), lat = exampledataset[ ,"ycoords"], lon = exampledataset[ ,"xcoords"])$xy[ ,2]
slmfit
objectExtract Log-Likelihood from a fitted class slmfit
object
loglik.slmfit(object, ...)
loglik.slmfit(object, ...)
object |
is a class |
... |
additional arguments |
the log-likelihood of the model fit in the slmfit
object
data(exampledataset) ## load a toy data set slmobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset, xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') loglik.slmfit(slmobj)
data(exampledataset) ## load a toy data set slmobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset, xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') loglik.slmfit(slmobj)
The primary purpose of m2LL.FPBK.nodet()
is to estimate
the spatial covariance parameters using REML. This is a helper
function to slmfit()
.
m2LL.FPBK.nodet(theta, zcol, XDesign, distmat, CorModel, estmethod)
m2LL.FPBK.nodet(theta, zcol, XDesign, distmat, CorModel, estmethod)
theta |
is the parameter vector of (nugget, partialsill, range) |
zcol |
is the response vector of densities |
XDesign |
is the design matrix containing the covariates used to predict animal or plant abundance (including a column of 1's for the intercept). |
distmat |
is the distance matrix of the sampled sites |
CorModel |
is the geostatistical spatial correlation model to
be used. See the |
estmethod |
is either "REML" for restricted maximum likelihood or "ML" for maximum likelihood. |
A numeric output of minus 2 times the restricted log likelihood to be minimized by 'optim' to obtain spatial parameter estimates.
Computes the generalized inverse of a matrix X. This function is used in
the m2LL.FPBK.nodet
functions in order
to estimate the spatial covariance parameters
mginv(X, tol = sqrt(.Machine$double.eps))
mginv(X, tol = sqrt(.Machine$double.eps))
X |
The matrix to be inverted |
tol |
The tolerance of the estimation |
The generalized inverse matrix
Creates a default map for the predictions of unobserved sites.
Note that all predictions are stored in a data frame in the output
of predict.slmfit()
. Therefore, if a user
would like to create his or her own plot, they can easily do so using
this data frame.
## S3 method for class 'predict.slmfit' plot(x, ...)
## S3 method for class 'predict.slmfit' plot(x, ...)
x |
the output of the |
... |
further arguments passed to or from other methods. |
a plot with x-coordinates on the x-axis and y-coordinates on the y-axis that is coloured by predictions, with points with an X denoting that a site was sampled and filled circles denoting unsampled sites.
data(exampledataset) ## load a toy data set slmobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset, xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') predobj <- predict(slmobj) plot(predobj)
data(exampledataset) ## load a toy data set slmobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset, xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') predobj <- predict(slmobj) plot(predobj)
Plots an empirical semi-variogram of the residuals from the spatial linear model with the fitted parametric model as a curve overtop of the binned points. By default, the empirical semi-variogram only shows distances that are less than or equal to the maximum distance in the data set divided by 2. Therefore, it's possible that the REML-fitted model will not "fit" the points perfectly.
## S3 method for class 'slmfit' plot(x, ...)
## S3 method for class 'slmfit' plot(x, ...)
x |
is an object of class |
... |
further arguments passed to or from other methods. |
a plot of the empirical semi-variogram with the fitted model overlayed.
data(exampledataset) ## load a toy data set slmobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset, xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') plot(slmobj) data(exampledataset) ## load a toy data set exampledataset$strata <- c(rep("A", 19), rep("B", 21)) strataobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset, stratacol = "strata", xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') plot(strataobj[[1]])
data(exampledataset) ## load a toy data set slmobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset, xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') plot(slmobj) data(exampledataset) ## load a toy data set exampledataset$strata <- c(rep("A", 19), rep("B", 21)) strataobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset, stratacol = "strata", xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') plot(strataobj[[1]])
simulates a completely spatially random point patterns. This function is only used in simulating data sets.
pointSimCSR( npoints = 100, lower_x_lim = 0, upper_x_lim = 1, lower_y_lim = 0, upper_y_lim = 1 )
pointSimCSR( npoints = 100, lower_x_lim = 0, upper_x_lim = 1, lower_y_lim = 0, upper_y_lim = 1 )
npoints |
number of points to add that are completely spatially random (CSR), default = 100 |
lower_x_lim |
left limit of boundary, default = 0 |
upper_x_lim |
right limit of boundary, default = 1 |
lower_y_lim |
lower limit of boundary, default = 0 |
upper_y_lim |
upper limit of boundary, default = 1 |
data.frame of two columns, x-coordinate in the first, and y-coordinate in the second.
Jay Ver Hoef
Creates a systematic grid of points. This function is only used in simulating data sets.
pointSimSyst( nrow = 10, ncol = 10, lower_x_lim = 0, upper_x_lim = 1, lower_y_lim = 0, upper_y_lim = 1 )
pointSimSyst( nrow = 10, ncol = 10, lower_x_lim = 0, upper_x_lim = 1, lower_y_lim = 0, upper_y_lim = 1 )
nrow |
the number of rows in the systematic grid, default is 10 |
ncol |
the number of cols in the systematic grid, default is 10 |
lower_x_lim |
the lower limit for x-coordinate, default is 0 |
upper_x_lim |
the upper limit for x-coordinate, default is 1 |
lower_y_lim |
the lower limit for y-coordinate, default is 0 |
upper_y_lim |
the upper limit for y-coordinate, default is 1 |
A data.frame with x- and y-coordinates of simulated locations
Jay Ver Hoef
Uses an object of class slmfit
from the slmfit()
function to predict the response on the unsampled sites.
The column of the data set that has the response should have
numeric values for the observed response on the sampled sites
and 'NA' for any site that was not sampled.
Note that there is no newdata
argument to
predict.slmfit()
: any point in space for which a prediction
is needed should be included in the original data set in
slmfit()
with the response variable as NA
.
## S3 method for class 'slmfit' predict(object, wtscol = NULL, conf_level = 0.9, ...)
## S3 method for class 'slmfit' predict(object, wtscol = NULL, conf_level = 0.9, ...)
object |
is an object generated from |
wtscol |
is the name of the column that contains the weights for prediction. The default setting predicts the population total |
conf_level |
is the confidence level for a prediction interval, 0.90 by default |
... |
further arguments passed to or from other methods. |
a list with
the estimated population total
the estimated prediction variance
a data frame containing
x-coordinates
y-coordinates
density predictions
count predictions
site-by-site density prediction variances
site-by-site count prediction variances
indicator variable for whether or not the each site was sampled
estimated mean for each site
area of each site
vector with estimated covariance parameters
the formula used to fit the model in slmfit()
the confidence level
the confidence interval bounds
data(exampledataset) ## load a toy data set slmobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset, xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') predict(slmobj)
data(exampledataset) ## load a toy data set slmobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset, xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') predict(slmobj)
Uses an object of class stratafit
from the stratafit()
function to predict the response on the unsampled sites for separate strata.
The column of the data set that has the response should have
numeric values for the observed response on the sampled sites and
'NA' for any site that was not sampled. Note that there is no
newdata
argument to predict.stratafit()
: any point in
space for which a prediction is needed should be included in the
original data set in stratafit()
with the response
variable as NA
.
## S3 method for class 'stratafit' predict(object, wtscol = NULL, conf_level = 0.9, ...)
## S3 method for class 'stratafit' predict(object, wtscol = NULL, conf_level = 0.9, ...)
object |
is an object generated from |
wtscol |
is the name of the column that contains the weights for prediction. The default setting predicts the population total |
conf_level |
by default, 0.90, this is the desired confidence level for a prediction interval |
... |
further arguments passed to or from other methods. |
a list with
the estimated population total
the estimated prediction variance
a data frame containing
x-coordinates
y-coordinates
density predictions
count predictions
site-by-site density prediction variances
site-by-site count prediction variances
indicator variable for whether or not the each site was sampled
estimated mean for each site
area of each site
vector with estimated covariance parameters
the formula used to fit the model in slmfit()
data(exampledataset) ## load a toy data set exampledataset$strata <- c(rep("A", 19), rep("B", 21)) strataobj <- stratafit(formula = counts ~ pred1 + pred2, data = exampledataset, stratacol = "strata", xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') predict(strataobj)
data(exampledataset) ## load a toy data set exampledataset$strata <- c(rep("A", 19), rep("B", 21)) strataobj <- stratafit(formula = counts ~ pred1 + pred2, data = exampledataset, stratacol = "strata", xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') predict(strataobj)
predict.slmfit()
function.This function uses the object that is output
from predict.slmfit()
of class predict.slmfit
.
## S3 method for class 'predict.slmfit' print(x, digits = max(3L, getOption("digits") - 3L), ...)
## S3 method for class 'predict.slmfit' print(x, digits = max(3L, getOption("digits") - 3L), ...)
x |
is a prediction object generated from |
digits |
is the number of digits to be displayed in the model output |
... |
further arguments passed to or from other methods. |
data(exampledataset) ## load a toy data set slmobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset, xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') print(predict(slmobj), digits = 4)
data(exampledataset) ## load a toy data set slmobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset, xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') print(predict(slmobj), digits = 4)
predict.stratafit()
function.This function uses the object that is output from
predict.stratafit()
of class predict.stratafit
.
## S3 method for class 'predict.stratafit' print(x, digits = max(3L, getOption("digits") - 3L), ...)
## S3 method for class 'predict.stratafit' print(x, digits = max(3L, getOption("digits") - 3L), ...)
x |
is a prediction object generated from
|
digits |
is the number of digits to be displayed in the model output |
... |
further arguments passed to or from other methods. |
a list with
a table of predictions, standard errors, and confidence intervals for each stratum and for the total.
data(exampledataset) ## load a toy data set exampledataset$strata <- c(rep("A", 19), rep("B", 21)) strataobj <- stratafit(formula = counts ~ pred1 + pred2, data = exampledataset, stratacol = "strata", xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') predict(strataobj)
data(exampledataset) ## load a toy data set exampledataset$strata <- c(rep("A", 19), rep("B", 21)) strataobj <- stratafit(formula = counts ~ pred1 + pred2, data = exampledataset, stratacol = "strata", xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') predict(strataobj)
This function uses the object that is output from
slmfit()
of class slmfit
.
## S3 method for class 'slmfit' print(x, digits = max(3L, getOption("digits") - 3L), ...)
## S3 method for class 'slmfit' print(x, digits = max(3L, getOption("digits") - 3L), ...)
x |
is an object generated from |
digits |
is the number of digits to be displayed in the model output |
... |
further arguments passed to or from other methods. |
a list with
model formula
summary statistics for the residuals.
a table of fixed effects estimates and associated standard errors.
estimated spatial covariance parameter estimates.
generalized r-squared value.
data(exampledataset) ## load a toy data set slmobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset, xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') print(slmobj)
data(exampledataset) ## load a toy data set slmobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset, xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') print(slmobj)
This function uses the object that is output from
summary.slmfit()
.
## S3 method for class 'summary.slmfit' print( x, digits = max(3L, getOption("digits") - 3L), signif.stars = getOption("show.signif.stars"), ... )
## S3 method for class 'summary.slmfit' print( x, digits = max(3L, getOption("digits") - 3L), signif.stars = getOption("show.signif.stars"), ... )
x |
is an summary object generated from
|
digits |
is the number of digits to be displayed in the model output |
signif.stars |
is an option to show which predictors are significant. |
... |
further arguments passed to or from other methods. |
a list with
model formula
summary statistics for the residuals.
a table of fixed effects estimates and associated standard errors.
estimated spatial covariance parameter estimates.
generalized r-squared value.
data(exampledataset) ## load a toy data set slmobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset, xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') print(summary(slmobj))
data(exampledataset) ## load a toy data set slmobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset, xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') print(summary(slmobj))
slmfit
object.Extract Model Residuals from an slmfit
object.
## S3 method for class 'slmfit' residuals(object, type = "raw", cross.validation = FALSE, ...)
## S3 method for class 'slmfit' residuals(object, type = "raw", cross.validation = FALSE, ...)
object |
a |
type |
residual type: |
cross.validation |
a logical ( |
... |
further arguments passed to or from other methods. |
a vector of residuals, consisting of each observed response/density minus the estimated mean, or, in the case of cross-validation, the observed response/density minus the leave-one-out-cross-validation prediction.
data(exampledataset) ## load a toy data set slmobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset, xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') residuals(slmobj) residuals(slmobj, cross.validation = TRUE)
data(exampledataset) ## load a toy data set slmobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset, xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') residuals(slmobj) residuals(slmobj, cross.validation = TRUE)
A simulated data set that can be used with the sptotal
package.
simdata
simdata
A data frame object including:
The x-coordinate for each site
The y-coordinate for each site
Simulated independent variable to be used as a predictor
Simulated independent variable to be used as a predictor
Simulated independent variable to be used as a predictor
Simulated independent variable to be used as a predictor
Simulated independent variable to be used as a predictor
Simulated spatially correlated random variable to be used as a predictor
Simulated spatially correlated random variable to be used as a predictor
Simulated factor variable to be used as a predictor
Simulated factor variable to be used as a predictor
The simulated response variable.
Prediction weights if estimating an overall mean
Prediction weights for estimating a total over a subset of 25 contiguous plots
data(simdata) names(simdata) summary(simdata)
data(simdata) names(simdata) summary(simdata)
Estimates regression coefficients and spatial autocorrelation parameters, given spatial coordinates and a model formula.
slmfit( formula, data, xcoordcol, ycoordcol, areacol = NULL, stratacol = NULL, CorModel = "Exponential", estmethod = "REML", covestimates = c(NA, NA, NA) )
slmfit( formula, data, xcoordcol, ycoordcol, areacol = NULL, stratacol = NULL, CorModel = "Exponential", estmethod = "REML", covestimates = c(NA, NA, NA) )
formula |
is an |
data |
is a data frame or tibble with the response column,
the covariates to be used for the block kriging, and the
spatial coordinates for all of the sites. Alternatively, data can be
an |
xcoordcol |
is the name of the column in the data frame with x coordinates or longitudinal coordinates |
ycoordcol |
is the name of the column in the data frame with y coordinates or latitudinal coordinates |
areacol |
is the name of the column with the areas of the sites. By default, we assume that all sites have equal area, in which case a vector of 1's is used as the areas. |
stratacol |
is the name of the the column with the stratification variable, if strata are to be fit separately, with different covariance parameter estimates. |
CorModel |
is the covariance structure. By default,
|
estmethod |
is either the default |
covestimates |
is an optional vector of covariance
parameter estimates (nugget, partial sill, range). If these are
given and |
a list of class slmfit
with
the spatial covariance estimates
the regression coefficient estimates
the covariance matrix of the fixed effects
minus two times the log-likelihood of the model
the names of the predictors
the sample size
the name of the covariance model used
a vector of residuals
the design matrix
a vector of the sampled densities
a list containing
formula, the model formula
data, the data set input as the data
argument
xcoordcol, the name of the x-coordinate column
ycoordcol, the name of the y-coordinate column
estmethod, either REML or ML
CorModel, the correlation model used
estimated covariance matrix of all sites
Inverted covariance matrix on the sampled sites
the vector of areas.
data(exampledataset) ## load a toy data set slmobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset, xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') summary(slmobj) data(exampledataset) ## load a toy data set exampledataset$strata <- c(rep("A", 19), rep("B", 21)) strataobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset, stratacol = "strata", xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') summary(strataobj)
data(exampledataset) ## load a toy data set slmobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset, xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') summary(slmobj) data(exampledataset) ## load a toy data set exampledataset$strata <- c(rep("A", 19), rep("B", 21)) strataobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset, stratacol = "strata", xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') summary(strataobj)
The package provides an option to perform FPBK on counts assuming perfect detection of counts on the sites that were in the survey sample. The functions in the package use methods in (Ver Hoef, 2008, <doi:10.1007/s10651-007-0035-y>)
sptotal
Main Functions:
slmfit
fits a spatial linear model to the response on the
observed/sampled sites.
predict.slmfit
uses the spatial linear model fit
from slmfit
and finite population block kriging to
predict the response at unobserved locations. A prediction for the
total response as well as a prediction variance are given by default.
Most of the remaining functions in the package are either helper functions
or extra optional functions to extract various specific things from an
slmfit
object, such as residuals, AIC, log-likelihood, etc.
See the Vignette for more details: browseVignettes("sptotal")
Reference for Mathematical Details:
Ver Hoef, Jay M. "Spatial methods for plot-based sampling of wildlife populations." A Environmental and Ecological Statistics 15, no. 1 (2008): 3-13.
Estimates regression coefficients and spatial autocorrelation
parameters, given spatial coordinates, a model formula, and a
stratification variable. Arguments are the same here as they are
for slmfit()
, with an extra argument for
stratacol
, the name of the stratification column. Note that
stratum can either by incorporated as a covariate in
slmfit()
, in which case the errors have the same
spatial covariance, or, models with differing spatial covariances
for the errors can be fit to each level of stratum, as is done here
in stratafit()
.
stratafit( formula, data, xcoordcol, ycoordcol, stratacol = NULL, areacol = NULL, CorModel = "Exponential", estmethod = "REML" )
stratafit( formula, data, xcoordcol, ycoordcol, stratacol = NULL, areacol = NULL, CorModel = "Exponential", estmethod = "REML" )
formula |
is an |
data |
is the data set with the response column, the covariates to be used for the block kriging, and the spatial coordinates for all of the sites. |
xcoordcol |
is the name of the column in the data frame with x coordinates or longitudinal coordinates |
ycoordcol |
is the name of the column in the data frame with y coordinates or latitudinal coordinates |
stratacol |
is the name of the stratification column |
areacol |
is the name of the column with the areas of the sites. By default, we assume that all sites have equal area, in which case a vector of 1's is used as the areas. |
CorModel |
is the covariance structure. By default, |
estmethod |
is either the default |
a list of class slmfit
with
the spatial covariance estimates
the regression coefficient estimates
the covariance matrix of the fixed effects
minus two times the log-likelihood of the model
the names of the predictors
the sample size
the name of the covariance model used
a vector of residuals
the design matrix
a vector of the sampled densities
a list containing
formula, the model formula
data, the data set input as the data
argument
xcoordcol, the name of the x-coordinate column
ycoordcol, the name of the y-coordinate column
estmethod, either REML or ML
CorModel, the correlation model used
estimated covariance matrix of all sites
Inverted covariance matrix on the sampled sites
the vector of areas.
data(exampledataset) ## load a toy data set exampledataset$strata <- c(rep("A", 19), rep("B", 21)) strataobj <- stratafit(formula = counts ~ pred1 + pred2, data = exampledataset, stratacol = "strata", xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') summary(strataobj)
data(exampledataset) ## load a toy data set exampledataset$strata <- c(rep("A", 19), rep("B", 21)) strataobj <- stratafit(formula = counts ~ pred1 + pred2, data = exampledataset, stratacol = "strata", xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') summary(strataobj)
In conjunction with print.summary.slmfit()
, the output looks similar
to output from R
's standard lm()
function.
## S3 method for class 'slmfit' summary(object, ...)
## S3 method for class 'slmfit' summary(object, ...)
object |
is an object generated from |
... |
further arguments passed to or from other methods. |
a list with
model formula
a table of fixed effects estimates and associated standard errors
estimated spatial covariance parameter estimates
residuals
generalized r-squared.
data(exampledataset) ## load a toy data set slmobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset, xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') summary(slmobj)
data(exampledataset) ## load a toy data set slmobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset, xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') summary(slmobj)
If a model is fitted with stratafit()
, then
this summary function produces summary output for each level
of the stratification variable in the same style as the
summary.slmfit()
function.
## S3 method for class 'stratafit' summary(object, ...)
## S3 method for class 'stratafit' summary(object, ...)
object |
is an object generated from |
... |
further arguments passed to or from other methods. |
a list with
model formula
a table of fixed effects estimates and associated standard errors
estimated spatial covariance parameter estimates
residuals
generalized r-squared.
data(exampledataset) ## load a toy data set exampledataset$strata <- c(rep("A", 25), rep("B", 15)) strataobj <- stratafit(formula = counts ~ pred1 + pred2, data = exampledataset, stratacol = "strata", xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') summary(strataobj)
data(exampledataset) ## load a toy data set exampledataset$strata <- c(rep("A", 25), rep("B", 15)) strataobj <- stratafit(formula = counts ~ pred1 + pred2, data = exampledataset, stratacol = "strata", xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') summary(strataobj)
Compute the empirical semivariogram for a data set with specified x and y spatial coordinates and residuals.
sv(data, xcoordcol, ycoordcol, residcol, bins = 15, cutoff = NULL, ...)
sv(data, xcoordcol, ycoordcol, residcol, bins = 15, cutoff = NULL, ...)
data |
A data frame or tibble that contains variables for the x coordinates, y coordinates, and residuals. |
xcoordcol |
is the name of the column in the data frame with x coordinates or longitudinal coordinates |
ycoordcol |
is the name of the column in the data frame with y coordinates or latitudinal coordinates |
residcol |
is the name of the column in the data frame with residuals. |
bins |
Number of equally spaced semivariogram bins. The default is 15. |
cutoff |
The maximum spatial distance to be considered. The default is half of the maximum observed distance in the data frame. |
... |
Additional arguments to be used by |
A data frame with the average distance in each bin (dist), the semivariance (gamma), and the number of unique pairs in each bin (np)
data(exampledataset) ## load a toy data set slmobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset, xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') sampleddataset <- na.omit(exampledataset) svexample <- data.frame( xcoords = sampleddataset$xcoords, ycoords = sampleddataset$ycoords, resids = residuals(slmobj) ) svdata <- sv(svexample, "xcoords", "ycoords", "resids")
data(exampledataset) ## load a toy data set slmobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset, xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar') sampleddataset <- na.omit(exampledataset) svexample <- data.frame( xcoords = sampleddataset$xcoords, ycoords = sampleddataset$ycoords, resids = residuals(slmobj) ) svdata <- sv(svexample, "xcoords", "ycoords", "resids")
These data contain dissolved organic carbon (DOC) in National Lakes Data from the U.S. Environmental Protection Agency
USlakes
USlakes
A data frame with 1206 rows and 9 variables:
x-coordinate from US Contiguous Albers Equal Area Conic projection
y-coordinate from US Contiguous Albers Equal Area Conic projection
Analyte value, in mg/L, for Dissolved Organic Carbon
Elevation at lake coordinates (LAT_DD_N83, LON_DD_N83) from NHD Digital Elevation Map layer
Fish cover: index of fish cover due to large structures in the littoral zone
riparian zone and vegetation: fraction of ground lacking cover in the riparian zone
riparian zone and vegetation: fraction of ground cover by woody vegetation in the riparian zone
riparian zone and vegetation: fraction of understory with nonwoody cover present in the riparian zone
A unique lake identifier in the EPA lake survey databases
National Aquatic Resource Surveys webpage. We combined site data, DOC data, and habitat metrics to create a data set of 1206 lakes in the conterminous United States.
data(USlakes) names(USlakes) summary(USlakes)
data(USlakes) names(USlakes) summary(USlakes)