cverrors: Estimate matching errors

Description Usage Arguments Value Author(s) Examples

View source: R/loocv.R

Description

Use the output from loocv to estimate matching errors for each output variable

Usage

1
cverrors(loocv_output = NULL, first_output_column = NULL)

Arguments

loocv_output

a data frame produced by the loocv function.

first_output_column

numeric. The column number of the first column in the loocv_output data frame that contains loocv differences in output variables (should usually be 6 or 8 for one- and two-step matching).

Value

a named vector where items are the estimated matching error for each output variable calculated using leave-one-out cross validation of the Subset cells (simulated sites).

Author(s)

Rachel R. Renne

Examples

 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
########################
# An example where secondarymatch = FALSE
# Load targetcells data for Target Cells
data(targetcells)

# Create data frame of potential matching variables for Target Cells
allvars <- makeInputdata(targetcells)

# Restrict data to matching variables of interest
matchingvars <- allvars[,c("cellnumbers","x","y","bioclim_01","bioclim_04",
                        "bioclim_09","bioclim_12","bioclim_15","bioclim_18")]

# Create vector of matching criteria
criteria <- c(0.7,42,3.3,66,5.4,18.4)

# Create raster template
raster_template = targetcells[[1]]

# Find solution for k = 200
# Note: n_starts should be >= 10, it is 1 here to reduce run time.
results1 <- kpoints(matchingvars,criteria = criteria,klist = 200,
                    n_starts = 1,min_area = 50,iter = 50,
                    raster_template = raster_template)

# Get points from solution to kpoints algorithm
subsetcells <- results1$solutions[[1]]

# Create a mock dataset of output results
output_results <- allvars[rownames(subsetcells),c("cellnumbers","bioclim_02",
                                                  "bioclim_03","bioclim_16",
                                                  "bioclim_17")]

# Create dataset of matchingvars for subsetcells
subset_matchingvars <- matchingvars[rownames(subsetcells),-1]

# Run leave-one-out cross validation of mock output results
loocv_results <- loocv(matchingvars = subset_matchingvars,
                       output_results = output_results,
                       criteria1 = criteria,
                       secondarymatch = FALSE, n_neighbors = 2)

# Calculate estimates of matching error for output variables
estimated_errors <-  cverrors(loocv_output = loocv_results,
first_output_column = 6)

DrylandEcology/rMultivariateMatching documentation built on Dec. 17, 2021, 5:30 p.m.