movement | R Documentation |
Uses the optim
method to create an optimised model of
population movements.
movement(formula, flux_model = gravity(), go_parallel = FALSE,
number_of_cores = NULL, ...)
formula |
A formula with one response (a |
flux_model |
The name of the movement model to use. Currently supported
models are |
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. |
An optimisedmodel
object containing the training results,
and the optimisation results.
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.
as.location_dataframe
, is.location_dataframe
,
as.movement_matrix
, is.movement_matrix
, originalRadiation
,
radiationWithSelection
, uniformSelection
,
interveningOpportunities
, gravity
and gravityWithDistance
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.