Description Usage Arguments Author(s) Examples
Fit support vector machine with optional subject-level weights
1 |
tr.x |
Matrix or data.frame of features for training |
tr.y |
Vector of group labels for training |
ts.x |
Matrix or data.frame of features for testing |
grid.C |
Vector of C values for tuning the SVM |
w |
optional vector of subject weights |
Kristin Linn
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 | if (require(MASS)){
##################################################
# Generate data
##################################################
set.seed(1)
n = 500
p = 2
sigma = matrix(.25, p, p)
diag(sigma) = 1
eps1 = MASS::mvrnorm(n, rep(0, p), sigma)
eps2 = MASS::mvrnorm(n, rep(0, p), sigma)
tr.y = rbinom(n, 1, .5)
x1 = 5 - .25*tr.y + .2*tr.y*eps1[,1] + .1*eps2[,1]
x2 = 5 - tr.y + .3*eps2[,1] + .5*(eps1[,2] + eps2[,2])
tr.x = cbind(x1, x2)
ts.eps1 = MASS::mvrnorm(n, rep(0, p), sigma)
ts.eps2 = MASS::mvrnorm(n, rep(0, p), sigma)
ts.y = rbinom(n, 1, .5)
ts.x1 = 5 - .25*ts.y + .2*ts.y*ts.eps1[,1] + .1*ts.eps2[,1]
ts.x2 = 5 - ts.y + .3*ts.eps2[,1] + .5*(ts.eps1[,2] + ts.eps2[,2])
ts.x = cbind(ts.x1, ts.x2)
grid.C = 10^c(-3:3)
out = fit.svm(tr.x=tr.x, tr.y=tr.y, ts.x=ts.x, grid.C=grid.C)
w = c(rep(2, 250), rep(1.5, 125), rep(3, 125))
w.out = fit.svm(tr.x=tr.x, tr.y=tr.y, ts.x=ts.x, grid.C=grid.C, w=w)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.