whatif: Counterfactual evaluation

Description Usage Arguments Value References See Also

Description

Implements the methods described in King and Zeng (2007) for evaluating counterfactuals. This function is a duplicate of the whatif function from the Whatif package (GPL >= 3 license).

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
whatif(
  formula = NULL,
  data,
  cfact,
  range = NULL,
  freq = NULL,
  nearby = 1,
  distance = "gower",
  miss = "list",
  choice = "both",
  return.inputs = FALSE,
  return.distance = FALSE,
  mc.cores = 2,
  verbose = TRUE,
  ...
)

Arguments

formula

An optional formula without a dependent variable that is of class "formula" and that follows standard R conventions for formulas, e.g. ~ x1 + x2. Allows you to transform or otherwise re-specify combinations of the variables in both data and cfact. To use this parameter, both data and cfact must be coercable to a data.frame; the variables of both data and cfact must be labelled; and all variables appearing in formula must also appear in both data and cfact. Otherwise, errors are returned. The intercept is automatically dropped. Default is NULL.

data

Either a model output object, or a n-by-k non-character (logical or numeric) matrix or data frame of observed covariate data with n data points or units and k covariates.

cfact

A R object or a string. If a R object, a m-by-k non-character matrix or data frame of counterfactuals with m counterfactuals and the same k covariates (in the same order) as in data. However, if formula is used to select a subset of the k covariates, then cfact may contain either only these j <= K covariates or the complete set of k covariates. An intercept should not be included as one of the covariates. Data frames will again be coerced to their internal numeric values if possible. If a string, either the complete path (including file name) of the file containing the counterfactuals or the path relative to your working directory. This file should be a white space delimited text file.

nearby

An optional scalar indicating which observed data points are considered to be nearby (i.e., withing ‘nearby’ geometric variances of) the counterfactuals. Used to calculate the summary statistic returned by the function: the fraction of the observed data nearby each counterfactual. By default, the geometric variance of the covariate data is used. For example, setting nearby to 2 will identify the proportion of data points within two geometric variances of a counterfactual. Default is NULL.

choice

An optional string indicating which analyses to undertake. The options are either "hull", only perform the convex hull membership test; "distance", do not perform the convex hull test but do everything else, such as calculating the distance between each counterfactual and data point; or "both", undertake both the convex hull test and the distance calculations (i.e., do everything). Default is "both".

verbose

Logical. Show or hide possible warnings and messages.

Value

An object of class "whatif".

References

Gandrud C, King G, Stoll H, Zeng L (2017). WhatIf: Evaluate Counterfactuals. R package version 1.5-9. https://CRAN.R-project.org/package=WhatIf.

King G, Zeng L (2007). When can history be our guide? The pitfalls of counterfactual inference. International Studies Quarterly 51, 183–210. DOI: 10.1111/j.1468-2478.2007.00445.x

See Also

compute_nearby


densitymodelling/dsmextra documentation built on Feb. 12, 2022, 4:40 a.m.