fit.ipw: fit.ipw

Description Usage Arguments Author(s) Examples

Description

Estimate inverse probability weights using logistic regression

Usage

1
fit.ipw(tr.c, tr.y)

Arguments

tr.c

Matrix or data.frame of confounders

tr.y

Vector of group labels for training

Author(s)

Kristin Linn

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
if (require(MASS)){
##################################################
# Generate data
##################################################
set.seed(1)
# Total in confounded sample
n = 200
# Number of noise features
k = 10
# a1 and a2 are confounders
a1 = runif (n, 0, 1)
a2 = rbinom(n, 1, .5)
# d is a vector of class labels
ld = -1 + a1 + a2 + rnorm(n, 0, .5)
d = 1*(exp(ld)/(1+exp(ld))>.5)
# covariance structure for features
# x1 and x2 are
covmat = matrix (c (2, .5, .5, 2), 2, 2)
errs = MASS::mvrnorm (n, mu=rep (0, 2), Sigma=covmat)
# x1 and x2 are features
x1mean = 5 - 2*d - .5*a1
x2mean = -3*a1 + .5*a2 - .5*d*(a1 + .5*a2 + .25*a1*a2)
x1 = scale(x1mean + errs[,1])
x2 = scale(x2mean + errs[,2])
noise = matrix (rnorm(n*k), n, k)
features = data.frame(x1=x1, x2=x2, noise=noise)
}

kalinn/weightedSVM documentation built on May 20, 2019, 6:33 a.m.