makeK: Build the Gaussian Kernel Matrix

View source: R/functions.R

makeKR Documentation

Build the Gaussian Kernel Matrix

Description

Builds the Gaussian kernel matrix using Rcpp.

Usage

makeK(allx, useasbases = NULL, b = NULL, linkernel = FALSE, scale = TRUE)

Arguments

allx

A data matrix containing all observations where rows are units and columns are covariates.

useasbases

Vector argument containing one's and zero's with length equal to the number of observations (rows in allx) to specify which bases to use when constructing the kernel matrix (columns of K). If not specified, the default is to use all observations.

b

Scaling factor in the calculation of Gaussian kernel distance equivalent to the entire denominator 2\sigma^2 of the exponent. Default is twice the number of covariates or columns in allx.

linkernel

Indicates that user wants linear kernel, K=XX', which in practice employs K=X.

scale

boolean flag for whether or not to standardize allx (demeaned with sd=1) before constructing the kernel matrix

Value

K

The kernel matrix

Examples

#load and clean data a bit

data(lalonde)
xvars=c("age","black","educ","hisp","married","re74","re75","nodegr","u74","u75")

#note that lalonde$nsw is the treatment vector, so the observed is 1-lalonde$nsw
#running makeK with the sampled/control units as the bases given 
#the large size of the data
K = makeK(allx = lalonde[,xvars], useasbases = 1-lalonde$nsw) 


chadhazlett/KBAL documentation built on Jan. 3, 2024, 9:57 p.m.