Learn R Programming

VizTest (version 0.3)

make_vt_data: Make custom visual testing data

Description

Makes custom visual testing objects that can be used as input to the viztest() function. This is useful in the case where coef() and vcov() do not function as expected on objects of interest, where the user wants to intervene with some modification to the usual estimates or (more likely) variance-covariance matrix or where normal theory tests may not be as useful (e.g., in the case of simulations of non-normal values). The examples section below shows how this could be leveraged to use a heteroskedasticity-consistent covariance matrix in the test rather than the one returned by lm().

Usage

make_vt_data(estimates, variances = NULL, type = c("est_var", "sim"), ...)

Value

An object of class "vtcustom" that takes one of two forms:

  1. A list with estimates and a variance-covariance matrix. In this case, the functionms coef.vtcustom() and vcov.vtcustom() are used to extract the coefficients and variance-covariance matrix in a way that will work with viztest.default().

  2. An object of class "vtsim" that has a single element - the data giving the draws from the simulation.

Arguments

estimates

A vector of estimates if type is "est_var" and or a number of simulations by number of parameters matrix of simulated values if type is "sim".

variances

In the case of independent estimates, a vector of variances of the same length as estimates if type is "est_var". These will be used as the diagonal elements in a variance-covariance matrix with zero covariances. Alternatively, if type is "est_var", this could be a variance-covariance matrix, with the same number of rows and columns as there are elements in the estimates vector. If type is "sim", variances should be NULL, but will be disregarded in any event. Also, note, these should be variances of the estimates (e.g., squared standard errors) and not raw variances from the data.

type

Indicates the type of input data either estimates with variances or a variance-covariance matrix or data from a simulation.

...

Other arguments passed down, currently not implemented.

Examples

Run this code
data(mtcars)
mtcars$cyl <- as.factor(mtcars$cyl)
mtcars$hp <- scale(mtcars$hp)
mtcars$wt <- scale(mtcars$wt)
mod <- lm(qsec ~ hp + wt + cyl, data=mtcars)
V <- sandwich::vcovHC(mod, "HC3")
vtdat <- make_vt_data(coef(mod), V)
viztest(vtdat, 
        test_level = .025, 
        include_intercept = FALSE, 
        include_zero = FALSE)

Run the code above in your browser using DataLab