movement: Create an optimised movement model

View source: R/movement.R

movementR Documentation

Create an optimised movement model

Description

Uses the optim method to create an optimised model of population movements.

Usage

movement(formula, flux_model = gravity(), go_parallel = FALSE,
  number_of_cores = NULL, ...)

Arguments

formula

A formula with one response (a movement_matrix object) and one predictor (a location_dataframe object), e.g. movement_matrix ~ location_dataframe. The location_dataframe object contains location data and the movement_matrix object contains the observed population movements.

flux_model

The name of the movement model to use. Currently supported models are originalRadiation, radiationWithSelection, uniformSelection, interveningOpportunities, gravity and gravityWithDistance

go_parallel

Flag to enable parallel calculations (if set to TRUE). Note that parallel programming will only improve the performance with larger datasets; for smaller datasets the performance will get worse due to the overhead of scheduling the tasks.

number_of_cores

Optional parameter to specify the number of cores used for parallel calculations. If no value is specified, the program will automatically detect the number of cores available on the machine when parallel programming is enabled.

...

Extra parameters to be passed to the prediction code.

Value

An optimisedmodel object containing the training results, and the optimisation results.

Note

The movement_matrix must contain integer values. If the input object contains non-integer values, the function will use rounding to return a valid matrix and display a warning to inform the user of this additional rounding.

The format of the location data must be as a single data.frame with the columns location, population, lat and long. This can be extracted from a larger dataframe with as.location_dataframe The movement_matrix can be extracted from a list of movements using as.movement_matrix. To check that the given objects are suitable, the helper functions is.location_dataframe and is.movement_matrix can be used.

See Also

as.location_dataframe, is.location_dataframe, as.movement_matrix, is.movement_matrix, originalRadiation, radiationWithSelection, uniformSelection, interveningOpportunities, gravity and gravityWithDistance

Examples

## Not run: 
# get location data
data(kenya)
kenya10 <- raster::aggregate(kenya, 10, sum)
net <- getNetwork(kenya10, min = 50000)
location_data <- data.frame(location = net$locations,
                           population = net$population,
                           x = net$coordinate[,1],
                           y = net$coordinate[,2])
location_data  <- as.location_dataframe(location_data)
# simulate movements (note the values of movementmatrix must be integer)
predicted_flux  <- predict(radiationWithSelection(theta = 0.5), location_data, symmetric = TRUE)
movement_matrix <- round(predicted_flux$movement_matrix)
# fit a new model to these data
movement_model <- movement(movement_matrix ~ location_data, radiationWithSelection(theta = 0.5))
# print movement_model
print(movement_model)
# predict the population movements
predicted_movements  <- predict(movement_model, kenya10)
# display the predicted movements
plot(predicted_movements)

## End(Not run)

SEEG-Oxford/movement documentation built on April 17, 2023, 4:17 p.m.