Description Usage Arguments Details Value See Also Examples
uhcsimXvalid
samples, randomly, locations from non-stratified
test data using k-fold cross validation.
1 2 | uhcsimXvalid(data_sim, k_folds, nsims, nused, navail, ncovariates,
model_form, z_colnames, xmat_colnames)
|
data_sim |
The data set to be used in cross-validation |
k_folds |
The number of bins to split data into |
nsims |
The number of simulations (M) used to create the UHC plot. |
nused |
The number of used locations in the data set. |
navail |
The number of available locations in the data set (ie not used) |
ncovariates |
The number of covariates or p in the model |
model_form |
The model in the form: "y~x1+x2+...+xp" (including quotations) |
z_colnames |
The column names of the environmental characteristics to
be plotted with |
xmat_colnames |
The column names of the environmental characteristics that were used as predictors in the model_form. Takes the form: c("x1","x2",...,"xp") |
This function samples, randomly, locations from non-stratified test data and returns an array of dimension nsims x nused_test x p (where p is the number of predictors to be validated)
An array of dimensions nsims x nused_test x p.
Full archive of the data and code necessary to replicate the manuscript at http://doi.org/10.13020/D6T590.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | # Simulate data using uhcplots::uhcdatasimulator
data_sim <- uhcdatasimulator(nused = 100,
navail = 10000,
betas = c(0.5, -1) ,
corx = 0,
ntemp = 100000,
example = "missing predictor")
#Set up parameters
# Number of used and available locations in dataset
used <- data_sim[data_sim$y==1,]; nused <- nrow(used)
avail <- data_sim[data_sim$y==0,]; navail <- nrow(avail)
## k-fold cross validation
#**Step 1** Partition data into k-fold bins
k_folds <- 10
nused_k <- nused/k_folds
navail_k <- navail/k_folds
data_sim$k <- dismo::kfold(data_sim, k = k_folds, by = data_sim$y)
table(data_sim$k)
#**Step 2** Fit a model (in this case, missing precipitation)
# Set up some parameters
nsims <- 1000 # M from paper;
ncovariates <- 2;
model_form_missingP <- "y~elev"
z_colnames <- c("elev","precip")
xmat_colnames_missingP <- c("elev")
# Create an array to store chosen location covariates for each simulation
# and each k-fold "test" data bin
x_sim_choice_missingP <- array(NA, dim = c(nsims, nused, ncovariates))
# Get predicted distribution of covariates for each fold, k:
x_sims_choice_missingP <- uhcplots::uhcsimXvalid(data_sim = data_sim,
k_folds = k_folds,
nsims = nsims,
nused = nused,
navail = navail,
ncovariates = ncovariates,
model_form = model_form_missingP,
z_colnames = z_colnames,
xmat_colnames = xmat_colnames_missingP)
# **Step 3** Density calculations
denscalc_elev_missingP <- uhcdenscalc(rand_sims = x_sims_choice_missingP[,,1],
dat = used[,"elev"],
avail = avail[,"elev"],
gridsize = 500)
denscalc_prec_missingP <- uhcdenscalc(rand_sims = x_sims_choice_missingP[,,2],
dat = used[,"precip"],
avail = avail[,"precip"],
gridsize = 500)
# **Step 4** Create UHC plots for each covariate
opar<-par()
layout(matrix(c(1,2,3,3), ncol=2, byrow=TRUE), heights=c(4,1))
par(mai=rep(0.5, 4))
uhcdensplot(densdat = denscalc_elev_missingP$densdat,
densrand = denscalc_elev_missingP$densrand,
includeAvail = TRUE,
densavail = denscalc_elev_missingP$densavail,includeLegend = FALSE)
mtext(outer=FALSE, side=1, line = 3, "Elevation")
uhcdensplot(densdat = denscalc_prec_missingP$densdat,
densrand = denscalc_prec_missingP$densrand,
includeAvail = TRUE,
densavail = denscalc_prec_missingP$densavail,
includeLegend = FALSE)
mtext(outer=FALSE, side=1, line= 3, "Precipitation")
par(mai=c(0,0,0,0))
plot.new()
legend("center",c("Available", "Used", "Predicted"), lty = c(1,2,1),
col = c("black", "red", "grey"), bty = "n", lwd = c(1,1,5))
par<-opar
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.