Learn R Programming

DTRlearn (version 1.3)

wsvm: weighted SVM

Description

This function transforms the a weighted SVM problem into its dual form, and solves it by the quadratic programing applying ipop in package kernlab. This is the core step in the improved single stage outcome weighted learning (Liu et.al.2015), and now it can takes positive and negative outcomes as an improvement from Zhao et.al.2012. The function wsvm can implement weighted SVM with gaussian or linear kernel. O-learning target at maximizing the expected value function by transforming it into a classification problem, mapping the feature variables X to the optimal treatment choice, which is \(sign(f(x))=sign(h(x)\beta+\beta_0)\). The original problem weighted SVM problem is \(\min \frac{1}{2}\|\beta\|^2+C\Sigma_{i=1}^N x_i |wR_i|\) subject to \(\xi_i\ge 0\) ,\(sign(wR_i)A_i(X_i\beta+\beta_0\ge 1-\xi_i)\)

The transformed dual problem is \(\min_{\alpha} 0.5\sum_i\sum_j \alpha_i wR_i A_i X_i^T X_j A_j wR_j \alpha_j - \sum_i |wR_i| \alpha_i,\) subject to \(0\le\alpha_i\le C,\) and \(\sum_i\alpha_i wR_i A_i=0\).

Usage

wsvm(X, A, wR, kernel = "linear", sigma = 0.05, C = 1, e = 1e-05)

Arguments

X

a n by p matrix, n is the sample size, p is the number of feature variables.

A

a vector of the treatment assignments coded by 1 and -1.

wR

a vector of weighted outcomes computed before hand, it is the outcome \(R_i\) weighted by inverse randomzation or observational probability. \(wR_i=R_i/\pi_i\)

kernel

the kernel function for weighted SVM, can be 'linear' or 'rbf' (radial basis kernel), default is 'linear'. When 'rbf' is specified, one can specify the sigma parameter for radial basis kernel.

sigma

the tuning parameter for 'rbf' kernal, this is from rbfdot function in package kernlab, \(Kernel(x,y)=exp(-sigma*(x-y)^2)\)

C

the tuning parameter for weighted SVM in the primal problem \(\min \frac{1}{2}\|\beta\|^2+C\Sigma_{i=1}^N x_i |wR_i|\) subject to \(\xi_i\ge 0,\) \(sign(wR_i)A_i(X_i\beta+\beta_0\ge 1-\xi_i)\)

e

the rounding error when computing the bias, for the varaibles \(\alpha_i\)'s in the dual problem, if \(|\alpha_i|<e\), we consider \(\alpha=0\).

Value

If kernel 'linear' is specified, it returns an object of class 'linearcl', and it is a list include the following elements:

alpha1

the scaled solution for the dual problem: \(alpha1_i=\alpha_i A_i wR_i\)

bias

the intercept \(\beta_0\) in \(f(X)=\beta_0+X\beta\).

fit

a vector of estimated values for \(\hat{f(x)}\) in training data, \(fit=bias+X\beta=bias+X*X'*alpha1\).

beta

The coefficients \(\beta\) for linear SVM, \(f(X)=bias+X\beta\).

If kernel 'rbf' is specified, it returns an object of class 'rbfcl', and it is a list include the following elements:

alpha1

the scaled solution for the dual problem: \(alpha1_i=\alpha_i A_i wR_i\) and \(X\beta= K(X,X)*alpha1\)

bias

the intercept \(\beta_0\) in \(f(X)=\beta_0+h(X)\beta\).

fit

a vector of estimated values for \(\hat{f(x)}\) in training data, \(fit=\beta_0+h(X)\beta=bias+K(X,X)*alpha1\).

Sigma

the bandwidth parameter for the rbf kernel

X

the matrix of training feature variable

References

Liu et al. (2015). Under double-blinded review.

Zhao, Y., Zeng, D., Rush, A. J., & Kosorok, M. R. (2012). Estimating individualized treatment rules using outcome weighted learning. Journal of the American Statistical Association, 107(499), 1106-1118.

See Also

plot.linearcl predict.linearcl predict.rbfcl

Examples

Run this code
# NOT RUN {
#generating random asigned treatment vector A
n=200
A=2*rbinom(n,1,0.5)-1
p=20
mu=numeric(p)
Sigma=diag(p)
#feature variable is multivariate normal distributed
X=mvrnorm(n,mu,Sigma)
#the outcome is generated where the true optimal treatment 
#is sign of the interaction term(of treatment and feature)
R=X[,1:3]%*%c(1,1,-2)+X[,3:5]%*%c(1,1,-2)*A+rnorm(n)

# linear SVM
model1=wsvm(X,A,R)
#Check the total number that agress with the true optimal treatment among n=200 patients
sum(sign(model1$fit)==sign(X[,3:5]%*%c(1,1,-2)))

# SVM with rbf kernel and sigma=0.05
model2=wsvm(X,A,R,'rbf',0.05)
#Check the total number that agress with the true optimal treatment among n=200 patients
sum(sign(model2$fit)==sign(X[,3:5]%*%c(1,1,-2)))
# }

Run the code above in your browser using DataLab