supplant_new_data: Supplant data in fitted object with new data for the purposes...

View source: R/supplant_with_new_data.R

supplant_new_dataR Documentation

Supplant data in fitted object with new data for the purposes of predicting on new data

Description

Supplant data in fitted object with new data for the purposes of predicting on new data

Usage

supplant_new_data(
  fit,
  Xocc,
  Xobs = NULL,
  ModelSite = NULL,
  y = NULL,
  toXocc = NULL,
  toXobs = NULL,
  ...
)

Arguments

fit

Fitted object

Xocc

A dataframe of covariates related to occupancy. One row per ModelSite. Must also include the ModelSiteVars columns to uniquely specify ModelSite.

Xobs

A dataframe of covariates related to observations. One row per visit. Each column is a covariate. Must also include the ModelSiteVars columns to uniquely specify ModelSite.

ModelSite

A vector of integers of equal length to the number of visits. Each entry species for the corresponding visit, the of Xocc that was visited

y

A dataframe of species observations (1 or 0). Each column is a species. Rows must correspond to Xobs

toXocc

NULL to use a process saved by sflddata::save_process, otherwise a function that takes Xocc as the only input and returns a model matrix for the occupancy component.

toXobs

like toXocc, except for Xobs and the detection component of the model.

Examples

fitold <- readRDS("../Experiments/7_4_modelrefinement/fittedmodels/7_4_13_model_2lv_e13.rds")
fit <- translatefit(fitold)
originalXocc <- unstandardise.designmatprocess(fit$XoccProcess, fit$data$Xocc)
originalXocc <- cbind(ModelSite = 1:nrow(originalXocc), originalXocc)
originalXobs <- unstandardise.designmatprocess(fit$XobsProcess, fit$data$Xobs)
originalXobs <- cbind(ModelSite = fit$data$ModelSite, originalXobs)
Xocc <- originalXocc[1:10, ]
Xobs <- originalXobs[originalXobs$ModelSite %in% Xocc$ModelSite, ]
y <- fit$data$y[originalXobs$ModelSite %in% Xocc$ModelSite, ]
ModelSite <- as.integer(Xobs$ModelSite)
fitwnewdata <- supplant_new_data(fit, Xocc, Xobs, ModelSite = ModelSite, y = y)
ds_detection_residuals.fit(fitwnewdata) #detection residuals on this new data
ds_occupancy_residuals.fit(fitwnewdata) #detection residuals on this new data

fitwnewdata <- supplant_new_data(fit, Xocc)


sustainablefarms/msod documentation built on March 6, 2023, 7:17 a.m.