downscale | R Documentation |
Performs downscaling of land-use data over specified time steps using a range of inputs, including targets, areas, explanatory variables, and priors. It supports both bias correction and non-targeted downscaling methods.
downscale(
targets,
start.areas,
times = NULL,
xmat = NULL,
betas = NULL,
areas.update.fun = areas.sum_to,
xmat.coltypes = NULL,
xmat.proj = NULL,
xmat.dyn.fun = xmat.sum_to,
priors = NULL,
restrictions = NULL,
options = downscale_control()
)
targets |
A dataframe with mandatory columns: |
start.areas |
A dataframe with starting areas. Includes mandatory columns: |
times |
A character vector of time steps for downscaling. The first time step must be present in |
xmat |
A dataframe with explanatory variables for econometric priors. Includes columns: |
betas |
A dataframe of coefficients for econometric priors. Includes columns: |
areas.update.fun |
A function providing an update for dynamic xmat columns. Takes as arguments |
xmat.coltypes |
A vector |
xmat.proj |
A dataframe with projections. Includes columns: |
xmat.dyn.fun |
A function providing updates for dynamic xmat columns. Takes as arguments |
priors |
A dataframe with exogenous priors. Includes columns: |
restrictions |
A dataframe with restrictions. Includes columns: |
options |
A list of solver options. Use |
The function integrates various data inputs to match p
targets using either projections from an MNL-type model or exogenous priors. Appropriate input validation and preprocessing are performed before downscaling.
A list containing three elements:
out.res
: A dataframe with columns times
, ns
, lu.from
, lu.to
, and value
(area allocation).
out.solver
: A list detailing the solver output.
ds.inputs
: A list documenting all the inputs used in the downscaling function.
require(dplyr)
require(tidyr)
require(tibble)
betas = NULL
for (jj in unique(argentina_luc$lu.from)) {
Y = dplyr::filter(argentina_luc,lu.from == jj & Ts == 2000) %>%
pivot_wider(names_from = lu.to)
X = argentina_df$xmat %>% tidyr::pivot_wider(names_from = "ks") %>%
dplyr::arrange(match(ns,Y$ns))
Y = Y %>% dplyr::select(-c(lu.from,Ts,ns))
X = X %>% dplyr::select(-c(ns))
res1 <- mnlogit(as.matrix(X), as.matrix(Y),baseline = which(colnames(Y) == jj),
niter = 3,nburn = 2)
betas = betas %>% dplyr::bind_rows(
apply(res1$postb, c(1, 2), mean) %>%
as.data.frame() %>% tibble::rownames_to_column("ks") %>%
pivot_longer(cols = -c(1),names_to = "lu.to") %>%
dplyr::mutate(lu.from = jj,.before="lu.to")
)
}
ns = unique(argentina_df$lu_levels$ns)
priors = data.frame(ns = as.character(ns),lu.from="Cropland",
lu.to="Forest",value = as.numeric(runif(length(ns))))
res1 = downscale(targets = argentina_FABLE %>% dplyr::filter(times == "2010"),
start.areas = argentina_df$lu_levels,
xmat = argentina_df$xmat,
betas = betas %>% dplyr::filter(lu.from!="Cropland" | lu.to!="Forest"),
priors = priors)
dgp1 = sim_luc(1000,tt = 3)
res1 = downscale(targets = dgp1$targets,start.area = dgp1$start.areas,
xmat = dgp1$xmat,betas = dgp1$betas,times = c(1:3))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.