Description Usage Arguments Value Note Author(s) References See Also Examples
snpRF
implements Breiman's random forest algorithm (based on
Breiman and Cutler's original Fortran code) for classification and
regression. It can also be used in unsupervised mode for assessing
proximities among data points. This is a modified version of the
randomForest function in the randomForest package addressing issues
of X-chromosome SNP importance bias by simulating the process of
X-inactivation.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | snpRF(x.autosome=NULL,x.xchrom=NULL, xchrom.names=NULL, x.covar=NULL, y,
xtest.autosome=NULL,xtest.xchrom=NULL, xtest.covar=NULL,
ytest=NULL, ntree=500,
mtry=floor(sqrt(sum(c(ncol(x.autosome),ncol(x.xchrom)/2,
ncol(x.covar))))),
replace=TRUE, classwt=NULL, cutoff, strata,
sampsize = if (replace) max(c(nrow(x.autosome),nrow(x.xchrom),
nrow(x.covar)))
else ceiling(.632*max(c(nrow(x.autosome),
nrow(x.xchrom),nrow(x.covar)))),
nodesize = 1,
maxnodes=NULL,
importance=FALSE, localImp=FALSE,
proximity, oob.prox=proximity,
norm.votes=TRUE, do.trace=FALSE,
keep.forest=!is.null(y) && (is.null(xtest.autosome) &
is.null(xtest.xchrom) &
is.null(xtest.covar)),
keep.inbag=FALSE, ...)
## S3 method for class 'snpRF'
print(x, ...)
|
x |
a |
x.autosome |
A matrix of autosomal markers with each column corresponding to a SNP coded as the count of a particular allele (i.e. 0,1 or 2), and each row corresponding to a sample/individual. |
x.xchrom |
A matrix of X chromosome markers, each marker coded as two adjacent columns, alleles of a marker are coded as 0 or 1 for carrying a particular allele. Although males only have one X-chromosome, their markers are coded as 2 columns as well, the second column being a duplicate of the first. Each row of this matrix corresponsponds to a sample/individual. This data must be phased in chromosomal order. |
xchrom.names |
A vector of names for markers (1 name per marker) in the x.xchrom matrix ordered in the same manner as markers in x.xchrom. |
x.covar |
A matrix of covariates, each column being a different covariate and each row, a sample/individual. |
y |
A response vector. Must be a factor, regression has not been implemented.
If omitted, |
xtest.autosome |
a matrix (like |
xtest.xchrom |
a matrix (like |
xtest.covar |
a matrix (like |
ytest |
response for the test set. |
ntree |
Number of trees to grow. This should not be set to too small a number, to ensure that every input row gets predicted at least a few times. |
mtry |
Number of variables randomly sampled as candidates at each
split. Note that the default values are different for
classification (sqrt(p) where p is number of variables in: |
replace |
Should sampling of cases be done with or without replacement? |
classwt |
Priors of the classes. Need not add up to one. |
cutoff |
A vector of length equal to number of classes. The ‘winning’ class for an observation is the one with the maximum ratio of proportion of votes to cutoff. Default is 1/k where k is the number of classes (i.e., majority vote wins). |
strata |
A (factor) variable that is used for stratified sampling. |
sampsize |
Size(s) of sample to draw. For classification, if sampsize is a vector of the length the number of strata, then sampling is stratified by strata, and the elements of sampsize indicate the numbers to be drawn from the strata. |
nodesize |
Minimum size of terminal nodes. Setting this number larger causes smaller trees to be grown (and thus take less time). |
maxnodes |
Maximum number of terminal nodes trees in the forest
can have. If not given, trees are grown to the maximum possible
(subject to limits by |
importance |
Should importance of predictors be assessed? |
localImp |
Should casewise importance measure be computed?
(Setting this to |
proximity |
Should proximity measure among the rows be calculated? |
oob.prox |
Should proximity be calculated only on “out-of-bag” data? |
norm.votes |
If |
do.trace |
If set to |
keep.forest |
If set to |
keep.inbag |
Should an |
... |
optional parameters to be passed to the low level function
|
An object of class snpRF
, which is a list with the
following components:
call |
the original call to |
type |
|
predicted |
the predicted values of the input data based on out-of-bag samples. |
importance |
a matrix with |
importanceSD |
The “standard errors” of the permutation-based
importance measure. For classification, a |
localImp |
a p by n matrix containing the casewise importance
measures, the [i,j] element of which is the importance of i-th
variable on the j-th case. |
ntree |
number of trees grown. |
mtry |
number of predictors sampled for spliting at each node. |
forest |
(a list that contains the entire forest; |
err.rate |
(classification only) vector error rates of the prediction on the input data, the i-th element being the (OOB) error rate for all trees up to the i-th. |
confusion |
(classification only) the confusion matrix of the prediction (based on OOB data). |
votes |
(classification only) a matrix with one row for each input data point and one column for each class, giving the fraction or number of (OOB) ‘votes’ from the random forest. |
oob.times |
number of times cases are ‘out-of-bag’ (and thus used in computing OOB error estimate) |
proximity |
if |
test |
if test set is given (through the |
For details on how the trees are
stored, see the help page for getTree
.
If xtest.*
is given, prediction of the test set is done “in
place” as the trees are grown. If ytest
is also given, and
do.trace
is set to some positive integer, then for every
do.trace
trees, the test set error is printed. Results for the
test set is returned in the test
component of the resulting
snpRF
object. For classification, the votes
component (for training or test set data) contain the votes the cases
received for the classes. If norm.votes=TRUE
, the fraction is
given, which can be taken as predicted probabilities for the classes.
The “local” (or casewise) variable importance is computed as the increase in percent of times a case is OOB and misclassified when the variable is permuted.
Greg Jenkinsjenkins.gregory@mayo.edu; modification of Andy Liaw and Matthew Wiener randomForest function in the randomForest package, based on original Fortran code by Leo Breiman and Adele Cutler.
Breiman, L. (2001), Random Forests, Machine Learning 45(1), 5-32.
Breiman, L (2002), “Manual On Setting Up, Using, And Understanding Random Forests V3.1”, http://oz.berkeley.edu/users/breiman/Using_random_forests_V3.1.pdf.
Jenkins, G., Biernacka J., Winham S., Random forest for genetic analysis: Integrating the X chromosome; (Abstract #1853). Presented at the 64th Annual Meeting of The American Society of Human Genetics, Date, October 21, 2014 in San Diego, CA.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | ## Classification:
data(snpRFexample)
set.seed(71)
eg.rf <- snpRF(x.autosome=autosome.snps,x.xchrom=xchrom.snps,
xchrom.names=xchrom.snps.names,x.covar=covariates,
y=phenotype,importance=TRUE, proximity=TRUE)
print(eg.rf)
## Look at variable importance:
round(importance(eg.rf), 2)
## Do MDS on 1 - proximity:
eg.mds <- cmdscale(1 - eg.rf$proximity, eig=TRUE)
print(eg.mds$GOF)
## Grow no more than 4 nodes per tree:
(treesize(snpRF(x.autosome=autosome.snps,x.xchrom=xchrom.snps,
xchrom.names=xchrom.snps.names,x.covar=covariates,
y=phenotype, maxnodes=4, ntree=30)))
|
snpRF 0.4
Call:
snpRF(x.autosome = autosome.snps, x.xchrom = xchrom.snps, xchrom.names = xchrom.snps.names, x.covar = covariates, y = phenotype, importance = TRUE, proximity = TRUE)
Type of random forest: classification
Number of trees: 500
No. of variables tried at each split: 5
OOB estimate of error rate: 48%
Confusion matrix:
control case class.error
control 31 61 0.6630435
case 35 73 0.3240741
control case MeanDecreaseAccuracy MeanDecreaseGini
rs11226839 -0.71 0.73 0.03 2.18
rs2275358 -1.34 -1.38 -1.89 2.13
rs765688 -1.59 -1.44 -1.96 3.70
rs11055625 -1.18 0.41 -0.61 1.54
rs2302711 1.12 -1.58 -0.24 3.85
rs7966866 0.91 2.89 2.77 3.51
rs10775270 -1.96 -0.80 -1.91 4.14
rs12187326 -0.55 0.75 0.15 1.59
rs12522802 0.45 -2.61 -1.26 2.59
rs220563 -0.84 0.15 -0.60 3.43
rs2274856 1.24 2.85 2.77 4.37
rs1070505 0.46 1.52 1.36 4.13
rs219931 -0.35 -0.99 -1.15 2.66
rs11074593 1.03 0.69 1.07 3.87
rs1428920 -3.15 0.68 -1.61 4.16
rs4764041 -0.01 -0.75 -0.71 0.99
rs2963954 -0.06 1.44 1.13 4.86
rs1003573 1.40 2.41 2.80 4.82
rs2275363 2.13 3.54 3.97 5.15
rs2964018 1.76 1.11 1.91 4.40
age -2.92 0.47 -1.48 14.78
smoking -0.79 -0.07 -0.56 2.59
rs5911560 -1.76 -2.27 -2.75 1.48
rs5911588 -0.38 1.21 0.82 2.26
rs4825857 -2.96 2.20 -0.02 2.87
rs504096 0.74 0.16 0.56 2.68
rs503118 0.90 0.28 0.85 2.79
[1] 0.05097091 0.05273912
[1] 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.