[R] rpart package: How can I save print(rpart)
Karim Mezhoud
kmezhoud at gmail.com
Thu Nov 13 21:35:56 CET 2014
Hi,
the print of rpart fitting gives the summary of tree
I would like to save the console text of:
fit <- rpart(formula, data)
summary <- print(fit)
when I look in "summary" I did not find the same thing as in
"print(rpart)"
[1] "Clinical Data exists"
[1] "merging samples from Clinical and Profile Data"
[1] "Selected formula: DFS_STATUS~."
n= 236
node), split, n, loss, yval, (yprob)
* denotes terminal node
1) root 236 58 DiseaseFree (0.21610169 0.75423729 0.02966102)
2) PIK3CA< 302.7615 105 42 DiseaseFree (0.39047619 0.60000000
0.00952381)
4) FGFR1< 941.6309 41 16 (0.60975610 0.36585366 0.02439024)
8) ANXA1>=2148.882 19 3 (0.84210526 0.10526316 0.05263158) *
9) ANXA1< 2148.882 22 9 DiseaseFree (0.40909091 0.59090909
0.00000000)
18) RAF1< 2315.279 13 4 (0.69230769 0.30769231 0.00000000) *
19) RAF1>=2315.279 9 0 DiseaseFree (0.00000000 1.00000000
0.00000000) *
5) FGFR1>=941.6309 64 16 DiseaseFree (0.25000000 0.75000000
0.00000000)
10) CDH2>=153.6887 10 2 (0.80000000 0.20000000 0.00000000) *
11) CDH2< 153.6887 54 8 DiseaseFree (0.14814815 0.85185185
0.00000000)
22) PCNA< 696.389 7 3 (0.57142857 0.42857143 0.00000000) *
23) PCNA>=696.389 47 4 DiseaseFree (0.08510638 0.91489362
0.00000000) *
3) PIK3CA>=302.7615 131 16 DiseaseFree (0.07633588 0.87786260
0.04580153) *
>
class(summary)
#rpart
summary
{list(var = c(6, 3, 1, 4, 7, 4, 4, 2, 4, 5, 4, 4, 4), n = c(236, 105, 41,
19, 22, 13, 9, 64, 10, 54, 7, 47, 131), wt = c(236, 105, 41, 19, 22, 13, 9,
64, 10, 54, 7, 47, 131), dev = c(58, 42, 16, 3, 9, 4, 0, 16, 2, 8, 3, 4,
16), yval = c(2, 2, 1, 1, 2, 1, 2, 2, 1, 2, 1, 2, 2), complexity =
c(0.0862068965517241, 0.0862068965517241, 0.0775862068965517, 0.01,
0.0775862068965517, 0.01, 0.01, 0.0862068965517241, 0.01,
0.0172413793103448, 0.01, 0, 0), ncompete = c(4, 4, 4, 0, 4, 0, 0, 4, 0, 4,
0, 0, 0),
nsurrogate = c(5, 5, 5, 0, 5, 0, 0, 5, 0, 5, 0, 0, 0), yval2 = c(2, 2,
1, 1, 2, 1, 2, 2, 1, 2, 1, 2, 2, 51, 41, 25, 16, 9, 9, 0, 16, 8, 8, 4, 4,
10, 178, 63, 15, 2, 13, 4, 9, 48, 2, 46, 3, 43, 115, 7, 1, 1, 1, 0, 0, 0,
0, 0, 0, 0, 0, 6, 0.216101694915254, 0.39047619047619, 0.609756097560976,
0.842105263157895, 0.409090909090909, 0.692307692307692, 0, 0.25, 0.8,
0.148148148148148, 0.571428571428571, 0.0851063829787234,
0.0763358778625954, 0.754237288135593, 0.6, 0.365853658536585,
0.105263157894737,
0.590909090909091, 0.307692307692308, 1, 0.75, 0.2, 0.851851851851852,
0.428571428571429, 0.914893617021277, 0.877862595419847,
0.0296610169491525, 0.00952380952380952, 0.024390243902439,
0.0526315789473684, 0, 0, 0, 0, 0, 0, 0, 0, 0.0458015267175573, 1,
0.444915254237288, 0.173728813559322, 0.0805084745762712,
0.0932203389830508, 0.0550847457627119, 0.038135593220339,
0.271186440677966, 0.0423728813559322, 0.228813559322034,
0.0296610169491525, 0.199152542372881, 0.555084745762712))} {c(13, 13, 13,
12, 7, 13, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12,
13, 13, 13, 13, 13, 13, 13, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12, 13, 13, 13, 13, 13,
13, 13, 13, 13, 13, 13, 13, 13, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
13, 13, 13, 13, 13, 13, 13, 13, 13, 6, 12, 12, 12, 6, 6, 13, 6, 13, 4, 13,
13, 13, 7, 12, 6, 12, 12, 12, 9, 4, 12, 11, 12, 12, 12, 11, 12, 12, 13, 7,
4, 12, 12, 4, 9, 7, 13, 12, 7, 12,
12, 13, 12, 13, 12, 11, 12, 13, 12, 13, 13, 13, 12, 13, 12, 13, 7, 13, 13,
12, 13, 13, 13, 13, 13, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12, 13, 13,
13, 7, 13, 11, 13, 4, 7, 4, 9, 9, 13, 4, 12, 13, 13, 13, 13, 4, 13, 7, 4,
6, 12, 12, 12, 12, 12, 13, 11, 13, 6, 13, 13, 4, 12, 12, 4, 11, 12, 12, 12,
13, 13, 13, 12, 9, 9, 9, 4, 9, 4, 4, 4, 11, 13, 4, 4, 9, 12, 6, 4, 9, 4, 6,
6, 6, 6, 6, 12)} {rpart(formula = frmla, data = ProfData, method =
"class")} {DFS_STATUS ~ A1CF + ACACA + ACKR2 + AGXT + AHCYL2 + AHSA1 +
AIMP2 + AKR1B1 + AKT1 + AKT1S1 + ANO3 + ANXA1 + APOBR + AQP7 + AR +
ARHGEF26 + ARID1A + ATM + BAK1 + BAX + BCL2 + BCL2L1 + BCL2L11 + BECN1 +
BID + BIRC2 + BRAF + CASP3 + CASP7 + CASP8 + CASP9 + CAT + CAV1 + CCL15 +
CCNB1 + CCND1 + CCNE1 + CCNE2 + CDH1 + CDH2 + CDHR2 + CDHR5 + CDK1 + CDKN1A
+ CHEK1 + CHEK2 + CHST5 + CLDN7 + CLIC6 + CNTN1 + COL6A2 + COX2 + CTNNB1 +
DDR2 + DEFA6 + DIABLO + DIRAS1 + DKK3 + DNAJC22 + DVL3 + EDAR + EEF2 +
EEF2K +
EGFR + EIF4E + EIF4EBP1 + ENGASE + ERBB2 + ERBB3 + ERC2 + ERCC1 +
ERRFI1 + ESR1 + FA2H + FAM153A + FAM184A + FGFR1 + FGGY + FN1 + FOXO3 +
GAB2 + GARS + GATA3 + GRID1 + GSK3A + GSK3B + GUCY2C + H3F3AP6 + HOMER2 +
HPGDS + HSPA1A + HSPA1B + HSPB8 + IFI27 + IGF1R + IGFBP2 + INF2 + INPP4B +
IRS1 + ITGA2 + JUN + KCNJ5 + KDR + KIAA0226L + KIT + KLK1 + KRAS + LCK +
LPAR1 + LPAR3 + MAP2K1 + MAPK1 + MAPK14 + MAPK4 + MAPK6 + MAPK8 + MAPK9 +
MAPT + MET + MOGAT3 + MRE11A + MS4A1 + MS4A2 + MSH2 + MSH6 + MTOR +
MYC + MYH7B + NANOS3 + NCOA3 + NDRG1 + NEURL1 + NF2 + NKX2.1 + NOTCH1 +
NOTCH3 + NPPC + PARK7 + PARP1 + PCDHB11 + PCNA + PDK1 + PDPK1 + PEA15 +
PECAM1 + PGR + PIK3CA + PIK3CB + PIK3CD + PNMAL1 + PRH2 + PRKAA1 + PRKAA2 +
PRKCA + PRKCD + PSMC4 + PSMD9 + PTCH1 + PTEN + PTK2 + PXN + RAB11A + RAB25
+ RAD50 + RAD51 + RAF1 + RB1 + REG1B + RORA + RPS6 + SETD2 + SHC1 + SLC18A1
+ SLC7A8 + SMAD1 + SMAD3 + SMAD4 + SNAI1 + SRC + SSSCA1 + SSUH2 + STAT3 +
STAT5A + STK11 + STMN4 + SYK + TAZ + TCEAL1 + TGM1 +
TGM2 + TGM3 + TGM4 + TMEM37 + TNFRSF11A + TONSL + TP53 + TP53AIP1 +
TP53BP1 + TRIL + TSC2 + TSPO2 + VASP + WWTR1 + XBP1 + XBP1P1 + XIAP + XRCC1
+ XRCC5 + YBX1 + YWHAE + YY1AP1} {c(0.0862068965517241, 0.0775862068965517,
0.0172413793103448, 0.01, 0, 3, 5, 6, 1, 0.724137931034483,
0.568965517241379, 0.551724137931034, 1, 1.22413793103448, 1.3448275862069,
1.41379310344828, 0.114035482086724, 0.121475068159872, 0.124592485529312,
0.12611980528159)} class {list(prior = c(0.216101694915254,
0.754237288135593, 0.0296610169491525), loss = c(0, 1, 1, 1, 0, 1, 1, 1,
0), split = 1)} {list(minsplit = 20, minbucket = 7, cp = 0.01, maxcompete =
4, maxsurrogate = 5, usesurrogate = 2, surrogatestyle = 0, maxdepth = 30,
xval = 10)} {list(summary = function (yval, dev, wt, ylevel, digits)
{
nclass <- (ncol(yval) - 2)/2
group <- yval[, 1]
counts <- yval[, 1 + (1:nclass)]
yprob <- yval[, 1 + nclass + 1:nclass]
nodeprob <- yval[, 2 * nclass + 2]
if (!is.null(ylevel))
group <- ylevel[group]
temp1 <- formatg(counts, format = "%5g")
temp2 <- formatg(yprob, format = "%5.3f")
if (nclass > 1) {
temp1 <- apply(matrix(temp1, ncol = nclass), 1, paste, collapse = "
")
temp2 <- apply(matrix(temp2, ncol = nclass), 1, paste, collapse = "
")
}
dev <- dev/(wt[1] * nodeprob)
paste0(" predicted class=", format(group, justify = "left"), "
expected loss=", formatg(dev, digits), " P(node) =", formatg(nodeprob,
digits), "\n", " class counts: ", temp1, "\n", " probabilities: ",
temp2)
}, print = function (yval, ylevel, digits)
{
temp <- if (is.null(ylevel))
as.character(yval[, 1])
else ylevel[yval[, 1]]
nclass <- (ncol(yval) - 2)/2
yprob <- if (nclass < 5)
format(yval[, 1 + nclass + 1:nclass], digits = digits, nsmall =
digits)
else formatg(yval[, 1 + nclass + 1:nclass], digits = 2)
if (!is.matrix(yprob))
yprob <- matrix(yprob, nrow = 1)
temp <- paste0(temp, " (", yprob[, 1])
for (i in 2:ncol(yprob)) temp <- paste(temp, yprob[, i], sep = " ")
temp <- paste0(temp, ")")
temp
}, text = function (yval, dev, wt, ylevel, digits, n, use.n)
{
nclass <- (ncol(yval) - 2)/2
group <- yval[, 1]
counts <- yval[, 1 + (1:nclass)]
if (!is.null(ylevel))
group <- ylevel[group]
temp1 <- formatg(counts, digits)
if (nclass > 1)
temp1 <- apply(matrix(temp1, ncol = nclass), 1, paste, collapse =
"/")
.......................
How can I save print(fit)?
Thank?
Ô__
c/ /'_;~~~~kmezhoud
(*) \(*) ⴽⴰⵔⵉⵎ ⵎⴻⵣⵀⵓⴷ
http://bioinformatics.tn/
[[alternative HTML version deleted]]
More information about the R-help
mailing list