|
a |
|
b/partyMod/vignettes/MOB.Rout.save |
|
|
1 |
|
|
|
2 |
> require("party") |
|
|
3 |
Loading required package: party |
|
|
4 |
Loading required package: grid |
|
|
5 |
Loading required package: zoo |
|
|
6 |
|
|
|
7 |
Attaching package: ‘zoo’ |
|
|
8 |
|
|
|
9 |
The following objects are masked from ‘package:base’: |
|
|
10 |
|
|
|
11 |
as.Date, as.Date.numeric |
|
|
12 |
|
|
|
13 |
Loading required package: sandwich |
|
|
14 |
Loading required package: strucchange |
|
|
15 |
Loading required package: modeltools |
|
|
16 |
Loading required package: stats4 |
|
|
17 |
|
|
|
18 |
> options(useFancyQuotes = FALSE) |
|
|
19 |
|
|
|
20 |
> library("party") |
|
|
21 |
|
|
|
22 |
> data("BostonHousing", package = "mlbench") |
|
|
23 |
|
|
|
24 |
> BostonHousing$lstat <- log(BostonHousing$lstat) |
|
|
25 |
|
|
|
26 |
> BostonHousing$rm <- BostonHousing$rm^2 |
|
|
27 |
|
|
|
28 |
> BostonHousing$chas <- factor(BostonHousing$chas, levels = 0:1, |
|
|
29 |
+ labels = c("no", "yes")) |
|
|
30 |
|
|
|
31 |
> BostonHousing$rad <- factor(BostonHousing$rad, ordered = TRUE) |
|
|
32 |
|
|
|
33 |
> ctrl <- mob_control(alpha = 0.05, bonferroni = TRUE, |
|
|
34 |
+ minsplit = 40, objfun = deviance, verbose = TRUE) |
|
|
35 |
|
|
|
36 |
> fmBH <- mob(medv ~ lstat + rm | zn + indus + chas + |
|
|
37 |
+ nox + age + dis + rad + tax + crim + b + ptratio, data = BostonHousing, |
|
|
38 |
+ control = .... [TRUNCATED] |
|
|
39 |
|
|
|
40 |
------------------------------------------- |
|
|
41 |
Fluctuation tests of splitting variables: |
|
|
42 |
zn indus chas nox age |
|
|
43 |
statistic 3.363356e+01 6.532322e+01 2.275635e+01 8.136281e+01 3.675850e+01 |
|
|
44 |
p.value 1.023987e-04 1.363602e-11 4.993053e-04 3.489797e-15 2.263798e-05 |
|
|
45 |
dis rad tax crim b |
|
|
46 |
statistic 6.848533e+01 1.153641e+02 9.068440e+01 8.655065e+01 3.627629e+01 |
|
|
47 |
p.value 2.693904e-12 7.087680e-13 2.735524e-17 2.356348e-16 2.860686e-05 |
|
|
48 |
ptratio |
|
|
49 |
statistic 7.221524e+01 |
|
|
50 |
p.value 3.953623e-13 |
|
|
51 |
|
|
|
52 |
Best splitting variable: tax |
|
|
53 |
Perform split? yes |
|
|
54 |
------------------------------------------- |
|
|
55 |
|
|
|
56 |
Node properties: |
|
|
57 |
tax <= 432; criterion = 1, statistic = 115.364 |
|
|
58 |
|
|
|
59 |
------------------------------------------- |
|
|
60 |
Fluctuation tests of splitting variables: |
|
|
61 |
zn indus chas nox age |
|
|
62 |
statistic 27.785009791 21.3329346 8.0272421 23.774323202 11.9204284 |
|
|
63 |
p.value 0.001494064 0.0285193 0.4005192 0.009518732 0.7666366 |
|
|
64 |
dis rad tax crim b |
|
|
65 |
statistic 24.268011081 50.481593270 3.523250e+01 3.276813e+01 9.0363245 |
|
|
66 |
p.value 0.007601532 0.003437763 4.275527e-05 1.404487e-04 0.9871502 |
|
|
67 |
ptratio |
|
|
68 |
statistic 4.510680e+01 |
|
|
69 |
p.value 3.309747e-07 |
|
|
70 |
|
|
|
71 |
Best splitting variable: ptratio |
|
|
72 |
Perform split? yes |
|
|
73 |
------------------------------------------- |
|
|
74 |
|
|
|
75 |
Node properties: |
|
|
76 |
ptratio <= 15.2; criterion = 1, statistic = 50.482 |
|
|
77 |
|
|
|
78 |
------------------------------------------- |
|
|
79 |
Fluctuation tests of splitting variables: |
|
|
80 |
zn indus chas nox age |
|
|
81 |
statistic 3.233350e+01 22.26864036 12.93407112 22.10510234 20.41295354 |
|
|
82 |
p.value 1.229678e-04 0.01504788 0.05259509 0.01622098 0.03499731 |
|
|
83 |
dis rad tax crim b |
|
|
84 |
statistic 17.7204735 5.526565e+01 2.879128e+01 20.28503194 6.5549665 |
|
|
85 |
p.value 0.1091769 7.112214e-04 6.916307e-04 0.03706934 0.9999522 |
|
|
86 |
ptratio |
|
|
87 |
statistic 4.789850e+01 |
|
|
88 |
p.value 4.738855e-08 |
|
|
89 |
|
|
|
90 |
Best splitting variable: ptratio |
|
|
91 |
Perform split? yes |
|
|
92 |
------------------------------------------- |
|
|
93 |
|
|
|
94 |
Node properties: |
|
|
95 |
ptratio <= 19.6; criterion = 1, statistic = 55.266 |
|
|
96 |
|
|
|
97 |
------------------------------------------- |
|
|
98 |
Fluctuation tests of splitting variables: |
|
|
99 |
zn indus chas nox age dis |
|
|
100 |
statistic 14.971474 14.6477733 7.1172962 14.3455158 8.2176363 16.1112185 |
|
|
101 |
p.value 0.280361 0.3134649 0.5405005 0.3467974 0.9906672 0.1847818 |
|
|
102 |
rad tax crim b ptratio |
|
|
103 |
statistic 43.17824350 3.447271e+01 9.340075 8.7773142 10.8469969 |
|
|
104 |
p.value 0.03281124 4.281939e-05 0.952996 0.9772696 0.8202694 |
|
|
105 |
|
|
|
106 |
Best splitting variable: tax |
|
|
107 |
Perform split? yes |
|
|
108 |
------------------------------------------- |
|
|
109 |
|
|
|
110 |
Node properties: |
|
|
111 |
tax <= 265; criterion = 1, statistic = 43.178 |
|
|
112 |
|
|
|
113 |
------------------------------------------- |
|
|
114 |
Fluctuation tests of splitting variables: |
|
|
115 |
zn indus chas nox age dis |
|
|
116 |
statistic 11.998039 7.3971233 7.227770 9.2936189 14.3023962 8.9239826 |
|
|
117 |
p.value 0.574642 0.9931875 0.522447 0.9119621 0.2886603 0.9389895 |
|
|
118 |
rad tax crim b ptratio |
|
|
119 |
statistic 33.1746444 16.6666129 11.7143758 9.9050903 11.5927528 |
|
|
120 |
p.value 0.3926249 0.1206412 0.6153455 0.8539893 0.6328381 |
|
|
121 |
|
|
|
122 |
Best splitting variable: tax |
|
|
123 |
Perform split? no |
|
|
124 |
------------------------------------------- |
|
|
125 |
|
|
|
126 |
------------------------------------------- |
|
|
127 |
Fluctuation tests of splitting variables: |
|
|
128 |
zn indus chas nox age dis |
|
|
129 |
statistic 10.9187926 9.0917078 2.754081e+01 17.39203006 4.6282349 11.9581600 |
|
|
130 |
p.value 0.7091039 0.9172303 4.987667e-05 0.08922543 0.9999992 0.5607267 |
|
|
131 |
rad tax crim b ptratio |
|
|
132 |
statistic 0.2557803 10.9076165 3.711175 3.158329 9.8865054 |
|
|
133 |
p.value 1.0000000 0.7106612 1.000000 1.000000 0.8410064 |
|
|
134 |
|
|
|
135 |
Best splitting variable: chas |
|
|
136 |
Perform split? yes |
|
|
137 |
------------------------------------------- |
|
|
138 |
|
|
|
139 |
Splitting factor variable, objective function: |
|
|
140 |
no |
|
|
141 |
Inf |
|
|
142 |
|
|
|
143 |
No admissable split found in 'chas' |
|
|
144 |
|
|
|
145 |
> fmBH |
|
|
146 |
1) tax <= 432; criterion = 1, statistic = 115.364 |
|
|
147 |
2) ptratio <= 15.2; criterion = 1, statistic = 50.482 |
|
|
148 |
3)* weights = 72 |
|
|
149 |
Terminal node model |
|
|
150 |
Linear model with coefficients: |
|
|
151 |
(Intercept) lstat rm |
|
|
152 |
9.2349 -4.9391 0.6859 |
|
|
153 |
|
|
|
154 |
2) ptratio > 15.2 |
|
|
155 |
4) ptratio <= 19.6; criterion = 1, statistic = 55.266 |
|
|
156 |
5) tax <= 265; criterion = 1, statistic = 43.178 |
|
|
157 |
6)* weights = 63 |
|
|
158 |
Terminal node model |
|
|
159 |
Linear model with coefficients: |
|
|
160 |
(Intercept) lstat rm |
|
|
161 |
3.9637 -2.7663 0.6881 |
|
|
162 |
|
|
|
163 |
5) tax > 265 |
|
|
164 |
7)* weights = 162 |
|
|
165 |
Terminal node model |
|
|
166 |
Linear model with coefficients: |
|
|
167 |
(Intercept) lstat rm |
|
|
168 |
-1.7984 -0.2677 0.6539 |
|
|
169 |
|
|
|
170 |
4) ptratio > 19.6 |
|
|
171 |
8)* weights = 56 |
|
|
172 |
Terminal node model |
|
|
173 |
Linear model with coefficients: |
|
|
174 |
(Intercept) lstat rm |
|
|
175 |
17.5865 -4.6190 0.3387 |
|
|
176 |
|
|
|
177 |
1) tax > 432 |
|
|
178 |
9)* weights = 153 |
|
|
179 |
Terminal node model |
|
|
180 |
Linear model with coefficients: |
|
|
181 |
(Intercept) lstat rm |
|
|
182 |
68.2971 -16.3540 -0.1478 |
|
|
183 |
|
|
|
184 |
|
|
|
185 |
> plot(fmBH) |
|
|
186 |
|
|
|
187 |
> coef(fmBH) |
|
|
188 |
(Intercept) lstat rm |
|
|
189 |
3 9.234880 -4.939096 0.6859136 |
|
|
190 |
6 3.963720 -2.766287 0.6881287 |
|
|
191 |
7 -1.798387 -0.267707 0.6538864 |
|
|
192 |
8 17.586490 -4.618975 0.3386744 |
|
|
193 |
9 68.297087 -16.354006 -0.1477939 |
|
|
194 |
|
|
|
195 |
> summary(fmBH, node = 7) |
|
|
196 |
|
|
|
197 |
Call: |
|
|
198 |
NULL |
|
|
199 |
|
|
|
200 |
Weighted Residuals: |
|
|
201 |
Min 1Q Median 3Q Max |
|
|
202 |
-9.092 0.000 0.000 0.000 10.236 |
|
|
203 |
|
|
|
204 |
Coefficients: |
|
|
205 |
Estimate Std. Error t value Pr(>|t|) |
|
|
206 |
(Intercept) -1.79839 2.84702 -0.632 0.529 |
|
|
207 |
lstat -0.26771 0.69581 -0.385 0.701 |
|
|
208 |
rm 0.65389 0.03757 17.404 <2e-16 *** |
|
|
209 |
--- |
|
|
210 |
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 |
|
|
211 |
|
|
|
212 |
Residual standard error: 2.652 on 159 degrees of freedom |
|
|
213 |
Multiple R-squared: 0.8173, Adjusted R-squared: 0.815 |
|
|
214 |
F-statistic: 355.6 on 2 and 159 DF, p-value: < 2.2e-16 |
|
|
215 |
|
|
|
216 |
|
|
|
217 |
> sctest(fmBH, node = 7) |
|
|
218 |
zn indus chas nox age dis |
|
|
219 |
statistic 11.998039 7.3971233 7.227770 9.2936189 14.3023962 8.9239826 |
|
|
220 |
p.value 0.574642 0.9931875 0.522447 0.9119621 0.2886603 0.9389895 |
|
|
221 |
rad tax crim b ptratio |
|
|
222 |
statistic 33.1746444 16.6666129 11.7143758 9.9050903 11.5927528 |
|
|
223 |
p.value 0.3926249 0.1206412 0.6153455 0.8539893 0.6328381 |
|
|
224 |
|
|
|
225 |
> mean(residuals(fmBH)^2) |
|
|
226 |
[1] 12.03518 |
|
|
227 |
|
|
|
228 |
> logLik(fmBH) |
|
|
229 |
'log Lik.' -1310.506 (df=24) |
|
|
230 |
|
|
|
231 |
> AIC(fmBH) |
|
|
232 |
[1] 2669.013 |
|
|
233 |
|
|
|
234 |
> nt <- NROW(coef(fmBH)) |
|
|
235 |
|
|
|
236 |
> nk <- NCOL(coef(fmBH)) |
|
|
237 |
|
|
|
238 |
> data("PimaIndiansDiabetes2", package = "mlbench") |
|
|
239 |
|
|
|
240 |
> PimaIndiansDiabetes <- na.omit(PimaIndiansDiabetes2[, |
|
|
241 |
+ -c(4, 5)]) |
|
|
242 |
|
|
|
243 |
> fmPID <- mob(diabetes ~ glucose | pregnant + pressure + |
|
|
244 |
+ mass + pedigree + age, data = PimaIndiansDiabetes, model = glinearModel, |
|
|
245 |
+ famil .... [TRUNCATED] |
|
|
246 |
|
|
|
247 |
> plot(fmPID) |
|
|
248 |
Loading required package: vcd |
|
|
249 |
|
|
|
250 |
> coef(fmPID) |
|
|
251 |
(Intercept) glucose |
|
|
252 |
2 -10.999447 0.06456780 |
|
|
253 |
4 -6.573067 0.04504490 |
|
|
254 |
5 -3.318569 0.02748038 |
|
|
255 |
|
|
|
256 |
> exp(coef(fmPID)[, 2]) |
|
|
257 |
2 4 5 |
|
|
258 |
1.066698 1.046075 1.027861 |
|
|
259 |
|
|
|
260 |
> risk <- round(100 * (exp(coef(fmPID)[, 2]) - 1), digits = 1) |
|
|
261 |
|
|
|
262 |
*** Run successfully completed *** |
|
|
263 |
> proc.time() |
|
|
264 |
user system elapsed |
|
|
265 |
3.548 0.080 3.636 |