gvifs_lm: Compute VIF using CAR package

Description Usage Arguments Examples

View source: R/vif_analysis.R

Description

Compute VIF using CAR package

Usage

1
gvifs_lm(Xocc, yXobs, species, ModelSite, OccFmla = "~ 1", ObsFmla = "~ 1")

Arguments

Xocc

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

yXobs

A dataframe of species observations (1 or 0) and covariates related to observations. One row per visit. Each column is either a covariate or a species. Must also include the ModelSiteVars columns to uniquely specify ModelSite.

species

A list of species names (corresponding to columns of yXobs) to model.

ModelSite

A list of column names in y, Xocc and Xobs that uniquely specify the ModelSite. Can be simply a ModelSite index

OccFmla

A formula specifying the occupancy model in terms of the covariates in Xocc.

ObsFmla

A formula specifying the model for detection in terms of the covariates in Xobs.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
inputdata <- readRDS("./private/data/clean/7_2_10_input_data.rds")

OccFmla <- reformulate(paste0("\`",setdiff(names(inputdata$insample$Xocc), c("ModelSiteID", "SiteCode", "SurveySiteId", "StudyId", "holdout", "gc", "AnnTempRange")), "\`"))
ObsFmla <- "~ 1 + MeanWind + MeanTime + MeanClouds + MeanTemp"
vifs <- gvifs_lm(inputdata$insample$Xocc,
         inputdata$insample$yXobs,
         species = inputdata$species,
         ModelSite = "ModelSiteID",
         OccFmla = OccFmla,
         ObsFmla = ObsFmla
         )

vifs[[1]] %>%
  tibble::enframe(name = "var", value = "vif") %>%
  arrange(vif) %>%
  ggplot() +
  geom_point(aes(y = var, x = vif)) +
  geom_vline(xintercept = 30)

sustainablefarms/linking-data documentation built on Oct. 28, 2020, 2:41 a.m.