Skip to contents

calc_all_lscps() calculates adaptive landscapes from a set of kriged surfaces of functional characteristics and sets of weights for those characteristics.

Usage

calc_all_lscps(kr_data, grid_weights, file = NULL)

Arguments

kr_data

a kriged_surfaces object; the output of a call to krige_surf.

grid_weights

a grid_weights object; the output of a call to generate_weights.

file

the path of a file to save the resulting output object, which may be quite large. The file path should contain an .rds or .rdata extension, which will be saved using saveRDS or save, respectively. See Details on how to load these files after saving them.

Details

calc_all_lscps() computes a combined adaptive landscape for each of the supplied sets of weights. The optimal landscape overall or for certain subsets of the sample data can be found using calcGrpWprime or calcWprimeBy. calc_lscp can be used to extract the surface of the weighted functional characteristics for each set of weights (see Examples).

Because the resulting objects are so large, it can be a good idea to save them after creation, which can be done automatically using the file argument. If the supplied file extension is .rds, saveRDS will be used to save the object to the supplied file path, and the file can be loaded using readRDS. If the supplied file extension is .RData, save will be used to save the object to the supplied file path, and the file can be loaded using load.

Value

An all_lscps object containing the following components:

dataframe

a list of the grid and new_data data frames stored in kr_data.

wtd_lscps

a list containing the weightred fitness values for each set of weights for the grid and new_data datasets. These are stored in matrices with a row for each data point in grid and new_data and a column for each set of weights.

grid_weights

the grid_weights object supplied to grid_weights.

See also

calc_lscp for computing a single weighted landscape or extracting the weighted surface of functional characteristics for a single set of weights.

generate_weights for generating the required matrix of weights.

calcGrpWprime and calcWprimeBy for finding optimal sets of weights and adaptive landscapes for subgroups.

Examples

data("warps")
data("turtles")

warps_fnc <- as_fnc_df(warps, 
                       func.names = c("hydro", "fea"))

kr_surf <- krige_surf(warps_fnc, new_data = turtles)
#> [using ordinary kriging]
#> [using ordinary kriging]
#> [using ordinary kriging]
#> [using ordinary kriging]

grid_weights <- generate_weights(n = 20, data = kr_surf)
#> 21 rows generated

all_lscps <- calc_all_lscps(kr_surf,
                            grid_weights = grid_weights)
all_lscps
#> An all_lscps object
#> - functional characteristics:
#> 	hydro, fea
#> - number of landscapes:
#> 	21
#> - weights incremented by:
#> 	0.05
#> - new data:
#> 	40 rows

# Extract the weighted surface for a single set
# of weights (here, the 6th set of weights)

grid_weights[6,]
#> hydro   fea 
#>  0.75  0.25 

wtd_lscp_6 <- calc_lscp(all_lscps, i = 6)
wtd_lscp_6
#> A wtd_lscp object
#> - weights:
#> hydro   fea 
#>  0.75  0.25 
#> - new data:
#> 	40 rows
#> 	average Z = 0.623

# This aligns with the weighted fitness value:
mean(all_lscps$wtd_lscps$new_data[,6])
#> [1] 0.6226965