> # test.varmod.R
> 
> source("test.prolog.R")
> library(earth)
Loading required package: Formula
Loading required package: plotmo
Loading required package: plotrix
> options(warn=1) # print warnings as they occur
> printh <- function(caption)
+     cat("===", caption, "\n", sep="")
> 
> CAPTION <- NULL
> 
> multifigure <- function(caption, nrow=3, ncol=3)
+ {
+     CAPTION <<- caption
+     printh(caption)
+     par(mfrow=c(nrow, ncol))
+     par(cex = 0.8)
+     par(mar = c(3, 3, 5, 0.5)) # small margins but space for right hand axis
+     par(mgp = c(1.6, 0.6, 0))  # flatten axis elements
+     oma <- par("oma") # make space for caption
+     oma[3] <- 2
+     par(oma=oma)
+ }
> do.caption <- function() # must be called _after_ first plot on new page
+     mtext(CAPTION, outer=TRUE, font=2, line=1, cex=1)
> 
> multifigure("test predict.earth with pints", 2, 2)
===test predict.earth with pints
> 
> set.seed(2)
> earth.trees <- earth(Volume~Girth, data=trees, nfold=3, ncross=3, varmod.method="earth")
> 
> old.environment <- attr(earth.trees$varmod, ".Environment")
> stopifnot(is.environment(old.environment))
> # following necessary else print.default prints a different default environment hex address each time
> attr(earth.trees$varmod, ".Environment") <- NULL
> printh("print.default(earth.trees$varmod)")
===print.default(earth.trees$varmod)
> print.default(earth.trees$varmod)
$call
varmod(parent = parent, method = method, exponent = exponent, 
    conv = conv, clamp = clamp, minspan = minspan, trace = trace, 
    parent.x = x, parent.y = y, model.var = model.var)

$parent
Selected 3 of 4 terms, and 1 of 1 predictors
Termination condition: RSq changed by less than 0.001 at 4 terms
Importance: Girth
Number of terms at each degree of interaction: 1 2 (additive model)
GCV 14.20145  RSS 309.6832  GRSq 0.949137  RSq 0.9617962  CVRSq 0.9391778

$method
[1] "earth"

$exponent
[1] 1

$lambda
[1] 1

$rmethod
[1] "hc12"

$converged
[1] TRUE

$iters
[1] 1

$residmod
Selected 2 of 4 terms, and 1 of 1 predictors
Termination condition: RSq changed by less than 0.001 at 4 terms
Importance: RHS
Number of terms at each degree of interaction: 1 1 (additive model)
GCV 3.469431    RSS 87.74303    GRSq 0.201497    RSq 0.3044152

$min.sd
[1] 0.3768615

$model.var
             [,1]
 [1,] 0.781975654
 [2,] 0.380089019
 [3,] 0.582758485
 [4,] 0.504914123
 [5,] 0.178568741
 [6,] 0.028039319
 [7,] 0.090059658
 [8,] 0.422836830
 [9,] 0.082078906
[10,] 0.088552129
[11,] 0.345306201
[12,] 0.630158271
[13,] 0.336500919
[14,] 0.133563294
[15,] 0.837790056
[16,] 2.204958223
[17,] 0.201022761
[18,] 1.807147402
[19,] 0.268167169
[20,] 1.809333273
[21,] 0.640120276
[22,] 0.370925125
[23,] 0.925079265
[24,] 0.319450065
[25,] 0.530235103
[26,] 1.307173363
[27,] 0.037534136
[28,] 1.257092327
[29,] 0.776503513
[30,] 0.007620971
[31,] 6.082359146

$abs.resids
         Volume
 [1,] 0.9972120
 [2,] 0.9723250
 [3,] 1.8202611
 [4,] 1.3499478
 [5,] 0.8303927
 [6,] 1.3274450
 [7,] 3.8646145
 [8,] 1.2316707
 [9,] 3.3429505
[10,] 0.3015926
[11,] 4.3500327
[12,] 0.9355264
[13,] 1.0922872
[14,] 0.4657214
[15,] 3.8742754
[16,] 4.0735748
[17,] 8.8560415
[18,] 1.3975099
[19,] 3.0799671
[20,] 4.5302574
[21,] 4.9795594
[22,] 0.6962448
[23,] 3.3650804
[24,] 5.3763683
[25,] 2.9142428
[26,] 4.1766153
[27,] 2.9175095
[28,] 3.1228458
[29,] 5.5561498
[30,] 6.0503894
[31,] 5.3658904

$parent.x
      Girth
 [1,]   8.3
 [2,]   8.6
 [3,]   8.8
 [4,]  10.5
 [5,]  10.7
 [6,]  10.8
 [7,]  11.0
 [8,]  11.0
 [9,]  11.1
[10,]  11.2
[11,]  11.3
[12,]  11.4
[13,]  11.4
[14,]  11.7
[15,]  12.0
[16,]  12.9
[17,]  12.9
[18,]  13.3
[19,]  13.7
[20,]  13.8
[21,]  14.0
[22,]  14.2
[23,]  14.5
[24,]  16.0
[25,]  16.3
[26,]  17.3
[27,]  17.5
[28,]  17.9
[29,]  18.0
[30,]  18.0
[31,]  20.6

$parent.y
      Volume
 [1,]   10.3
 [2,]   10.3
 [3,]   10.2
 [4,]   16.4
 [5,]   18.8
 [6,]   19.7
 [7,]   15.6
 [8,]   18.2
 [9,]   22.6
[10,]   19.9
[11,]   24.2
[12,]   21.0
[13,]   21.4
[14,]   21.3
[15,]   19.1
[16,]   22.2
[17,]   33.8
[18,]   27.4
[19,]   25.7
[20,]   24.9
[21,]   34.5
[22,]   31.7
[23,]   36.3
[24,]   38.3
[25,]   42.6
[26,]   55.4
[27,]   55.7
[28,]   58.3
[29,]   51.5
[30,]   51.0
[31,]   77.0

$iter.rsq
[1] 0.3044152

$iter.stderr
     (Intercept) bxh(25.6817-RHS) 
      0.39973858       0.06692328 

attr(,"class")
[1] "varmod"
> attr(earth.trees$varmod, ".Environment") <- old.environment
> 
> printh("summary(earth.trees)")
===summary(earth.trees)
> print(summary(earth.trees))
Call: earth(formula=Volume~Girth, data=trees, nfold=3, ncross=3,
            varmod.method="earth")

              coefficients
(Intercept)      28.766764
h(13.8-Girth)    -3.427802
h(Girth-13.8)     6.570747

Selected 3 of 4 terms, and 1 of 1 predictors
Termination condition: RSq changed by less than 0.001 at 4 terms
Importance: Girth
Number of terms at each degree of interaction: 1 2 (additive model)
GCV 14.20145  RSS 309.6832  GRSq 0.949137  RSq 0.9617962  CVRSq 0.9391778

Note: the cross-validation sd's below are standard deviations across folds

Cross validation:   nterms 3.00 sd 0.00    nvars 1.00 sd 0.00

     CVRSq    sd     MaxErr   sd
     0.939 0.033       9.74 7.81

varmod: method "earth"    min.sd 0.377    iter.rsq 0.304

stddev of predictions:
                  coefficients iter.stderr iter.stderr%
(Intercept)          4.8820836    0.500998           10
h(25.6817-Volume)   -0.2988094   0.0838759           28

                              mean   smallest    largest      ratio
95% prediction interval   14.79879    1.47727   19.13742   12.95458

                                         68%    80%    90%    95% 
response values in prediction interval   68     90     94     97  
> 
> # level arg not allowed with interval="se"
> expect.err(try(predict(earth.trees, interval="se", level=.8)))
Error : predict.varmod: the level argument is not allowed with type="se"
Got expected error from try(predict(earth.trees, interval = "se", level = 0.8))
> 
> printh("predict(earth.trees, interval=\"se\")")
===predict(earth.trees, interval="se")
> stderrs <- predict(earth.trees, interval="se")
> print(stderrs)
 [1] 0.3768615 0.4777686 0.6826204 2.4238612 2.6287131 2.7311390 2.9359909
 [8] 2.9359909 3.0384168 3.1408428 3.2432687 3.3456946 3.3456946 3.6529724
[15] 3.9602502 4.8820836 4.8820836 4.8820836 4.8820836 4.8820836 4.8820836
[22] 4.8820836 4.8820836 4.8820836 4.8820836 4.8820836 4.8820836 4.8820836
[29] 4.8820836 4.8820836 4.8820836
> 
> # level arg not allowed with interval="abs.residual"
> expect.err(try(predict(earth.trees, interval="abs.res", level=.8)))
Error : predict.varmod: the level argument is not allowed with type="abs.residual"
Got expected error from try(predict(earth.trees, interval = "abs.res", level = 0.8))
> 
> printh("predict(earth.trees, interval=\"abs.residual\")")
===predict(earth.trees, interval="abs.residual")
> stderrs <- predict(earth.trees, interval="abs.residual")
> print(stderrs)
 [1] 0.3006919 0.3812042 0.5446523 1.9339615 2.0974096 2.1791337 2.3425818
 [8] 2.3425818 2.4243059 2.5060299 2.5877540 2.6694781 2.6694781 2.9146503
[15] 3.1598225 3.8953391 3.8953391 3.8953391 3.8953391 3.8953391 3.8953391
[22] 3.8953391 3.8953391 3.8953391 3.8953391 3.8953391 3.8953391 3.8953391
[29] 3.8953391 3.8953391 3.8953391
> 
> expect.err(try(predict(earth.trees, newdata=trees, interval="cint")))
Error : predict.varmod: newdata is not allowed with interval="cint"
Got expected error from try(predict(earth.trees, newdata = trees, interval = "cint"))
> 
> printh("predict(earth.trees, interval=\"cint\")")
===predict(earth.trees, interval="cint")
> cints <- predict(earth.trees, interval="cint")
> print(cints)
         fit       lwr      upr
1   9.913855  8.180670 11.64704
2  10.942195  9.733851 12.15054
3  11.627755 10.131546 13.12396
4  17.455018 16.062320 18.84772
5  18.140578 17.312349 18.96881
6  18.483359 18.155164 18.81155
7  19.168919 18.580735 19.75710
8  19.168919 17.894435 20.44340
9  19.511699 18.950181 20.07322
10 19.854479 19.271239 20.43772
11 20.197259 19.045531 21.34899
12 20.540040 18.984171 22.09591
13 20.540040 19.403090 21.67699
14 21.568380 20.852086 22.28467
15 22.596721 20.802748 24.39069
16 25.681742 22.771372 28.59211
17 25.681742 24.802981 26.56050
18 27.052863 24.418080 29.68765
19 28.423983 27.409019 29.43895
20 28.766764 26.130387 31.40314
21 30.080913 28.512795 31.64903
22 31.395063 30.201373 32.58875
23 33.366287 31.481173 35.25140
24 43.222408 42.114638 44.33018
25 45.193632 43.766440 46.62082
26 51.764379 49.523520 54.00524
27 53.078529 52.698811 53.45825
28 55.706828 53.509314 57.90434
29 56.363903 54.636793 58.09101
30 56.363903 56.192801 56.53500
31 73.447846 68.614097 78.28160
> 
> printh("predict(earth.trees, interval=\"pin\", level=.80)")
===predict(earth.trees, interval="pin", level=.80)
> news <- predict(earth.trees, interval="pin", level=.80)
> print(news)
         fit       lwr      upr
1   9.913855  9.430887 10.39682
2  10.942195 10.329910 11.55448
3  11.627755 10.752942 12.50257
4  17.455018 14.348715 20.56132
5  18.140578 14.771747 21.50941
6  18.483359 14.983263 21.98345
7  19.168919 15.406295 22.93154
8  19.168919 15.406295 22.93154
9  19.511699 15.617811 23.40559
10 19.854479 15.829327 23.87963
11 20.197259 16.040843 24.35368
12 20.540040 16.252359 24.82772
13 20.540040 16.252359 24.82772
14 21.568380 16.886908 26.24985
15 22.596721 17.521456 27.67199
16 25.681742 19.425100 31.93838
17 25.681742 19.425100 31.93838
18 27.052863 20.796221 33.30950
19 28.423983 22.167342 34.68063
20 28.766764 22.510122 35.02341
21 30.080913 23.824271 36.33755
22 31.395063 25.138421 37.65170
23 33.366287 27.109645 39.62293
24 43.222408 36.965766 49.47905
25 45.193632 38.936990 51.45027
26 51.764379 45.507738 58.02102
27 53.078529 46.821887 59.33517
28 55.706828 49.450186 61.96347
29 56.363903 50.107261 62.62054
30 56.363903 50.107261 62.62054
31 73.447846 67.191204 79.70449
> expect.err(try(predict(earth.trees, interval="none", level=.80)), "predict.earth: level=0.8 was specified but interval=\"none\"")
Error : predict.earth: level=0.8 was specified but interval="none"
Got expected error from try(predict(earth.trees, interval = "none", level = 0.8))
> expect.err(try(predict(earth.trees, interval="pin", type="class")), "predict.earth: the interval argument is not allowed with type=\"class\"")
Error : predict.earth: the interval argument is not allowed with type="class"
Got expected error from try(predict(earth.trees, interval = "pin", type = "class"))
> expect.err(try(predict(earth.trees, interval="pin", type="cl")), "predict.earth: the interval argument is not allowed with type=\"class\"")
Error : predict.earth: the interval argument is not allowed with type="class"
Got expected error from try(predict(earth.trees, interval = "pin", type = "cl"))
> expect.err(try(predict(earth.trees, interval="pin", type="ter")), "predict.earth: the interval argument is not allowed with type=\"terms\"")
Error : predict.earth: the interval argument is not allowed with type="terms"
Got expected error from try(predict(earth.trees, interval = "pin", type = "ter"))
> 
> printh("print.default(earth.trees$varmod$residmod)")
===print.default(earth.trees$varmod$residmod)
> # have to modify earth.trees because terms field stores the environment
> # as a hex address which messes up the diffs
> earth.trees$varmod$residmod$terms <- NULL
> print.default(earth.trees$varmod$residmod)
$rss
[1] 87.74303

$rsq
[1] 0.3044152

$gcv
[1] 3.469431

$grsq
[1] 0.201497

$bx
      (Intercept) h(25.6817-RHS)
 [1,]           1      15.767888
 [2,]           1      14.739547
 [3,]           1      14.053987
 [4,]           1       8.226724
 [5,]           1       7.541164
 [6,]           1       7.198383
 [7,]           1       6.512823
 [8,]           1       6.512823
 [9,]           1       6.170043
[10,]           1       5.827263
[11,]           1       5.484483
[12,]           1       5.141702
[13,]           1       5.141702
[14,]           1       4.113362
[15,]           1       3.085021
[16,]           1       0.000000
[17,]           1       0.000000
[18,]           1       0.000000
[19,]           1       0.000000
[20,]           1       0.000000
[21,]           1       0.000000
[22,]           1       0.000000
[23,]           1       0.000000
[24,]           1       0.000000
[25,]           1       0.000000
[26,]           1       0.000000
[27,]           1       0.000000
[28,]           1       0.000000
[29,]           1       0.000000
[30,]           1       0.000000
[31,]           1       0.000000

$dirs
               RHS
(Intercept)      0
h(RHS-25.6817)   1
h(25.6817-RHS)  -1
h(RHS-43.2224)   1

$cuts
                    RHS
(Intercept)     0.00000
h(RHS-25.6817) 25.68174
h(25.6817-RHS) 25.68174
h(RHS-43.2224) 43.22241

$selected.terms
[1] 1 3

$prune.terms
     [,1] [,2] [,3] [,4]
[1,]    1    0    0    0
[2,]    1    3    0    0
[3,]    1    3    4    0
[4,]    1    2    3    4

$fitted.values
      abs.resids
 [1,]  0.1360320
 [2,]  0.3812042
 [3,]  0.5446523
 [4,]  1.9339615
 [5,]  2.0974096
 [6,]  2.1791337
 [7,]  2.3425818
 [8,]  2.3425818
 [9,]  2.4243059
[10,]  2.5060299
[11,]  2.5877540
[12,]  2.6694781
[13,]  2.6694781
[14,]  2.9146503
[15,]  3.1598225
[16,]  3.8953391
[17,]  3.8953391
[18,]  3.8953391
[19,]  3.8953391
[20,]  3.8953391
[21,]  3.8953391
[22,]  3.8953391
[23,]  3.8953391
[24,]  3.8953391
[25,]  3.8953391
[26,]  3.8953391
[27,]  3.8953391
[28,]  3.8953391
[29,]  3.8953391
[30,]  3.8953391
[31,]  3.8953391

$residuals
      abs.resids
 [1,]  0.8611800
 [2,]  0.5911208
 [3,]  1.2756088
 [4,] -0.5840137
 [5,] -1.2670169
 [6,] -0.8516886
 [7,]  1.5220327
 [8,] -1.1109111
 [9,]  0.9186446
[10,] -2.2044373
[11,]  1.7622786
[12,] -1.7339517
[13,] -1.5771909
[14,] -2.4489289
[15,]  0.7144529
[16,]  0.1782357
[17,]  4.9607024
[18,] -2.4978292
[19,] -0.8153720
[20,]  0.6349183
[21,]  1.0842203
[22,] -3.1990944
[23,] -0.5302587
[24,]  1.4810292
[25,] -0.9810963
[26,]  0.2812761
[27,] -0.9778296
[28,] -0.7724933
[29,]  1.6608107
[30,]  2.1550503
[31,]  1.4705513

$coefficients
               abs.resids
(Intercept)     3.8953391
h(25.6817-RHS) -0.2384154

$rss.per.response
[1] 87.74303

$rsq.per.response
[1] 0.3044152

$gcv.per.response
[1] 3.469431

$grsq.per.response
[1] 0.201497

$rss.per.subset
[1] 126.14282  87.74303  82.82243  82.80450

$gcv.per.subset
[1] 4.344919 3.469431 3.798070 4.456492

$leverages
 [1] 0.24689453 0.21180022 0.19014329 0.06223841 0.05380006 0.05010267
 [7] 0.04375147 0.04375147 0.04109766 0.03879170 0.03683360 0.03522336
[13] 0.03522336 0.03247977 0.03286691 0.05281259 0.05281259 0.05281259
[19] 0.05281259 0.05281259 0.05281259 0.05281259 0.05281259 0.05281259
[25] 0.05281259 0.05281259 0.05281259 0.05281259 0.05281259 0.05281259
[31] 0.05281259

$pmethod
[1] "backward"

$nprune
NULL

$penalty
[1] 2

$nk
[1] 21

$thresh
[1] 0.001

$termcond
[1] 4

$weights
NULL

$call
earth(formula = abs.resids ~ ., data = data, weights = weights, 
    keepxy = TRUE, trace = trace, minspan = minspan)

$namesx
[1] "RHS"

$modvars
    RHS
RHS   1

$xlevels
named list()

$data
   abs.resids       RHS
1   0.9972120  9.913855
2   0.9723250 10.942195
3   1.8202611 11.627755
4   1.3499478 17.455018
5   0.8303927 18.140578
6   1.3274450 18.483359
7   3.8646145 19.168919
8   1.2316707 19.168919
9   3.3429505 19.511699
10  0.3015926 19.854479
11  4.3500327 20.197259
12  0.9355264 20.540040
13  1.0922872 20.540040
14  0.4657214 21.568380
15  3.8742754 22.596721
16  4.0735748 25.681742
17  8.8560415 25.681742
18  1.3975099 27.052863
19  3.0799671 28.423983
20  4.5302574 28.766764
21  4.9795594 30.080913
22  0.6962448 31.395063
23  3.3650804 33.366287
24  5.3763683 43.222408
25  2.9142428 45.193632
26  4.1766153 51.764379
27  2.9175095 53.078529
28  3.1228458 55.706828
29  5.5561498 56.363903
30  6.0503894 56.363903
31  5.3658904 73.447846

$y
      abs.resids
 [1,]  0.9972120
 [2,]  0.9723250
 [3,]  1.8202611
 [4,]  1.3499478
 [5,]  0.8303927
 [6,]  1.3274450
 [7,]  3.8646145
 [8,]  1.2316707
 [9,]  3.3429505
[10,]  0.3015926
[11,]  4.3500327
[12,]  0.9355264
[13,]  1.0922872
[14,]  0.4657214
[15,]  3.8742754
[16,]  4.0735748
[17,]  8.8560415
[18,]  1.3975099
[19,]  3.0799671
[20,]  4.5302574
[21,]  4.9795594
[22,]  0.6962448
[23,]  3.3650804
[24,]  5.3763683
[25,]  2.9142428
[26,]  4.1766153
[27,]  2.9175095
[28,]  3.1228458
[29,]  5.5561498
[30,]  6.0503894
[31,]  5.3658904

attr(,"class")
[1] "earth"
> # prevent mistakes later where we try to use a modified earth.trees
> remove(earth.trees)
> 
> multifigure("test example for varmod help page", 2, 2)
===test example for varmod help page
> 
> data(ozone1)
> set.seed(1) # optional, for cross validation reproducibility
> 
> a <- earth(O3~temp, data=ozone1, nfold=10, ncross=3, varmod.method="earth")
> 
> print(summary(a)) # note additional info on the variance model
Call: earth(formula=O3~temp, data=ozone1, nfold=10, ncross=3,
            varmod.method="earth")

            coefficients
(Intercept)    7.5768304
h(58-temp)    -0.1572930
h(temp-58)     0.6090229

Selected 3 of 4 terms, and 1 of 1 predictors
Termination condition: RSq changed by less than 0.001 at 4 terms
Importance: temp
Number of terms at each degree of interaction: 1 2 (additive model)
GCV 22.43818  RSS 7181.917  GRSq 0.6514492  RSq 0.6598731  CVRSq 0.6232032

Note: the cross-validation sd's below are standard deviations across folds

Cross validation:   nterms 3.67 sd 1.47    nvars 1.00 sd 0.00

     CVRSq    sd     MaxErr   sd
     0.623 0.106       17.5 11.8

varmod: method "earth"    min.sd 0.464    iter.rsq 0.169

stddev of predictions:
              coefficients iter.stderr iter.stderr%
(Intercept)      6.6003879    0.304075            5
h(16.1032-O3)   -0.3474529   0.0425299           12

                             mean   smallest    largest      ratio
95% prediction interval   18.2071   7.190636   25.87305   3.598158

                                         68%    80%    90%    95% 
response values in prediction interval   71     82     95     97  
> 
> old.mfrow <- par(mfrow=c(2,2))
> 
> # the variance model assumes residuals are symmetric, which is not
> # quite true in this example, so the lower band is a bit too big
> plotmo(a, do.par=FALSE, col.response=1, level=.95, main="earth model: O3~temp")
> 
> plot(a, which=1)            # model selection plot, same as ever
> plot(a, which=3, level=.95) # residual plot: note 95% pred and darker conf intervals
> plot(a, which=3, level=.95, standardize=TRUE) # standardize resids are approx homoscedastic
> 
> par(par=old.mfrow)
> 
> plot(a$varmod)              # plot the embedded variance model (this calls plot.varmod)
> 
> multifigure("test example for plot.varmod help page", 2, 2)
===test example for plot.varmod help page
> 
> # multivariate example (for univariate, see the example on the varmod help page)
> 
> data(ozone1)
> set.seed(1) # optional, for cross validation reproducibility
> 
> mod.temp.vh.doy <- earth(O3~temp+vh+vis+doy, data=ozone1, nfold=5, ncross=3, varmod.method="x.earth")
> 
> print(summary(mod.temp.vh.doy))  # note additional info on the variance model
Call: earth(formula=O3~temp+vh+vis+doy, data=ozone1, nfold=5, ncross=3,
            varmod.method="x.earth")

            coefficients
(Intercept)    9.8874670
h(temp-58)     0.4016529
h(vh-5530)     0.0210146
h(vis-17)     -0.0324305
h(vis-200)     0.0474193
h(106-doy)    -0.0972229
h(doy-151)    -0.0285859

Selected 7 of 15 terms, and 4 of 4 predictors
Termination condition: Reached nk 21
Importance: temp, vis, doy, vh
Number of terms at each degree of interaction: 1 6 (additive model)
GCV 17.87166  RSS 5442.137  GRSq 0.7223847  RSq 0.742267  CVRSq 0.699885

Note: the cross-validation sd's below are standard deviations across folds

Cross validation:   nterms 8.07 sd 1.28    nvars 4.00 sd 0.00

     CVRSq    sd     MaxErr   sd
       0.7 0.071       15.2 13.2

varmod: method "x.earth"    min.sd 0.414    iter.rsq 0.252

stddev of predictions:
            coefficients iter.stderr iter.stderr%
(Intercept)    8.3952546     1.32479           16
h(vh-5690)     0.0137305   0.0026369           19
h(vis-70)     -0.0221452   0.0057626           26
h(vis-150)     0.0221952    0.008622           39
h(doy-119)    -0.0219062   0.0059075           27
h(302-doy)    -0.0216992   0.0061695           28

                              mean   smallest    largest      ratio
95% prediction interval   16.22979   3.466058   31.21429   9.005701

                                         68%    80%    90%    95% 
response values in prediction interval   73     82     93     96  
> 
> plot(mod.temp.vh.doy, level=.95) # note 95% pred and darker conf intervals in resids plot
> 
> plot(mod.temp.vh.doy$varmod)     # plot the variance model (this calls plot.varmod)
> 
> plot(mod.temp.vh.doy, versus="", level=.9, caption="plot.earth versus=\"\"")
> plot(mod.temp.vh.doy, versus="v", level=.9, caption="plot.earth versus=\"v\" and versus=\"temp\"", do.par=2)
> plot(mod.temp.vh.doy, versus="temp", level=.9, caption="", main="temp on same page")
> 
> # plot.earth will silently not plots it cannot plot below, so 1:9 becomes c(3,5,6)
> plot(mod.temp.vh.doy, which=1:9, versus="v", info=T, caption='which=c(3,5) versus="v" info=T')
> par(org.par)
> 
> # versus="b:"
> plot(mod.temp.vh.doy, versus="b:", level=.9,
+      caption="plot.earth versus=\"b:\"")
> 
> # versus="b:" and versus=1:4 with info
> plot(mod.temp.vh.doy, versus="b:", level=.8, info=TRUE,
+      caption="plot.earth versus=\"b:\" with info")
> 
> multifigure("versus=1:4", 3, 3)
===versus=1:4
> 
> plot(mod.temp.vh.doy, versus=1, caption="", do.par=FALSE, which=3)
> do.caption()
> plot(mod.temp.vh.doy, versus=2, caption="", do.par=FALSE)
> plot(mod.temp.vh.doy, versus=3, caption="", do.par=FALSE)
> 
> plot(mod.temp.vh.doy, versus=1, info=TRUE, caption="", do.par=FALSE, which=3)
> plot(mod.temp.vh.doy, versus=2, info=TRUE, caption="", do.par=FALSE)
> plot(mod.temp.vh.doy, versus=3, info=TRUE, caption="", do.par=FALSE)
> 
> plot(mod.temp.vh.doy, versus=1, info=TRUE, caption="", do.par=FALSE, level=.8, which=3)
> plot(mod.temp.vh.doy, versus=2, info=TRUE, caption="", do.par=FALSE, level=.8)
> plot(mod.temp.vh.doy, versus=3, info=TRUE, caption="", do.par=FALSE, level=.8)
> 
> expect.err(try(plot(mod.temp.vh.doy, versus=9)))
Error : versus must be an integer or a string:
  1    fitted (default)
  2    observation numbers
  3    response
  4    leverages
  ""   predictors
  "b:" basis functions
Got expected error from try(plot(mod.temp.vh.doy, versus = 9))
> expect.err(try(plot(mod.temp.vh.doy, versus=1.2)))
Error : versus must be an integer or a string:
  1    fitted (default)
  2    observation numbers
  3    response
  4    leverages
  ""   predictors
  "b:" basis functions
Got expected error from try(plot(mod.temp.vh.doy, versus = 1.2))
> expect.err(try(plot(mod.temp.vh.doy, versus=2:3)))
Error : illegal 'versus' argument (length of 'versus' must be 1 when 'versus' is numeric)
Got expected error from try(plot(mod.temp.vh.doy, versus = 2:3))
> 
> # versus="b:doy"
> 
> plot(mod.temp.vh.doy, versus="b:doy", level=.9, caption="plot.earth versus=\"b:doy\"")
> 
> # test warnings from plotres about which
> plot(mod.temp.vh.doy, which=1, versus="b:doy")
Warning: which=1 is now empty because plots were removed because versus=b:doy
Warning: plotres: nothing to plot
> 
> multifigure("test example in (very old) earth vignette", 2, 2)
===test example in (very old) earth vignette
> 
> data(ozone1)
> x <- ozone1$temp
> y <- ozone1$O3
> 
> set.seed(1) # optional, for cross validation reproducibility
> earth.mod <- earth(y~x, nfold=10, ncross=3, varmod.method="earth", trace=.1)
CV fold  1.1  CVRSq  0.704   n.oof 297 10%   n.infold.nz 297 100%   n.oof.nz  33 100%
CV fold  1.2  CVRSq  0.514   n.oof 297 10%   n.infold.nz 297 100%   n.oof.nz  33 100%
CV fold  1.3  CVRSq  0.774   n.oof 297 10%   n.infold.nz 297 100%   n.oof.nz  33 100%
CV fold  1.4  CVRSq  0.726   n.oof 297 10%   n.infold.nz 297 100%   n.oof.nz  33 100%
CV fold  1.5  CVRSq  0.543   n.oof 297 10%   n.infold.nz 297 100%   n.oof.nz  33 100%
CV fold  1.6  CVRSq  0.695   n.oof 297 10%   n.infold.nz 297 100%   n.oof.nz  33 100%
CV fold  1.7  CVRSq  0.641   n.oof 297 10%   n.infold.nz 297 100%   n.oof.nz  33 100%
CV fold  1.8  CVRSq  0.674   n.oof 297 10%   n.infold.nz 297 100%   n.oof.nz  33 100%
CV fold  1.9  CVRSq  0.482   n.oof 297 10%   n.infold.nz 297 100%   n.oof.nz  33 100%
CV fold  1.10 CVRSq  0.564   n.oof 297 10%   n.infold.nz 297 100%   n.oof.nz  33 100%
CV fold  2.1  CVRSq  0.693   n.oof 297 10%   n.infold.nz 297 100%   n.oof.nz  33 100%
CV fold  2.2  CVRSq  0.568   n.oof 297 10%   n.infold.nz 297 100%   n.oof.nz  33 100%
CV fold  2.3  CVRSq  0.505   n.oof 297 10%   n.infold.nz 297 100%   n.oof.nz  33 100%
CV fold  2.4  CVRSq  0.676   n.oof 297 10%   n.infold.nz 297 100%   n.oof.nz  33 100%
CV fold  2.5  CVRSq  0.377   n.oof 297 10%   n.infold.nz 297 100%   n.oof.nz  33 100%
CV fold  2.6  CVRSq  0.794   n.oof 297 10%   n.infold.nz 297 100%   n.oof.nz  33 100%
CV fold  2.7  CVRSq  0.843   n.oof 297 10%   n.infold.nz 297 100%   n.oof.nz  33 100%
CV fold  2.8  CVRSq  0.534   n.oof 297 10%   n.infold.nz 297 100%   n.oof.nz  33 100%
CV fold  2.9  CVRSq  0.609   n.oof 297 10%   n.infold.nz 297 100%   n.oof.nz  33 100%
CV fold  2.10 CVRSq  0.481   n.oof 297 10%   n.infold.nz 297 100%   n.oof.nz  33 100%
CV fold  3.1  CVRSq  0.647   n.oof 297 10%   n.infold.nz 297 100%   n.oof.nz  33 100%
CV fold  3.2  CVRSq  0.631   n.oof 297 10%   n.infold.nz 297 100%   n.oof.nz  33 100%
CV fold  3.3  CVRSq  0.641   n.oof 297 10%   n.infold.nz 297 100%   n.oof.nz  33 100%
CV fold  3.4  CVRSq  0.565   n.oof 297 10%   n.infold.nz 297 100%   n.oof.nz  33 100%
CV fold  3.5  CVRSq  0.515   n.oof 297 10%   n.infold.nz 297 100%   n.oof.nz  33 100%
CV fold  3.6  CVRSq  0.704   n.oof 297 10%   n.infold.nz 297 100%   n.oof.nz  33 100%
CV fold  3.7  CVRSq  0.611   n.oof 297 10%   n.infold.nz 297 100%   n.oof.nz  33 100%
CV fold  3.8  CVRSq  0.560   n.oof 297 10%   n.infold.nz 297 100%   n.oof.nz  33 100%
CV fold  3.9  CVRSq  0.717   n.oof 297 10%   n.infold.nz 297 100%   n.oof.nz  33 100%
CV fold  3.10 CVRSq  0.709   n.oof 297 10%   n.infold.nz 297 100%   n.oof.nz  33 100%
CV all        CVRSq  0.623                   n.infold.nz 330 100%
> predict <- predict(earth.mod, interval="pint")
> cat("\npredict(earth.mod, interval=\"pint\")\n")

predict(earth.mod, interval="pint")
> print(head(predict))
       fit        lwr       upr
1 4.745556 -0.4564985  9.947611
2 5.532021 -0.2056124 11.269655
3 6.947658  0.2459826 13.649334
4 3.959091 -0.7073845  8.625567
5 5.532021 -0.2056124 11.269655
6 7.104951  0.2961598 13.913743
> 
> order <- order(x)
> x <- x[order]
> y <- y[order]
> predict <- predict[order,]
> 
> inconf <- y >= predict$lwr & y <= predict$upr
> 
> plot(x, y, pch=20, col=ifelse(inconf, 1, 2), main=sprint(
+     "Prediction intervals\n%.0f%% of the points are in the estimated band",
+     100 * sum(inconf) / length(y)))
> do.caption()
> 
> lines(x, predict$fit)
> lines(x, predict$lwr, lty=2)
> lines(x, predict$upr, lty=2)
> 
> # Plot the Residuals vs Fitted graph
> plot(earth.mod, which=3, level=.95)
> 
> # Plot the embedded residual model
> plot(earth.mod$varmod, do.par=F, which=1:2)
> 
> cat('head(residuals(earth.mod))\n')
head(residuals(earth.mod))
> print(head(residuals(earth.mod)))
           y
1 -1.7455563
2 -0.5320213
3 -1.9476584
4  2.0409087
5 -1.5320213
6 -3.1049514
> cat('head(residuals(earth.mod, type="standardize"))\n')
head(residuals(earth.mod, type="standardize"))
> print(head(residuals(earth.mod, type="standardize")))
           y
1 -0.6627370
2 -0.1824742
3 -0.5713109
4  0.8688808
5 -0.5254570
6 -0.8967349
> 
> multifigure("plot.earth varmod options", 2, 2)
===plot.earth varmod options
> 
> plot(earth.mod, which=3, level=.95, level.shade=0, main="plot.earth varmod options")
> do.caption()
> plot(earth.mod, which=3, level.shade="orange", level.shade2="darkgray", level=.99)
> plot(earth.mod, which=3, level=.95, level.shade=0, level.shade2="mistyrose4")
> 
> multifigure("plot.earth delever and standardize", 2, 2)
===plot.earth delever and standardize
> 
> set.seed(4)
> earth.mod1 <- earth(O3~temp, data=ozone1, nfold=5, ncross=3, varmod.method="lm", keepxy=T, trace=.5)
Model with pmethod="backward": GRSq 0.651 RSq 0.660 nterms 3
CV fold  1.1  CVRSq  0.648   n.oof 264 20%   n.infold.nz 264 100%   n.oof.nz  66 100%
CV fold  1.2  CVRSq  0.739   n.oof 264 20%   n.infold.nz 264 100%   n.oof.nz  66 100%
CV fold  1.3  CVRSq  0.549   n.oof 264 20%   n.infold.nz 264 100%   n.oof.nz  66 100%
CV fold  1.4  CVRSq  0.436   n.oof 264 20%   n.infold.nz 264 100%   n.oof.nz  66 100%
CV fold  1.5  CVRSq  0.665   n.oof 264 20%   n.infold.nz 264 100%   n.oof.nz  66 100%
CV fold  2.1  CVRSq  0.666   n.oof 264 20%   n.infold.nz 264 100%   n.oof.nz  66 100%
CV fold  2.2  CVRSq  0.673   n.oof 264 20%   n.infold.nz 264 100%   n.oof.nz  66 100%
CV fold  2.3  CVRSq  0.652   n.oof 264 20%   n.infold.nz 264 100%   n.oof.nz  66 100%
CV fold  2.4  CVRSq  0.645   n.oof 264 20%   n.infold.nz 264 100%   n.oof.nz  66 100%
CV fold  2.5  CVRSq  0.496   n.oof 264 20%   n.infold.nz 264 100%   n.oof.nz  66 100%
CV fold  3.1  CVRSq  0.671   n.oof 264 20%   n.infold.nz 264 100%   n.oof.nz  66 100%
CV fold  3.2  CVRSq  0.588   n.oof 264 20%   n.infold.nz 264 100%   n.oof.nz  66 100%
CV fold  3.3  CVRSq  0.632   n.oof 264 20%   n.infold.nz 264 100%   n.oof.nz  66 100%
CV fold  3.4  CVRSq  0.616   n.oof 264 20%   n.infold.nz 264 100%   n.oof.nz  66 100%
CV fold  3.5  CVRSq  0.610   n.oof 264 20%   n.infold.nz 264 100%   n.oof.nz  66 100%
CV all        CVRSq  0.619                   n.infold.nz 330 100%


varmod method="lm" rmethod="hc12" lambda=1 exponent=1 conv=1 clamp=0.1 minspan=-3:
     iter weight.ratio coefchange% (Intercept)   O3
        1           11        0.00         1.7 0.18
        2           15       15.79         1.4 0.21
        3           16        2.25         1.4 0.21
        4           16        0.32         1.3 0.21

> plot(earth.mod1, which=3, ylim=c(-16,20), info=TRUE, level=.95)
> do.caption()
> plot(earth.mod1, which=3, ylim=c(-16,20), delever=TRUE, level=.95)
> plot(earth.mod1, which=3, standardize=TRUE, info=TRUE,    level=.95)
> # the standardize and delever arguments cannot both be set
> expect.err(try(plot(earth.mod1, which=3, standardize=TRUE, delever=TRUE, level=.95)))
Error : the standardize and delever arguments cannot both be set
Got expected error from try(plot(earth.mod1, which = 3, standardize = TRUE, delever = TRUE,     level = 0.95))
> 
> multifigure("plot.earth which=5 and which=6", 2, 3)
===plot.earth which=5 and which=6
> plot(earth.mod1, which=5, info=T,            main="which=5, info=T")
> plot(earth.mod1, which=5, standardize=T, info=T, main="which=5, standardize=T, info=T")
> plot(earth.mod1, which=5, standardize=T,         main="which=5, standardize=T")
> do.caption()
> plot(earth.mod1, which=6, info=T,            main="which=6, info=T")
> plot(earth.mod1, which=6, standardize=T, info=T, main="which=6, standardize=T, info=T")
> plot(earth.mod1, which=6, standardize=T,         main="which=6, standardize=T")
> 
> multifigure("plot.earth which=7", 2, 3)
===plot.earth which=7
> plot(earth.mod1, which=7, info=T,            main="which=7, info=T")
> plot(earth.mod1, which=7, standardize=T, info=T, main="which=7, standardize=T, info=T")
> plot(earth.mod1, which=7, standardize=T,         main="which=7, standardize=T")
> do.caption()
> 
> multifigure("plot.earth which=8 and which=9", 2, 3)
===plot.earth which=8 and which=9
> plot(earth.mod1, which=8, info=T,            main="which=8, info=T")
> plot(earth.mod1, which=8, standardize=T, info=T, main="which=8, standardize=T, info=T")
> plot(earth.mod1, which=8, standardize=T,         main="which=8, standardize=T")
> do.caption()
> plot(earth.mod1, which=9, info=T,            main="which=9, info=T")
> plot(earth.mod1, which=9, standardize=T, info=T, main="which=9, standardize=T, info=T")
> plot(earth.mod1, which=9, standardize=T,         main="which=9, standardize=T")
> 
> multifigure("plot.earth versus=4, which=3 and which=5", 2, 3)
===plot.earth versus=4, which=3 and which=5
> plot(earth.mod1, versus=4, which=3,                    main="versus=4, which=3")
> plot(earth.mod1, versus=4, which=3, standardize=T, info=T, main="versus=4, which=3, standardize=T, info=T")
> plot(earth.mod1, versus=4, which=3, standardize=T,         main="versus=4, which=3, standardize=T")
> do.caption()
> plot(earth.mod1, versus=4, which=5,                    main="versus=4, which=5")
> plot(earth.mod1, versus=4, which=5, standardize=T, info=T, main="versus=4, which=5, standardize=T, info=T")
> plot(earth.mod1, versus=4, which=5, standardize=T,         main="versus=4, which=5, standardize=T")
> 
> cat("summary(earth.mod1, newdata=ozone1)\n")
summary(earth.mod1, newdata=ozone1)
> print(summary(earth.mod1, newdata=ozone1))
RSq 0.660 on newdata (330 cases)

                                 68%    80%    90%    95% 
newdata in prediction interval   72     83     93     97  
> 
> cat("summary(earth.mod1, newdata=ozone1[1:100,]:)\n")
summary(earth.mod1, newdata=ozone1[1:100,]:)
> print(summary(earth.mod1, newdata=ozone1[1:100,]))
RSq 0.199 on newdata (100 cases)

                                 68%    80%    90%    95% 
newdata in prediction interval   79     85     92     95  
> 
> expect.err(try(summary(earth.mod1, newdata=c(1,2,3))),
+            "plotmo_response: newdata must be a matrix or data.frame")
Error : plotmo_response: newdata must be a matrix or data.frame
Got expected error from try(summary(earth.mod1, newdata = c(1, 2, 3)))
> expect.err(try(summary(earth.mod1, newdata=ozone1[1:100,1:3])),
+            "response with newdata object 'temp' not found")
Error : response with newdata object 'temp' not found
Got expected error from try(summary(earth.mod1, newdata = ozone1[1:100, 1:3]))
> 
> # earth.default
> O3 <- ozone1$O3
> temper <- ozone1$temp
> set.seed(4)
> earth.default <- earth(temper, O3, nfold=5, ncross=3, varmod.method="lm")
> cat("summary(earth.default)\n")
summary(earth.default)
> print(summary(earth.default))
Call: earth(x=temper, y=O3, nfold=5, ncross=3, varmod.method="lm")

             coefficients
(Intercept)     7.5768304
h(58-temper)   -0.1572930
h(temper-58)    0.6090229

Selected 3 of 4 terms, and 1 of 1 predictors
Termination condition: RSq changed by less than 0.001 at 4 terms
Importance: temper
Number of terms at each degree of interaction: 1 2 (additive model)
GCV 22.43818  RSS 7181.917  GRSq 0.6514492  RSq 0.6598731  CVRSq 0.6191483

Note: the cross-validation sd's below are standard deviations across folds

Cross validation:   nterms 3.87 sd 1.25    nvars 1.00 sd 0.00

     CVRSq    sd     MaxErr   sd
     0.619 0.076       19.6 11.4

varmod: method "lm"    min.sd 0.481    iter.rsq 0.149

stddev of predictions:
            coefficients iter.stderr iter.stderr%
(Intercept)    1.6911524    0.333325           20
O3             0.2644448   0.0348975           13

                            mean   smallest    largest      ratio
95% prediction interval   18.836   9.102701   36.57943   4.018524

                                         68%    80%    90%    95% 
response values in prediction interval   72     83     93     97  
> expect.err(try(summary(earth.default, newdata=ozone1[1:100,])),
+           "model.matrix.earth could not interpret the data")

stats::predict(earth.object, data.frame[100,10], type="response")

Error : model.matrix.earth could not interpret the data
           model.matrix returned 0 columns: 
           need 1 column: "temper"
Got expected error from try(summary(earth.default, newdata = ozone1[1:100, ]))
> newdata_temper <- matrix(c(O3[1:100], temper[1:100]), ncol=2)
> expect.err(try(summary(earth.default, newdata=newdata_temper)),
+           "cannot get response from newdata because newdata has no column names")
Error : cannot get response from newdata because newdata has no column names
Got expected error from try(summary(earth.default, newdata = newdata_temper))
> colnames(newdata_temper) <- c("O3", "temper")
> cat("summary(earth.default, newdata=newdata_temper)\n")
summary(earth.default, newdata=newdata_temper)
> print(summary(earth.default, newdata=newdata_temper))
RSq 0.199 on newdata (100 cases)

                                 68%    80%    90%    95% 
newdata in prediction interval   79     85     92     95  
> plot(earth.default, level=.80, caption="earth.default")
> options(warn=2) # treat warnings as errors
> expect.err(try(plotmo(earth.default, level=.80, col.response=3)),
+            "Cannot determine which variables to plot (use all1=TRUE?)")
Error : (converted from warning) Cannot determine which variables to plot (use all1=TRUE?)
             single.names=c(temper,temper)
             colnames(x)=x

Got expected error from try(plotmo(earth.default, level = 0.8, col.response = 3))
> plotmo(earth.default, all1=TRUE, level=.80, col.response=3, caption="earth.default\nlevel = .80")
> options(warn=1) # print warnings as they occur
> 
> multifigure("plot(earth.mod2)", 2, 2)
===plot(earth.mod2)
> set.seed(5)
> earth.mod2 <- earth(y~x, nfold=10, ncross=5, varmod.method="earth")
> plot(earth.mod2, caption="plot(earth.mod2)", level=.95)
> do.caption()
> 
> multifigure("plot(earth.mod2) with standardize=TRUE", 2, 2)
===plot(earth.mod2) with standardize=TRUE
> plot(earth.mod2, standardize=TRUE, level=.95,
+      caption="plot(earth.mod2, standardize=TRUE, level=.95)")
> do.caption()
> 
> multifigure("plot.varmod by calling plot(earth.mod2$varmod)", 2, 2)
===plot.varmod by calling plot(earth.mod2$varmod)
> plot(earth.mod2$varmod)
> 
> multifigure("embedded earth model by calling plot(earth.mod2$varmod$residmod)", 2, 2)
===embedded earth model by calling plot(earth.mod2$varmod$residmod)
> plot(earth.mod2$varmod$residmod, caption="embedded earth model")
> do.caption()
> 
> # test varmod.* args like varmod.conv
> 
> # cat("test varmod.exponent=.5\n")
> # set.seed(1)
> # (earth(Volume~Girth, data=trees, nfold=3, ncross=3, varmod.method="lm", trace=.3, varmod.exponent=.5))
> 
> # cat("test varmod.lambda=2/3\n")
> # set.seed(1)
> # (earth(Volume~Girth, data=trees, nfold=3, ncross=3, varmod.method="lm", trace=.3, varmod.lambda=2/3))
> 
> cat("test varmod.conv=50%\n")
test varmod.conv=50%
> set.seed(1)
> (earth(Volume~Girth, data=trees, nfold=3, ncross=3, varmod.method="lm", trace=.3, varmod.conv=50))
CV fold  1.1  CVRSq  0.927   n.oof 20 35%   n.infold.nz 20 100%   n.oof.nz 11 100%
CV fold  1.2  CVRSq  0.953   n.oof 21 32%   n.infold.nz 21 100%   n.oof.nz 10 100%
CV fold  1.3  CVRSq  0.927   n.oof 21 32%   n.infold.nz 21 100%   n.oof.nz 10 100%
CV fold  2.1  CVRSq  0.263   n.oof 20 35%   n.infold.nz 20 100%   n.oof.nz 11 100%
CV fold  2.2  CVRSq  0.940   n.oof 21 32%   n.infold.nz 21 100%   n.oof.nz 10 100%
CV fold  2.3  CVRSq  0.966   n.oof 21 32%   n.infold.nz 21 100%   n.oof.nz 10 100%
CV fold  3.1  CVRSq  0.965   n.oof 20 35%   n.infold.nz 20 100%   n.oof.nz 11 100%
CV fold  3.2  CVRSq  0.968   n.oof 21 32%   n.infold.nz 21 100%   n.oof.nz 10 100%
CV fold  3.3  CVRSq  0.921   n.oof 21 32%   n.infold.nz 21 100%   n.oof.nz 10 100%
CV all        CVRSq  0.870                  n.infold.nz 31 100%

varmod method="lm" rmethod="hc12" lambda=1 exponent=1 conv=50 clamp=0.1 minspan=-3:
     iter weight.ratio coefchange% (Intercept) Volume
        1          2.3           0         2.9  0.026
        2          1.8          20         3.1  0.017

Selected 3 of 4 terms, and 1 of 1 predictors
Termination condition: RSq changed by less than 0.001 at 4 terms
Importance: Girth
Number of terms at each degree of interaction: 1 2 (additive model)
GCV 14.20145  RSS 309.6832  GRSq 0.949137  RSq 0.9617962  CVRSq 0.8701366
> 
> cat("test varmod.conv=-5\n")
test varmod.conv=-5
> set.seed(1)
> (earth(Volume~Girth, data=trees, nfold=3, ncross=3, varmod.method="lm", trace=.3, varmod.conv=-5))
CV fold  1.1  CVRSq  0.927   n.oof 20 35%   n.infold.nz 20 100%   n.oof.nz 11 100%
CV fold  1.2  CVRSq  0.953   n.oof 21 32%   n.infold.nz 21 100%   n.oof.nz 10 100%
CV fold  1.3  CVRSq  0.927   n.oof 21 32%   n.infold.nz 21 100%   n.oof.nz 10 100%
CV fold  2.1  CVRSq  0.263   n.oof 20 35%   n.infold.nz 20 100%   n.oof.nz 11 100%
CV fold  2.2  CVRSq  0.940   n.oof 21 32%   n.infold.nz 21 100%   n.oof.nz 10 100%
CV fold  2.3  CVRSq  0.966   n.oof 21 32%   n.infold.nz 21 100%   n.oof.nz 10 100%
CV fold  3.1  CVRSq  0.965   n.oof 20 35%   n.infold.nz 20 100%   n.oof.nz 11 100%
CV fold  3.2  CVRSq  0.968   n.oof 21 32%   n.infold.nz 21 100%   n.oof.nz 10 100%
CV fold  3.3  CVRSq  0.921   n.oof 21 32%   n.infold.nz 21 100%   n.oof.nz 10 100%
CV all        CVRSq  0.870                  n.infold.nz 31 100%

varmod method="lm" rmethod="hc12" lambda=1 exponent=1 conv=-5 clamp=0.1 minspan=-3:
     iter weight.ratio coefchange% (Intercept) Volume
        1          2.3         0.0         2.9  0.026
        2          1.8        19.9         3.1  0.017
        3          2.0         7.1         3.1  0.021
        4          1.9         2.7         3.1  0.019
        5          1.9         1.0         3.1  0.020

Selected 3 of 4 terms, and 1 of 1 predictors
Termination condition: RSq changed by less than 0.001 at 4 terms
Importance: Girth
Number of terms at each degree of interaction: 1 2 (additive model)
GCV 14.20145  RSS 309.6832  GRSq 0.949137  RSq 0.9617962  CVRSq 0.8701366
> 
> cat("test varmod.clamp\n")
test varmod.clamp
> set.seed(1)
> a.noclamp <- earth(Volume~Girth, data=trees, nfold=3, ncross=3, varmod.method="lm")
> plot(a.noclamp$varmod, which=1:2, caption="a.noclamp and a.clamp", do.par=FALSE)
> set.seed(1)
> a.clamp <- earth(Volume~Girth, data=trees, nfold=3, ncross=3, varmod.method="lm", varmod.clamp=.6)
> plot(a.clamp$varmod, which=1:2, caption="", do.par=FALSE)
> 
> cat("test varmod.minspan=-5\n")
test varmod.minspan=-5
> set.seed(1)
> a.varmod.minspan.minus5 <- earth(Volume~Girth, data=trees, nfold=3, ncross=3, varmod.method="earth", trace=.3, varmod.minspan=-5)
CV fold  1.1  CVRSq  0.927   n.oof 20 35%   n.infold.nz 20 100%   n.oof.nz 11 100%
CV fold  1.2  CVRSq  0.953   n.oof 21 32%   n.infold.nz 21 100%   n.oof.nz 10 100%
CV fold  1.3  CVRSq  0.927   n.oof 21 32%   n.infold.nz 21 100%   n.oof.nz 10 100%
CV fold  2.1  CVRSq  0.263   n.oof 20 35%   n.infold.nz 20 100%   n.oof.nz 11 100%
CV fold  2.2  CVRSq  0.940   n.oof 21 32%   n.infold.nz 21 100%   n.oof.nz 10 100%
CV fold  2.3  CVRSq  0.966   n.oof 21 32%   n.infold.nz 21 100%   n.oof.nz 10 100%
CV fold  3.1  CVRSq  0.965   n.oof 20 35%   n.infold.nz 20 100%   n.oof.nz 11 100%
CV fold  3.2  CVRSq  0.968   n.oof 21 32%   n.infold.nz 21 100%   n.oof.nz 10 100%
CV fold  3.3  CVRSq  0.921   n.oof 21 32%   n.infold.nz 21 100%   n.oof.nz 10 100%
CV all        CVRSq  0.870                  n.infold.nz 31 100%

varmod method="earth" rmethod="hc12" lambda=1 exponent=1 conv=1 clamp=0.1 minspan=-5:
     iter weight.ratio coefchange% (Intercept) h(Volume-19.1689)
        1          6.9           0         2.5              0.06
 h(19.1689-Volume)
              0.45

> print(coef(a.varmod.minspan.minus5$varmod))
      (Intercept) h(Volume-19.1689) h(19.1689-Volume) 
       3.19140324        0.07540525        0.55793565 
> cat("test varmod.minspan=1\n")
test varmod.minspan=1
> set.seed(1)
> a.varmod.minspan1 <- earth(Volume~Girth, data=trees, nfold=3, ncross=3, varmod.method="earth", trace=.3, varmod.minspan=1)
CV fold  1.1  CVRSq  0.927   n.oof 20 35%   n.infold.nz 20 100%   n.oof.nz 11 100%
CV fold  1.2  CVRSq  0.953   n.oof 21 32%   n.infold.nz 21 100%   n.oof.nz 10 100%
CV fold  1.3  CVRSq  0.927   n.oof 21 32%   n.infold.nz 21 100%   n.oof.nz 10 100%
CV fold  2.1  CVRSq  0.263   n.oof 20 35%   n.infold.nz 20 100%   n.oof.nz 11 100%
CV fold  2.2  CVRSq  0.940   n.oof 21 32%   n.infold.nz 21 100%   n.oof.nz 10 100%
CV fold  2.3  CVRSq  0.966   n.oof 21 32%   n.infold.nz 21 100%   n.oof.nz 10 100%
CV fold  3.1  CVRSq  0.965   n.oof 20 35%   n.infold.nz 20 100%   n.oof.nz 11 100%
CV fold  3.2  CVRSq  0.968   n.oof 21 32%   n.infold.nz 21 100%   n.oof.nz 10 100%
CV fold  3.3  CVRSq  0.921   n.oof 21 32%   n.infold.nz 21 100%   n.oof.nz 10 100%
CV all        CVRSq  0.870                  n.infold.nz 31 100%

varmod method="earth" rmethod="hc12" lambda=1 exponent=1 conv=1 clamp=0.1 minspan=1:
     iter weight.ratio coefchange% (Intercept) h(Volume-19.1689)
        1          6.9           0         2.5              0.06
 h(19.1689-Volume)
              0.45

> print(coef(a.varmod.minspan1$varmod))
      (Intercept) h(Volume-19.1689) h(19.1689-Volume) 
       3.19140324        0.07540525        0.55793565 
> 
> # gam and y.gam are repeated below and on the repeat we will use the mgcv not gam package
> use.mgcv.package <- FALSE
> 
> for(varmod.method in c(earth:::VARMOD.METHODS, "gam", "x.gam")) {
+ 
+     multifigure(sprint("varmod.method=\"%s\"", varmod.method), 2, 3)
+     par(mar = c(3, 3, 2, 3)) # space for right margin axis
+ 
+     if(varmod.method %in% c("gam", "x.gam")) {
+         if(use.mgcv.package) {
+             # TODO with R 3.2.1 unload(gam) no longer works
+             cat("skipping mgcv tests\n")
+             next                                # NOTE next
+             cat("library(mgcv)\n")
+             library(mgcv)
+         } else
+             library(gam)
+     }
+     set.seed(2019)
+     # may 2019: following added because gam version 1.16 R version 3.6.0 gives Warning: non-list contrasts argument ignored
+     if(varmod.method %in% c("gam", "x.gam"))
+         options(warn=1)
+     earth.mod <- earth(Volume~Girth, data=trees, nfold=3, ncross=3,
+                        varmod.method=varmod.method,
+                        trace=if(varmod.method %in% c("const", "lm", "power")) .3 else 0)
+     printh(sprint("varmod.method %s: summary(earth.mod)", varmod.method))
+     printh("summary(earth.mod)")
+     print(summary(earth.mod))
+ 
+     if(use.mgcv.package && (varmod.method == "x.gam" || varmod.method == "gam")) {
+         # summary(mgcv) prints environment as hex address which messes up the diffs
+         printh("skipping summary(mgcv::gam) etc.\n")
+     } else {
+         printh("earth.mod$varmod")
+         print(earth.mod$varmod, style="unit")
+ 
+         printh("summary(earth.mod$varmod)")
+         print(summary(earth.mod$varmod))
+ 
+         printh("summary(earth.mod$varmod$residmod)")
+         print(summary(earth.mod$varmod$residmod))
+     }
+     printh(sprint("varmod.method %s: predict(earth.mod, interval=\"pint\")", varmod.method))
+     pints <- predict(earth.mod, interval="pint")
+     print(pints)
+ 
+     plotmo(earth.mod$varmod, do.par=FALSE, col.response=2, clip=FALSE,
+            main="plotmo residual model",
+            xlab="x", ylab="varmod residuals")
+ 
+     plotmo(earth.mod, level=.90, do.par=FALSE, col.response=1, clip=FALSE,
+            main="main model plotmo Girth")
+     do.caption()
+ 
+     plot(earth.mod, which=3, do.par=FALSE, level=.95)
+ 
+     # plot.varmod
+     plot(earth.mod$varmod, do.par=FALSE, which=1:3, info=(varmod.method=="earth"))
+ 
+     # on second use of gam and y.gam we want to use the mgcv package
+     if(varmod.method == "x.gam" && !use.mgcv.package) {
+         use.mgcv.package <- TRUE
+         cat("detach(\"package:gam\", unload=TRUE)\n")
+         detach("package:gam", unload=TRUE)
+     }
+ }
===varmod.method="const"
CV fold  1.1  CVRSq  0.913   n.oof 20 35%   n.infold.nz 20 100%   n.oof.nz 11 100%
CV fold  1.2  CVRSq  0.949   n.oof 21 32%   n.infold.nz 21 100%   n.oof.nz 10 100%
CV fold  1.3  CVRSq  0.928   n.oof 21 32%   n.infold.nz 21 100%   n.oof.nz 10 100%
CV fold  2.1  CVRSq  0.952   n.oof 20 35%   n.infold.nz 20 100%   n.oof.nz 11 100%
CV fold  2.2  CVRSq  0.917   n.oof 21 32%   n.infold.nz 21 100%   n.oof.nz 10 100%
CV fold  2.3  CVRSq  0.947   n.oof 21 32%   n.infold.nz 21 100%   n.oof.nz 10 100%
CV fold  3.1  CVRSq  0.924   n.oof 20 35%   n.infold.nz 20 100%   n.oof.nz 11 100%
CV fold  3.2  CVRSq  0.974   n.oof 21 32%   n.infold.nz 21 100%   n.oof.nz 10 100%
CV fold  3.3  CVRSq  0.957   n.oof 21 32%   n.infold.nz 21 100%   n.oof.nz 10 100%
CV all        CVRSq  0.940                  n.infold.nz 31 100%

varmod method="const" rmethod="hc12" lambda=1 exponent=1 conv=1 clamp=0.1 minspan=-3:
     iter weight.ratio coefchange% (Intercept)
        1            1           0           3

===varmod.method const: summary(earth.mod)
===summary(earth.mod)
Call: earth(formula=Volume~Girth, data=trees,
            trace=if(varmod.method%in%c("const","lm","power"))0.3els...),
            nfold=3, ncross=3, varmod.method=varmod.method)

              coefficients
(Intercept)      28.766764
h(13.8-Girth)    -3.427802
h(Girth-13.8)     6.570747

Selected 3 of 4 terms, and 1 of 1 predictors
Termination condition: RSq changed by less than 0.001 at 4 terms
Importance: Girth
Number of terms at each degree of interaction: 1 2 (additive model)
GCV 14.20145  RSS 309.6832  GRSq 0.949137  RSq 0.9617962  CVRSq 0.9401008

Note: the cross-validation sd's below are standard deviations across folds

Cross validation:   nterms 3.00 sd 0.00    nvars 1.00 sd 0.00

     CVRSq   sd     MaxErr   sd
      0.94 0.02       10.4 7.04

varmod: method "const"    min.sd 0.38

stddev of predictions:
            coefficients iter.stderr iter.stderr%
(Intercept)      3.80095    0.464479           12

                              mean   smallest    largest   ratio
95% prediction interval   14.89945   14.89945   14.89945       1

                                         68%    80%    90%    95% 
response values in prediction interval   77     90     97     97  
===earth.mod$varmod
method "const"    min.sd 0.38

stddev of predictions (scaled by unit):
            coefficients iter.stderr iter.stderr%
(Intercept)          1.0       0.122           12
unit                 3.8          NA           NA

                          mean   smallest   largest   ratio
95% prediction interval     15         15        15       1

                                         68%    80%    90%    95% 
response values in prediction interval   77     90     97     97  
===summary(earth.mod$varmod)
Parent model: earth(formula=Volume~Girth, data=trees,
                    trace=if(varmod.method%in%c("const","lm","power"))0.3els...),
                    nfold=3, ncross=3, varmod.method=varmod.method)

method "const"    min.sd 0.38

stddev of predictions:
            coefficients iter.stderr iter.stderr%
(Intercept)          3.8        0.46           12

                          mean   smallest   largest   ratio
95% prediction interval     15         15        15       1

                                         68%    80%    90%    95% 
response values in prediction interval   77     90     97     97  

Regression submodel (Abs Residuals):

Call:
lm(formula = abs.resids ~ 1, data = data, weights = weights, 
    y = TRUE)

Coefficients:
(Intercept)  
          3  

===summary(earth.mod$varmod$residmod)

Call:
lm(formula = abs.resids ~ 1, data = data, weights = weights, 
    y = TRUE)

Residuals:
    Min      1Q  Median      3Q     Max 
-2.8891 -1.8867  0.0443  1.1643  5.9181 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)   3.0327     0.3706   8.183 3.91e-09 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 2.063 on 30 degrees of freedom

===varmod.method const: predict(earth.mod, interval="pint")
         fit       lwr      upr
1   9.913855  2.464130 17.36358
2  10.942195  3.492471 18.39192
3  11.627755  4.178031 19.07748
4  17.455018 10.005294 24.90474
5  18.140578 10.690854 25.59030
6  18.483359 11.033634 25.93308
7  19.168919 11.719195 26.61864
8  19.168919 11.719195 26.61864
9  19.511699 12.061975 26.96142
10 19.854479 12.404755 27.30420
11 20.197259 12.747535 27.64698
12 20.540040 13.090315 27.98976
13 20.540040 13.090315 27.98976
14 21.568380 14.118656 29.01810
15 22.596721 15.146996 30.04644
16 25.681742 18.232018 33.13147
17 25.681742 18.232018 33.13147
18 27.052863 19.603138 34.50259
19 28.423983 20.974259 35.87371
20 28.766764 21.317039 36.21649
21 30.080913 22.631189 37.53064
22 31.395063 23.945338 38.84479
23 33.366287 25.916562 40.81601
24 43.222408 35.772684 50.67213
25 45.193632 37.743908 52.64336
26 51.764379 44.314655 59.21410
27 53.078529 45.628805 60.52825
28 55.706828 48.257104 63.15655
29 56.363903 48.914178 63.81363
30 56.363903 48.914178 63.81363
31 73.447846 65.998122 80.89757
===varmod.method="power"
CV fold  1.1  CVRSq  0.913   n.oof 20 35%   n.infold.nz 20 100%   n.oof.nz 11 100%
CV fold  1.2  CVRSq  0.949   n.oof 21 32%   n.infold.nz 21 100%   n.oof.nz 10 100%
CV fold  1.3  CVRSq  0.928   n.oof 21 32%   n.infold.nz 21 100%   n.oof.nz 10 100%
CV fold  2.1  CVRSq  0.952   n.oof 20 35%   n.infold.nz 20 100%   n.oof.nz 11 100%
CV fold  2.2  CVRSq  0.917   n.oof 21 32%   n.infold.nz 21 100%   n.oof.nz 10 100%
CV fold  2.3  CVRSq  0.947   n.oof 21 32%   n.infold.nz 21 100%   n.oof.nz 10 100%
CV fold  3.1  CVRSq  0.924   n.oof 20 35%   n.infold.nz 20 100%   n.oof.nz 11 100%
CV fold  3.2  CVRSq  0.974   n.oof 21 32%   n.infold.nz 21 100%   n.oof.nz 10 100%
CV fold  3.3  CVRSq  0.957   n.oof 21 32%   n.infold.nz 21 100%   n.oof.nz 10 100%
CV all        CVRSq  0.940                  n.infold.nz 31 100%

varmod method="power" rmethod="hc12" lambda=1 exponent=1 conv=1 clamp=0.1 minspan=-3:

     start: (Intercept)=1.1    coef=0.064    exponent=1

     iter weight.ratio coefchange% (Intercept) coef exponent
        1           19        0.00       -4.28 2.89     0.28
        2           14      141.52        0.69 0.12     0.87
        3           16       69.67        0.13 0.25     0.72
        4           15       69.80        0.35 0.19     0.78
        5           15       10.17        0.28 0.21     0.76
        6           15        3.92        0.30 0.20     0.77
        7           15        1.22        0.30 0.21     0.77
        8           15        0.41        0.30 0.20     0.77

===varmod.method power: summary(earth.mod)
===summary(earth.mod)
Call: earth(formula=Volume~Girth, data=trees,
            trace=if(varmod.method%in%c("const","lm","power"))0.3els...),
            nfold=3, ncross=3, varmod.method=varmod.method)

              coefficients
(Intercept)      28.766764
h(13.8-Girth)    -3.427802
h(Girth-13.8)     6.570747

Selected 3 of 4 terms, and 1 of 1 predictors
Termination condition: RSq changed by less than 0.001 at 4 terms
Importance: Girth
Number of terms at each degree of interaction: 1 2 (additive model)
GCV 14.20145  RSS 309.6832  GRSq 0.949137  RSq 0.9617962  CVRSq 0.9401008

Note: the cross-validation sd's below are standard deviations across folds

Cross validation:   nterms 3.00 sd 0.00    nvars 1.00 sd 0.00

     CVRSq   sd     MaxErr   sd
      0.94 0.02       10.4 7.04

varmod: method "power"    min.sd 0.381    iter.rsq 0.195

stddev of predictions:
            coefficients iter.stderr iter.stderr%
(Intercept)    0.3731063     4.80734          big
coef           0.2564899     1.41384          551
exponent       0.7682587     1.19522          156

                              mean   smallest    largest      ratio
95% prediction interval   14.92662   7.320158   28.74623   3.926996

                                         68%    80%    90%    95% 
response values in prediction interval   74     94     97     97  
===earth.mod$varmod
method "power"    min.sd 0.381    iter.rsq 0.195

stddev of predictions (scaled by unit):
            coefficients iter.stderr iter.stderr%
(Intercept)         1.46        18.7          big
coef                1.00         5.5          551
exponent            0.77         1.2          156
unit                0.26          NA           NA

                          mean   smallest   largest   ratio
95% prediction interval     15        7.3        29     3.9

                                         68%    80%    90%    95% 
response values in prediction interval   74     94     97     97  
===summary(earth.mod$varmod)
Parent model: earth(formula=Volume~Girth, data=trees,
                    trace=if(varmod.method%in%c("const","lm","power"))0.3els...),
                    nfold=3, ncross=3, varmod.method=varmod.method)

method "power"    min.sd 0.381    iter.rsq 0.195

stddev of predictions:
            coefficients iter.stderr iter.stderr%
(Intercept)         0.37         4.8          big
coef                0.26         1.4          551
exponent            0.77         1.2          156

                          mean   smallest   largest   ratio
95% prediction interval     15        7.3        29     3.9

                                         68%    80%    90%    95% 
response values in prediction interval   74     94     97     97  

Regression submodel (Abs Residuals):

Nonlinear regression model
  model: abs.resids ~ `(Intercept)` + coef * RHS^exponent
   data: data
(Intercept)        coef    exponent 
       0.30        0.20        0.77 
 weighted residual sum-of-squares: 84

Number of iterations to convergence: 4 
Achieved convergence tolerance: 2.5e-09
===summary(earth.mod$varmod$residmod)

Formula: abs.resids ~ `(Intercept)` + coef * RHS^exponent

Parameters:
            Estimate Std. Error t value Pr(>|t|)
(Intercept)   0.2977     3.8357   0.078    0.939
coef          0.2046     1.1281   0.181    0.857
exponent      0.7683     1.1952   0.643    0.526

Residual standard error: 1.733 on 28 degrees of freedom

Number of iterations to convergence: 4 
Achieved convergence tolerance: 2.499e-09

===varmod.method power: predict(earth.mod, interval="pint")
         fit       lwr      upr
1   9.913855  6.253775 13.57393
2  10.942195  7.051413 14.83298
3  11.627755  7.585971 15.66954
4  17.455018 12.200662 22.70937
5  18.140578 12.750354 23.53080
6  18.483359 13.025648 23.94107
7  19.168919 13.577097 24.76074
8  19.168919 13.577097 24.76074
9  19.511699 13.853240 25.17016
10 19.854479 14.129654 25.57930
11 20.197259 14.406333 25.98819
12 20.540040 14.683271 26.39681
13 20.540040 14.683271 26.39681
14 21.568380 15.515591 27.62117
15 22.596721 16.350065 28.84338
16 25.681742 18.865271 32.49821
17 25.681742 18.865271 32.49821
18 27.052863 19.988309 34.11742
19 28.423983 21.114245 35.73372
20 28.766764 21.396162 36.13737
21 30.080913 22.478506 37.68332
22 31.395063 23.563187 39.22694
23 33.366287 25.194327 41.53825
24 43.222408 33.413638 53.03118
25 45.193632 35.068459 55.31881
26 51.764379 40.606627 62.92213
27 53.078529 41.718012 64.43905
28 55.706828 43.944227 67.46943
29 56.363903 44.501475 68.22633
30 56.363903 44.501475 68.22633
31 73.447846 59.074729 87.82096
===varmod.method="power0"
===varmod.method power0: summary(earth.mod)
===summary(earth.mod)
Call: earth(formula=Volume~Girth, data=trees,
            trace=if(varmod.method%in%c("const","lm","power"))0.3els...),
            nfold=3, ncross=3, varmod.method=varmod.method)

              coefficients
(Intercept)      28.766764
h(13.8-Girth)    -3.427802
h(Girth-13.8)     6.570747

Selected 3 of 4 terms, and 1 of 1 predictors
Termination condition: RSq changed by less than 0.001 at 4 terms
Importance: Girth
Number of terms at each degree of interaction: 1 2 (additive model)
GCV 14.20145  RSS 309.6832  GRSq 0.949137  RSq 0.9617962  CVRSq 0.9401008

Note: the cross-validation sd's below are standard deviations across folds

Cross validation:   nterms 3.00 sd 0.00    nvars 1.00 sd 0.00

     CVRSq   sd     MaxErr   sd
      0.94 0.02       10.4 7.04

varmod: method "power0"    min.sd 0.38    iter.rsq 0.197

stddev of predictions:
         coefficients iter.stderr iter.stderr%
coef        0.3806261    0.298741           78
exponent    0.6838047    0.236589           35

                              mean   smallest    largest      ratio
95% prediction interval   14.91131   7.161631   28.16708   3.933054

                                         68%    80%    90%    95% 
response values in prediction interval   77     94     97     97  
===earth.mod$varmod
method "power0"    min.sd 0.38    iter.rsq 0.197

stddev of predictions (scaled by unit):
         coefficients iter.stderr iter.stderr%
coef             0.56        0.44           78
exponent         0.68        0.24           35
unit             0.68          NA           NA

                          mean   smallest   largest   ratio
95% prediction interval     15        7.2        28     3.9

                                         68%    80%    90%    95% 
response values in prediction interval   77     94     97     97  
===summary(earth.mod$varmod)
Parent model: earth(formula=Volume~Girth, data=trees,
                    trace=if(varmod.method%in%c("const","lm","power"))0.3els...),
                    nfold=3, ncross=3, varmod.method=varmod.method)

method "power0"    min.sd 0.38    iter.rsq 0.197

stddev of predictions:
         coefficients iter.stderr iter.stderr%
coef             0.38       0.299           78
exponent         0.68       0.237           35

                          mean   smallest   largest   ratio
95% prediction interval     15        7.2        28     3.9

                                         68%    80%    90%    95% 
response values in prediction interval   77     94     97     97  

Regression submodel (Abs Residuals):

Nonlinear regression model
  model: abs.resids ~ coef * RHS^exponent
   data: data
    coef exponent 
    0.30     0.68 
 weighted residual sum-of-squares: 83

Number of iterations to convergence: 2 
Achieved convergence tolerance: 4.6e-12
===summary(earth.mod$varmod$residmod)

Formula: abs.resids ~ coef * RHS^exponent

Parameters:
         Estimate Std. Error t value Pr(>|t|)   
coef       0.3037     0.2384   1.274  0.21274   
exponent   0.6838     0.2366   2.890  0.00722 **
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 1.693 on 29 degrees of freedom

Number of iterations to convergence: 2 
Achieved convergence tolerance: 4.643e-12

===varmod.method power0: predict(earth.mod, interval="pint")
         fit       lwr      upr
1   9.913855  6.333039 13.49467
2  10.942195  7.111381 14.77301
3  11.627755  7.634402 15.62111
4  17.455018 12.182992 22.72704
5  18.140578 12.727826 23.55333
6  18.483359 13.000875 23.96584
7  19.168919 13.548187 24.78965
8  19.168919 13.548187 24.78965
9  19.511699 13.822431 25.20097
10 19.854479 14.097054 25.61190
11 20.197259 14.372048 26.02247
12 20.540040 14.647405 26.43267
13 20.540040 14.647405 26.43267
14 21.568380 15.475575 27.66119
15 22.596721 16.306741 28.88670
16 25.681742 18.816522 32.54696
17 25.681742 18.816522 32.54696
18 27.052863 19.939078 34.16665
19 28.423983 21.065587 35.78238
20 28.766764 21.347802 36.18573
21 30.080913 22.431838 37.72999
22 31.395063 23.519032 39.27109
23 33.366287 25.155370 41.57720
24 43.222408 33.421822 53.02299
25 45.193632 35.089566 55.29770
26 51.764379 40.677507 62.85125
27 53.078529 41.799954 64.35710
28 55.706828 44.049286 67.36437
29 56.363903 44.612510 68.11530
30 56.363903 44.612510 68.11530
31 73.447846 59.364306 87.53139
===varmod.method="lm"
CV fold  1.1  CVRSq  0.913   n.oof 20 35%   n.infold.nz 20 100%   n.oof.nz 11 100%
CV fold  1.2  CVRSq  0.949   n.oof 21 32%   n.infold.nz 21 100%   n.oof.nz 10 100%
CV fold  1.3  CVRSq  0.928   n.oof 21 32%   n.infold.nz 21 100%   n.oof.nz 10 100%
CV fold  2.1  CVRSq  0.952   n.oof 20 35%   n.infold.nz 20 100%   n.oof.nz 11 100%
CV fold  2.2  CVRSq  0.917   n.oof 21 32%   n.infold.nz 21 100%   n.oof.nz 10 100%
CV fold  2.3  CVRSq  0.947   n.oof 21 32%   n.infold.nz 21 100%   n.oof.nz 10 100%
CV fold  3.1  CVRSq  0.924   n.oof 20 35%   n.infold.nz 20 100%   n.oof.nz 11 100%
CV fold  3.2  CVRSq  0.974   n.oof 21 32%   n.infold.nz 21 100%   n.oof.nz 10 100%
CV fold  3.3  CVRSq  0.957   n.oof 21 32%   n.infold.nz 21 100%   n.oof.nz 10 100%
CV all        CVRSq  0.940                  n.infold.nz 31 100%

varmod method="lm" rmethod="hc12" lambda=1 exponent=1 conv=1 clamp=0.1 minspan=-3:
     iter weight.ratio coefchange% (Intercept) Volume
        1           11       0.000        1.09  0.064
        2           16      18.134        0.85  0.073
        3           16       1.170        0.83  0.074
        4           16       0.045        0.83  0.074

===varmod.method lm: summary(earth.mod)
===summary(earth.mod)
Call: earth(formula=Volume~Girth, data=trees,
            trace=if(varmod.method%in%c("const","lm","power"))0.3els...),
            nfold=3, ncross=3, varmod.method=varmod.method)

              coefficients
(Intercept)      28.766764
h(13.8-Girth)    -3.427802
h(Girth-13.8)     6.570747

Selected 3 of 4 terms, and 1 of 1 predictors
Termination condition: RSq changed by less than 0.001 at 4 terms
Importance: Girth
Number of terms at each degree of interaction: 1 2 (additive model)
GCV 14.20145  RSS 309.6832  GRSq 0.949137  RSq 0.9617962  CVRSq 0.9401008

Note: the cross-validation sd's below are standard deviations across folds

Cross validation:   nterms 3.00 sd 0.00    nvars 1.00 sd 0.00

     CVRSq   sd     MaxErr   sd
      0.94 0.02       10.4 7.04

varmod: method "lm"    min.sd 0.383    iter.rsq 0.186

stddev of predictions:
            coefficients iter.stderr iter.stderr%
(Intercept)   1.04223409    0.871036           84
Volume        0.09231383   0.0358384           39

                              mean   smallest    largest      ratio
95% prediction interval   15.00326   7.672945   30.66358   3.996325

                                         68%    80%    90%    95% 
response values in prediction interval   74     94     97     97  
===earth.mod$varmod
method "lm"    min.sd 0.383    iter.rsq 0.186

stddev of predictions (scaled by unit):
            coefficients iter.stderr iter.stderr%
(Intercept)        11.29         9.4           84
Volume              1.00         0.4           39
unit                0.09          NA           NA

                          mean   smallest   largest   ratio
95% prediction interval     15        7.7        31       4

                                         68%    80%    90%    95% 
response values in prediction interval   74     94     97     97  
===summary(earth.mod$varmod)
Parent model: earth(formula=Volume~Girth, data=trees,
                    trace=if(varmod.method%in%c("const","lm","power"))0.3els...),
                    nfold=3, ncross=3, varmod.method=varmod.method)

method "lm"    min.sd 0.383    iter.rsq 0.186

stddev of predictions:
            coefficients iter.stderr iter.stderr%
(Intercept)        1.042        0.87           84
Volume             0.092        0.04           39

                          mean   smallest   largest   ratio
95% prediction interval     15        7.7        31       4

                                         68%    80%    90%    95% 
response values in prediction interval   74     94     97     97  

Regression submodel (Abs Residuals):

Call:
lm(formula = abs.resids ~ ., data = data, weights = weights, 
    y = TRUE)

Coefficients:
(Intercept)          RHS  
      0.832        0.074  

===summary(earth.mod$varmod$residmod)

Call:
lm(formula = abs.resids ~ ., data = data, weights = weights, 
    y = TRUE)

Weighted Residuals:
    Min      1Q  Median      3Q     Max 
-2.4007 -1.1849 -0.3129  1.0673  5.8571 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)  
(Intercept)  0.83158    0.69499   1.197   0.2412  
RHS          0.07366    0.02859   2.576   0.0154 *
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 1.729 on 29 degrees of freedom
Multiple R-squared:  0.1862,	Adjusted R-squared:  0.1581 
F-statistic: 6.635 on 1 and 29 DF,  p-value: 0.01536

===varmod.method lm: predict(earth.mod, interval="pint")
         fit       lwr      upr
1   9.913855  6.077382 13.75033
2  10.942195  6.919663 14.96473
3  11.627755  7.481184 15.77433
4  17.455018 12.254109 22.65593
5  18.140578 12.815630 23.46553
6  18.483359 13.096390 23.87033
7  19.168919 13.657911 24.67993
8  19.168919 13.657911 24.67993
9  19.511699 13.938671 25.08473
10 19.854479 14.219432 25.48953
11 20.197259 14.500192 25.89433
12 20.540040 14.780952 26.29913
13 20.540040 14.780952 26.29913
14 21.568380 15.623233 27.51353
15 22.596721 16.465514 28.72793
16 25.681742 18.992357 32.37113
17 25.681742 18.992357 32.37113
18 27.052863 20.115399 33.99033
19 28.423983 21.238440 35.60953
20 28.766764 21.519200 36.01433
21 30.080913 22.595579 37.56625
22 31.395063 23.671957 39.11817
23 33.366287 25.286524 41.44605
24 43.222408 33.359359 53.08546
25 45.193632 34.973926 55.41334
26 51.764379 40.355817 63.17294
27 53.078529 41.432195 64.72486
28 55.706828 43.584951 67.82870
29 56.363903 44.123140 68.60467
30 56.363903 44.123140 68.60467
31 73.447846 58.116055 88.77964
===varmod.method="rlm"
===varmod.method rlm: summary(earth.mod)
===summary(earth.mod)
Call: earth(formula=Volume~Girth, data=trees,
            trace=if(varmod.method%in%c("const","lm","power"))0.3els...),
            nfold=3, ncross=3, varmod.method=varmod.method)

              coefficients
(Intercept)      28.766764
h(13.8-Girth)    -3.427802
h(Girth-13.8)     6.570747

Selected 3 of 4 terms, and 1 of 1 predictors
Termination condition: RSq changed by less than 0.001 at 4 terms
Importance: Girth
Number of terms at each degree of interaction: 1 2 (additive model)
GCV 14.20145  RSS 309.6832  GRSq 0.949137  RSq 0.9617962  CVRSq 0.9401008

Note: the cross-validation sd's below are standard deviations across folds

Cross validation:   nterms 3.00 sd 0.00    nvars 1.00 sd 0.00

     CVRSq   sd     MaxErr   sd
      0.94 0.02       10.4 7.04

varmod: method "rlm"    min.sd 0.359    iter.rsq 0.179

stddev of predictions:
            coefficients iter.stderr iter.stderr%
(Intercept)    0.9844540    0.785585           80
Volume         0.0862091   0.0323205           37

                              mean   smallest    largest     ratio
95% prediction interval   14.05477   7.209212   28.67947   3.97817

                                         68%    80%    90%    95% 
response values in prediction interval   71     90     97     97  
===earth.mod$varmod
method "rlm"    min.sd 0.359    iter.rsq 0.179

stddev of predictions (scaled by unit):
            coefficients iter.stderr iter.stderr%
(Intercept)        11.42         9.1           80
Volume              1.00         0.4           37
unit                0.09          NA           NA

                          mean   smallest   largest   ratio
95% prediction interval     14        7.2        29       4

                                         68%    80%    90%    95% 
response values in prediction interval   71     90     97     97  
===summary(earth.mod$varmod)
Parent model: earth(formula=Volume~Girth, data=trees,
                    trace=if(varmod.method%in%c("const","lm","power"))0.3els...),
                    nfold=3, ncross=3, varmod.method=varmod.method)

method "rlm"    min.sd 0.359    iter.rsq 0.179

stddev of predictions:
            coefficients iter.stderr iter.stderr%
(Intercept)        0.984        0.79           80
Volume             0.086        0.03           37

                          mean   smallest   largest   ratio
95% prediction interval     14        7.2        29       4

                                         68%    80%    90%    95% 
response values in prediction interval   71     90     97     97  

Regression submodel (Abs Residuals):

Call:
rlm(formula = abs.resids ~ ., data = data, weights = weights, 
    method = "MM")
Converged in 6 iterations

Coefficients:
(Intercept)         RHS 
      0.785       0.069 

Degrees of freedom: 31 total; 29 residual
Scale estimate: 1.67 
===summary(earth.mod$varmod$residmod)

Call: rlm(formula = abs.resids ~ ., data = data, weights = weights, 
    method = "MM")
Residuals:
    Min      1Q  Median      3Q     Max 
-2.2413 -1.0249 -0.1484  1.2252  6.0184 

Coefficients:
            Value  Std. Error t value
(Intercept) 0.7855 0.6268     1.2531 
RHS         0.0688 0.0258     2.6673 

Residual standard error: 1.671 on 29 degrees of freedom
===varmod.method rlm: predict(earth.mod, interval="pint")
         fit       lwr      upr
1   9.913855  6.309248 13.51846
2  10.942195  7.163834 14.72056
3  11.627755  7.733557 15.52195
4  17.455018 12.576206 22.33383
5  18.140578 13.145930 23.13523
6  18.483359 13.430792 23.53593
7  19.168919 14.000515 24.33732
8  19.168919 14.000515 24.33732
9  19.511699 14.285377 24.73802
10 19.854479 14.570238 25.13872
11 20.197259 14.855100 25.53942
12 20.540040 15.139962 25.94012
13 20.540040 15.139962 25.94012
14 21.568380 15.994547 27.14221
15 22.596721 16.849132 28.34431
16 25.681742 19.412888 31.95060
17 25.681742 19.412888 31.95060
18 27.052863 20.552335 33.55339
19 28.423983 21.691782 35.15619
20 28.766764 21.976643 35.55688
21 30.080913 23.068745 37.09308
22 31.395063 24.160847 38.62928
23 33.366287 25.799000 40.93357
24 43.222408 33.989765 52.45505
25 45.193632 35.627918 54.75935
26 51.764379 41.088427 62.44033
27 53.078529 42.180529 63.97653
28 55.706828 44.364733 67.04892
29 56.363903 44.910784 67.81702
30 56.363903 44.910784 67.81702
31 73.447846 59.108109 87.78758
===varmod.method="earth"
===varmod.method earth: summary(earth.mod)
===summary(earth.mod)
Call: earth(formula=Volume~Girth, data=trees,
            trace=if(varmod.method%in%c("const","lm","power"))0.3els...),
            nfold=3, ncross=3, varmod.method=varmod.method)

              coefficients
(Intercept)      28.766764
h(13.8-Girth)    -3.427802
h(Girth-13.8)     6.570747

Selected 3 of 4 terms, and 1 of 1 predictors
Termination condition: RSq changed by less than 0.001 at 4 terms
Importance: Girth
Number of terms at each degree of interaction: 1 2 (additive model)
GCV 14.20145  RSS 309.6832  GRSq 0.949137  RSq 0.9617962  CVRSq 0.9401008

Note: the cross-validation sd's below are standard deviations across folds

Cross validation:   nterms 3.00 sd 0.00    nvars 1.00 sd 0.00

     CVRSq   sd     MaxErr   sd
      0.94 0.02       10.4 7.04

varmod: method "earth"    min.sd 0.38    iter.rsq 0.241

stddev of predictions:
                  coefficients iter.stderr iter.stderr%
(Intercept)          4.7975074    0.526686           11
h(25.6817-Volume)   -0.2674352   0.0881764           33

                              mean   smallest    largest      ratio
95% prediction interval   14.89945   2.275985   18.80588   8.262746

                                         68%    80%    90%     95% 
response values in prediction interval   77     94     97     100  
===earth.mod$varmod
method "earth"    min.sd 0.38    iter.rsq 0.241

stddev of predictions (scaled by unit):
                  coefficients iter.stderr iter.stderr%
(Intercept)                 18        1.97           11
h(25.6817-Volume)           -1        0.33           33

                          mean   smallest   largest   ratio
95% prediction interval     15        2.3        19     8.3

                                         68%    80%    90%     95% 
response values in prediction interval   77     94     97     100  
===summary(earth.mod$varmod)
Parent model: earth(formula=Volume~Girth, data=trees,
                    trace=if(varmod.method%in%c("const","lm","power"))0.3els...),
                    nfold=3, ncross=3, varmod.method=varmod.method)

method "earth"    min.sd 0.38    iter.rsq 0.241

stddev of predictions:
                  coefficients iter.stderr iter.stderr%
(Intercept)               4.80        0.53           11
h(25.6817-Volume)        -0.27        0.09           33

                          mean   smallest   largest   ratio
95% prediction interval     15        2.3        19     8.3

                                         68%    80%    90%     95% 
response values in prediction interval   77     94     97     100  

Regression submodel (Abs Residuals):

Selected 2 of 4 terms, and 1 of 1 predictors
Termination condition: RSq changed by less than 0.001 at 4 terms
Importance: RHS
Number of terms at each degree of interaction: 1 1 (additive model)
GCV 3.8    RSS 97    GRSq 0.13    RSq 0.24
===summary(earth.mod$varmod$residmod)
Call: earth(formula=abs.resids~., data=data, weights=weights, keepxy=TRUE,
            trace=trace, minspan=minspan)

               coefficients
(Intercept)       3.8278571
h(25.6817-RHS)   -0.2133824

Selected 2 of 4 terms, and 1 of 1 predictors
Termination condition: RSq changed by less than 0.001 at 4 terms
Importance: RHS
Number of terms at each degree of interaction: 1 1 (additive model)
GCV 3.834325    RSS 96.97131    GRSq 0.1284858    RSq 0.2408143
===varmod.method earth: predict(earth.mod, interval="pint")
         fit       lwr      upr
1   9.913855  8.775862 11.05185
2  10.942195  9.265184 12.61921
3  11.627755  9.591399 13.66411
4  17.455018 12.364224 22.54581
5  18.140578 12.690439 23.59072
6  18.483359 12.853546 24.11317
7  19.168919 13.179761 25.15808
8  19.168919 13.179761 25.15808
9  19.511699 13.342868 25.68053
10 19.854479 13.505975 26.20298
11 20.197259 13.669083 26.72544
12 20.540040 13.832190 27.24789
13 20.540040 13.832190 27.24789
14 21.568380 14.321512 28.81525
15 22.596721 14.810834 30.38261
16 25.681742 16.278800 35.08468
17 25.681742 16.278800 35.08468
18 27.052863 17.649921 36.45580
19 28.423983 19.021042 37.82693
20 28.766764 19.363822 38.16971
21 30.080913 20.677971 39.48385
22 31.395063 21.992121 40.79800
23 33.366287 23.963345 42.76923
24 43.222408 33.819466 52.62535
25 45.193632 35.790690 54.59657
26 51.764379 42.361438 61.16732
27 53.078529 43.675587 62.48147
28 55.706828 46.303886 65.10977
29 56.363903 46.960961 65.76684
30 56.363903 46.960961 65.76684
31 73.447846 64.044904 82.85079
===varmod.method="gam"
Loading required package: splines
Loading required package: foreach
Loaded gam 1.22-4

===varmod.method gam: summary(earth.mod)
===summary(earth.mod)
Call: earth(formula=Volume~Girth, data=trees,
            trace=if(varmod.method%in%c("const","lm","power"))0.3els...),
            nfold=3, ncross=3, varmod.method=varmod.method)

              coefficients
(Intercept)      28.766764
h(13.8-Girth)    -3.427802
h(Girth-13.8)     6.570747

Selected 3 of 4 terms, and 1 of 1 predictors
Termination condition: RSq changed by less than 0.001 at 4 terms
Importance: Girth
Number of terms at each degree of interaction: 1 2 (additive model)
GCV 14.20145  RSS 309.6832  GRSq 0.949137  RSq 0.9617962  CVRSq 0.9401008

Note: the cross-validation sd's below are standard deviations across folds

Cross validation:   nterms 3.00 sd 0.00    nvars 1.00 sd 0.00

     CVRSq   sd     MaxErr   sd
      0.94 0.02       10.4 7.04

varmod: method "gam" (gam package)    min.sd 0.373    iter.rsq 0.271

stddev of predictions:
            coefficients iter.stderr iter.stderr%
(Intercept)   0.90395875    0.816758           90
s(Volume)     0.09087774   0.0340212           37

                              mean   smallest    largest      ratio
95% prediction interval   14.63944   7.984429   26.45596   3.313444

                                         68%    80%    90%    95% 
response values in prediction interval   84     90     97     97  
===earth.mod$varmod
method "gam" (gam package)    min.sd 0.373    iter.rsq 0.271

stddev of predictions (scaled by unit):
            coefficients iter.stderr iter.stderr%
(Intercept)         9.95           9           90
s(Volume)           1.00         0.4           37
unit                0.09          NA           NA

                          mean   smallest   largest   ratio
95% prediction interval     15          8        26     3.3

                                         68%    80%    90%    95% 
response values in prediction interval   84     90     97     97  
===summary(earth.mod$varmod)
Parent model: earth(formula=Volume~Girth, data=trees,
                    trace=if(varmod.method%in%c("const","lm","power"))0.3els...),
                    nfold=3, ncross=3, varmod.method=varmod.method)

method "gam" (gam package)    min.sd 0.373    iter.rsq 0.271

stddev of predictions:
            coefficients iter.stderr iter.stderr%
(Intercept)        0.904        0.82           90
s(Volume)          0.091        0.03           37

                          mean   smallest   largest   ratio
95% prediction interval     15          8        26     3.3

                                         68%    80%    90%    95% 
response values in prediction interval   84     90     97     97  

Regression submodel (Abs Residuals):

Call:
gam::gam(formula = form, data = data, weights = weights)

Degrees of Freedom: 30 total; 26 Residual
Residual Deviance: 69.35 
===summary(earth.mod$varmod$residmod)

Call: gam::gam(formula = form, data = data, weights = weights)
Deviance Residuals:
    Min      1Q  Median      3Q     Max 
-2.2464 -0.9264 -0.1597  0.7912  4.5141 

(Dispersion Parameter for gaussian family taken to be 2.6674)

    Null Deviance: 95.1631 on 30 degrees of freedom
Residual Deviance: 69.3525 on 25.9999 degrees of freedom
AIC: 133.2783 

Number of Local Scoring Iterations: NA 

Anova for Parametric Effects
          Df Sum Sq Mean Sq F value  Pr(>F)  
s(RHS)     1 19.033 19.0329  7.1354 0.01287 *
Residuals 26 69.353  2.6674                  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Anova for Nonparametric Effects
            Npar Df  Npar F  Pr(F)
(Intercept)                       
s(RHS)            3 0.84695 0.4808
===varmod.method gam: predict(earth.mod, interval="pint")
         fit       lwr      upr
1   9.913855  5.764567 14.06314
2  10.942195  6.891083 14.99331
3  11.627755  7.635541 15.61997
4  17.455018 13.288559 21.62148
5  18.140578 13.807943 22.47321
6  18.483359 14.052497 22.91422
7  19.168919 14.514981 23.82286
8  19.168919 14.514981 23.82286
9  19.511699 14.735062 24.28834
10 19.854479 14.948275 24.76068
11 20.197259 15.154184 25.24033
12 20.540040 15.352863 25.72722
13 20.540040 15.352863 25.72722
14 21.568380 15.904134 27.23263
15 22.596721 16.407111 28.78633
16 25.681742 18.006579 33.35691
17 25.681742 18.006579 33.35691
18 27.052863 18.906909 35.19882
19 28.423983 19.922792 36.92518
20 28.766764 20.191769 37.34176
21 30.080913 21.270124 38.89170
22 31.395063 22.402661 40.38746
23 33.366287 24.139303 42.59327
24 43.222408 33.212278 53.23254
25 45.193632 35.096740 55.29052
26 51.764379 41.207623 62.32114
27 53.078529 42.375943 63.78111
28 55.706828 44.658253 66.75540
29 56.363903 45.223339 67.50447
30 56.363903 45.223339 67.50447
31 73.447846 60.219868 86.67582
===varmod.method="x.lm"
===varmod.method x.lm: summary(earth.mod)
===summary(earth.mod)
Call: earth(formula=Volume~Girth, data=trees,
            trace=if(varmod.method%in%c("const","lm","power"))0.3els...),
            nfold=3, ncross=3, varmod.method=varmod.method)

              coefficients
(Intercept)      28.766764
h(13.8-Girth)    -3.427802
h(Girth-13.8)     6.570747

Selected 3 of 4 terms, and 1 of 1 predictors
Termination condition: RSq changed by less than 0.001 at 4 terms
Importance: Girth
Number of terms at each degree of interaction: 1 2 (additive model)
GCV 14.20145  RSS 309.6832  GRSq 0.949137  RSq 0.9617962  CVRSq 0.9401008

Note: the cross-validation sd's below are standard deviations across folds

Cross validation:   nterms 3.00 sd 0.00    nvars 1.00 sd 0.00

     CVRSq   sd     MaxErr   sd
      0.94 0.02       10.4 7.04

varmod: method "x.lm"    min.sd 0.378    iter.rsq 0.217

stddev of predictions:
            coefficients iter.stderr iter.stderr%
(Intercept)   -1.6318976     1.67757          103
Girth          0.4084884    0.144115           35

                              mean   smallest    largest      ratio
95% prediction interval   14.81699   6.893412   26.58873   3.857121

                                         68%    80%    90%    95% 
response values in prediction interval   77     94     97     97  
===earth.mod$varmod
method "x.lm"    min.sd 0.378    iter.rsq 0.217

stddev of predictions (scaled by unit):
            coefficients iter.stderr iter.stderr%
(Intercept)        -3.99         4.1          103
Girth               1.00         0.4           35
unit                0.41          NA           NA

                          mean   smallest   largest   ratio
95% prediction interval     15        6.9        27     3.9

                                         68%    80%    90%    95% 
response values in prediction interval   77     94     97     97  
===summary(earth.mod$varmod)
Parent model: earth(formula=Volume~Girth, data=trees,
                    trace=if(varmod.method%in%c("const","lm","power"))0.3els...),
                    nfold=3, ncross=3, varmod.method=varmod.method)

method "x.lm"    min.sd 0.378    iter.rsq 0.217

stddev of predictions:
            coefficients iter.stderr iter.stderr%
(Intercept)        -1.63        1.68          103
Girth               0.41        0.14           35

                          mean   smallest   largest   ratio
95% prediction interval     15        6.9        27     3.9

                                         68%    80%    90%    95% 
response values in prediction interval   77     94     97     97  

Regression submodel (Abs Residuals):

Call:
lm(formula = abs.resids ~ ., data = data, weights = weights, 
    y = TRUE)

Coefficients:
(Intercept)        Girth  
      -1.30         0.33  

===summary(earth.mod$varmod$residmod)

Call:
lm(formula = abs.resids ~ ., data = data, weights = weights, 
    y = TRUE)

Weighted Residuals:
    Min      1Q  Median      3Q     Max 
-2.3859 -1.2223 -0.0691  0.9672  5.2921 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)   
(Intercept)  -1.3021     1.3385  -0.973  0.33871   
Girth         0.3259     0.1150   2.834  0.00827 **
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 1.642 on 29 degrees of freedom
Multiple R-squared:  0.2169,	Adjusted R-squared:  0.1899 
F-statistic: 8.034 on 1 and 29 DF,  p-value: 0.008275

===varmod.method x.lm: predict(earth.mod, interval="pint")
         fit       lwr      upr
1   9.913855  6.467148 13.36056
2  10.942195  7.255302 14.62909
3  11.627755  7.780738 15.47477
4  17.455018 12.246943 22.66309
5  18.140578 12.772378 23.50878
6  18.483359 13.035096 23.93162
7  19.168919 13.560532 24.77731
8  19.168919 13.560532 24.77731
9  19.511699 13.823250 25.20015
10 19.854479 14.085968 25.62299
11 20.197259 14.348686 26.04583
12 20.540040 14.611404 26.46868
13 20.540040 14.611404 26.46868
14 21.568380 15.399557 27.73720
15 22.596721 16.187711 29.00573
16 25.681742 18.552172 32.81131
17 25.681742 18.552172 32.81131
18 27.052863 19.603044 34.50268
19 28.423983 20.653916 36.19405
20 28.766764 20.916634 36.61689
21 30.080913 22.070659 38.09117
22 31.395063 23.224684 39.56544
23 33.366287 24.955721 41.77685
24 43.222408 33.610908 52.83391
25 45.193632 35.341946 55.04532
26 51.764379 41.112071 62.41669
27 53.078529 42.266096 63.89096
28 55.706828 44.574146 66.83951
29 56.363903 45.151158 67.57665
30 56.363903 45.151158 67.57665
31 73.447846 60.153483 86.74221
===varmod.method="x.rlm"
===varmod.method x.rlm: summary(earth.mod)
===summary(earth.mod)
Call: earth(formula=Volume~Girth, data=trees,
            trace=if(varmod.method%in%c("const","lm","power"))0.3els...),
            nfold=3, ncross=3, varmod.method=varmod.method)

              coefficients
(Intercept)      28.766764
h(13.8-Girth)    -3.427802
h(Girth-13.8)     6.570747

Selected 3 of 4 terms, and 1 of 1 predictors
Termination condition: RSq changed by less than 0.001 at 4 terms
Importance: Girth
Number of terms at each degree of interaction: 1 2 (additive model)
GCV 14.20145  RSS 309.6832  GRSq 0.949137  RSq 0.9617962  CVRSq 0.9401008

Note: the cross-validation sd's below are standard deviations across folds

Cross validation:   nterms 3.00 sd 0.00    nvars 1.00 sd 0.00

     CVRSq   sd     MaxErr   sd
      0.94 0.02       10.4 7.04

varmod: method "x.rlm"    min.sd 0.36    iter.rsq 0.214

stddev of predictions:
            coefficients iter.stderr iter.stderr%
(Intercept)   -1.4695340     1.57954          107
Girth          0.3827563    0.135229           35

                              mean   smallest   largest      ratio
95% prediction interval   14.11711   6.692661   25.1473   3.757444

                                         68%    80%    90%    95% 
response values in prediction interval   71     90     97     97  
===earth.mod$varmod
method "x.rlm"    min.sd 0.36    iter.rsq 0.214

stddev of predictions (scaled by unit):
            coefficients iter.stderr iter.stderr%
(Intercept)        -3.84         4.1          107
Girth               1.00         0.4           35
unit                0.38          NA           NA

                          mean   smallest   largest   ratio
95% prediction interval     14        6.7        25     3.8

                                         68%    80%    90%    95% 
response values in prediction interval   71     90     97     97  
===summary(earth.mod$varmod)
Parent model: earth(formula=Volume~Girth, data=trees,
                    trace=if(varmod.method%in%c("const","lm","power"))0.3els...),
                    nfold=3, ncross=3, varmod.method=varmod.method)

method "x.rlm"    min.sd 0.36    iter.rsq 0.214

stddev of predictions:
            coefficients iter.stderr iter.stderr%
(Intercept)        -1.47        1.58          107
Girth               0.38        0.14           35

                          mean   smallest   largest   ratio
95% prediction interval     14        6.7        25     3.8

                                         68%    80%    90%    95% 
response values in prediction interval   71     90     97     97  

Regression submodel (Abs Residuals):

Call:
rlm(formula = abs.resids ~ ., data = data, weights = weights, 
    method = "MM", y.ret = TRUE)
Converged in 6 iterations

Coefficients:
(Intercept)       Girth 
      -1.17        0.31 

Degrees of freedom: 31 total; 29 residual
Scale estimate: 1.67 
===summary(earth.mod$varmod$residmod)

Call: rlm(formula = abs.resids ~ ., data = data, weights = weights, 
    method = "MM", y.ret = TRUE)
Residuals:
     Min       1Q   Median       3Q      Max 
-2.28196 -1.11477  0.05309  1.10372  5.44602 

Coefficients:
            Value   Std. Error t value
(Intercept) -1.1725  1.2603    -0.9304
Girth        0.3054  0.1079     2.8304

Residual standard error: 1.667 on 29 degrees of freedom
===varmod.method x.rlm: predict(earth.mod, interval="pint")
         fit       lwr      upr
1   9.913855  6.567524 13.26019
2  10.942195  7.370808 14.51358
3  11.627755  7.906330 15.34918
4  17.455018 12.458273 22.45176
5  18.140578 12.993795 23.28736
6  18.483359 13.261557 23.70516
7  19.168919 13.797079 24.54076
8  19.168919 13.797079 24.54076
9  19.511699 14.064841 24.95856
10 19.854479 14.332602 25.37636
11 20.197259 14.600363 25.79416
12 20.540040 14.868125 26.21195
13 20.540040 14.868125 26.21195
14 21.568380 15.671409 27.46535
15 22.596721 16.474692 28.71875
16 25.681742 18.884544 32.47894
17 25.681742 18.884544 32.47894
18 27.052863 19.955590 34.15014
19 28.423983 21.026635 35.82133
20 28.766764 21.294396 36.23913
21 30.080913 22.458508 37.70332
22 31.395063 23.622620 39.16751
23 33.366287 25.368787 41.36379
24 43.222408 34.099626 52.34519
25 45.193632 35.845793 54.54147
26 51.764379 41.666352 61.86241
27 53.078529 42.830464 63.32659
28 55.706828 45.158688 66.25497
29 56.363903 45.740744 66.98706
30 56.363903 45.740744 66.98706
31 73.447846 60.874197 86.02149
===varmod.method="x.earth"
===varmod.method x.earth: summary(earth.mod)
===summary(earth.mod)
Call: earth(formula=Volume~Girth, data=trees,
            trace=if(varmod.method%in%c("const","lm","power"))0.3els...),
            nfold=3, ncross=3, varmod.method=varmod.method)

              coefficients
(Intercept)      28.766764
h(13.8-Girth)    -3.427802
h(Girth-13.8)     6.570747

Selected 3 of 4 terms, and 1 of 1 predictors
Termination condition: RSq changed by less than 0.001 at 4 terms
Importance: Girth
Number of terms at each degree of interaction: 1 2 (additive model)
GCV 14.20145  RSS 309.6832  GRSq 0.949137  RSq 0.9617962  CVRSq 0.9401008

Note: the cross-validation sd's below are standard deviations across folds

Cross validation:   nterms 3.00 sd 0.00    nvars 1.00 sd 0.00

     CVRSq   sd     MaxErr   sd
      0.94 0.02       10.4 7.04

varmod: method "x.earth"    min.sd 0.38    iter.rsq 0.272

stddev of predictions:
            coefficients iter.stderr iter.stderr%
(Intercept)    2.5942766    0.544528           21
h(Girth-11)    0.4795752    0.145551           30

                              mean   smallest    largest      ratio
95% prediction interval   14.89945   10.16938   28.21642   2.774646

                                         68%    80%    90%    95% 
response values in prediction interval   81     90     97     97  
===earth.mod$varmod
method "x.earth"    min.sd 0.38    iter.rsq 0.272

stddev of predictions (scaled by unit):
            coefficients iter.stderr iter.stderr%
(Intercept)          5.4        1.14           21
h(Girth-11)          1.0         0.3           30

                          mean   smallest   largest   ratio
95% prediction interval     15         10        28     2.8

                                         68%    80%    90%    95% 
response values in prediction interval   81     90     97     97  
===summary(earth.mod$varmod)
Parent model: earth(formula=Volume~Girth, data=trees,
                    trace=if(varmod.method%in%c("const","lm","power"))0.3els...),
                    nfold=3, ncross=3, varmod.method=varmod.method)

method "x.earth"    min.sd 0.38    iter.rsq 0.272

stddev of predictions:
            coefficients iter.stderr iter.stderr%
(Intercept)         2.59        0.54           21
h(Girth-11)         0.48        0.15           30

                          mean   smallest   largest   ratio
95% prediction interval     15         10        28     2.8

                                         68%    80%    90%    95% 
response values in prediction interval   81     90     97     97  

Regression submodel (Abs Residuals):

Selected 2 of 5 terms, and 1 of 1 predictors
Termination condition: RSq changed by less than 0.001 at 5 terms
Importance: Girth
Number of terms at each degree of interaction: 1 1 (additive model)
GCV 3.7    RSS 93    GRSq 0.16    RSq 0.27
===summary(earth.mod$varmod$residmod)
Call: earth(formula=abs.resids~., data=data, weights=weights, keepxy=TRUE,
            trace=trace, minspan=minspan)

            coefficients
(Intercept)    2.0699332
h(Girth-11)    0.3826456

Selected 2 of 5 terms, and 1 of 1 predictors
Termination condition: RSq changed by less than 0.001 at 5 terms
Importance: Girth
Number of terms at each degree of interaction: 1 1 (additive model)
GCV 3.674869    RSS 92.93863    GRSq 0.1647288    RSq 0.272386
===varmod.method x.earth: predict(earth.mod, interval="pint")
         fit       lwr      upr
1   9.913855  4.829166 14.99854
2  10.942195  5.857506 16.02688
3  11.627755  6.543067 16.71244
4  17.455018 12.370330 22.53971
5  18.140578 13.055890 23.22527
6  18.483359 13.398670 23.56805
7  19.168919 14.084230 24.25361
8  19.168919 14.084230 24.25361
9  19.511699 14.333016 24.69038
10 19.854479 14.581801 25.12716
11 20.197259 14.830586 25.56393
12 20.540040 15.079371 26.00071
13 20.540040 15.079371 26.00071
14 21.568380 15.825726 27.31103
15 22.596721 16.572082 28.62136
16 25.681742 18.811148 32.55234
17 25.681742 18.811148 32.55234
18 27.052863 19.806289 34.29944
19 28.423983 20.801430 36.04654
20 28.766764 21.050215 36.48331
21 30.080913 22.176374 37.98545
22 31.395063 23.302534 39.48759
23 33.366287 24.991773 41.74080
24 43.222408 33.437969 53.00685
25 45.193632 35.127208 55.26006
26 51.764379 40.758005 62.77075
27 53.078529 41.884165 64.27289
28 55.706828 44.136484 67.27717
29 56.363903 44.699563 68.02824
30 56.363903 44.699563 68.02824
31 73.447846 59.339636 87.55606
===varmod.method="x.gam"
===varmod.method x.gam: summary(earth.mod)
===summary(earth.mod)
Call: earth(formula=Volume~Girth, data=trees,
            trace=if(varmod.method%in%c("const","lm","power"))0.3els...),
            nfold=3, ncross=3, varmod.method=varmod.method)

              coefficients
(Intercept)      28.766764
h(13.8-Girth)    -3.427802
h(Girth-13.8)     6.570747

Selected 3 of 4 terms, and 1 of 1 predictors
Termination condition: RSq changed by less than 0.001 at 4 terms
Importance: Girth
Number of terms at each degree of interaction: 1 2 (additive model)
GCV 14.20145  RSS 309.6832  GRSq 0.949137  RSq 0.9617962  CVRSq 0.9401008

Note: the cross-validation sd's below are standard deviations across folds

Cross validation:   nterms 3.00 sd 0.00    nvars 1.00 sd 0.00

     CVRSq   sd     MaxErr   sd
      0.94 0.02       10.4 7.04

varmod: method "x.gam" (gam package)    min.sd 0.374    iter.rsq 0.289

stddev of predictions:
            coefficients iter.stderr iter.stderr%
(Intercept)   -2.1239640      1.8135           85
s(Volume)      0.4316199    0.156258           36

                              mean   smallest    largest      ratio
95% prediction interval   14.67221   7.622878   26.26615   3.445701

                                         68%    80%    90%     95% 
response values in prediction interval   84     87     97     100  
===earth.mod$varmod
method "x.gam" (gam package)    min.sd 0.374    iter.rsq 0.289

stddev of predictions (scaled by unit):
            coefficients iter.stderr iter.stderr%
(Intercept)        -4.92         4.2           85
s(Volume)           1.00         0.4           36
unit                0.43          NA           NA

                          mean   smallest   largest   ratio
95% prediction interval     15        7.6        26     3.4

                                         68%    80%    90%     95% 
response values in prediction interval   84     87     97     100  
===summary(earth.mod$varmod)
Parent model: earth(formula=Volume~Girth, data=trees,
                    trace=if(varmod.method%in%c("const","lm","power"))0.3els...),
                    nfold=3, ncross=3, varmod.method=varmod.method)

method "x.gam" (gam package)    min.sd 0.374    iter.rsq 0.289

stddev of predictions:
            coefficients iter.stderr iter.stderr%
(Intercept)        -2.12        1.81           85
s(Volume)           0.43        0.16           36

                          mean   smallest   largest   ratio
95% prediction interval     15        7.6        26     3.4

                                         68%    80%    90%     95% 
response values in prediction interval   84     87     97     100  

Regression submodel (Abs Residuals):

Call:
gam::gam(formula = form, data = data, weights = weights)

Degrees of Freedom: 30 total; 26 Residual
Residual Deviance: 65.15 
===summary(earth.mod$varmod$residmod)

Call: gam::gam(formula = form, data = data, weights = weights)
Deviance Residuals:
    Min      1Q  Median      3Q     Max 
-2.2060 -0.8878 -0.1530  0.7521  4.0281 

(Dispersion Parameter for gaussian family taken to be 2.5059)

    Null Deviance: 91.5706 on 30 degrees of freedom
Residual Deviance: 65.1524 on 26 degrees of freedom
AIC: 132.156 

Number of Local Scoring Iterations: NA 

Anova for Parametric Effects
          Df Sum Sq Mean Sq F value Pr(>F)  
s(RHS)     1 19.120 19.1196  7.6299 0.0104 *
Residuals 26 65.152  2.5059                 
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Anova for Nonparametric Effects
            Npar Df  Npar F  Pr(F)
(Intercept)                       
s(RHS)            3 0.97087 0.4214
===varmod.method x.gam: predict(earth.mod, interval="pint")
         fit       lwr      upr
1   9.913855  5.505536 14.32217
2  10.942195  6.770308 15.11408
3  11.627755  7.601547 15.65396
4  17.455018 13.643579 21.26646
5  18.140578 14.126734 22.15442
6  18.483359 14.345510 22.62121
7  19.168919 14.748924 23.58891
8  19.168919 14.748924 23.58891
9  19.511699 14.939781 24.08362
10 19.854479 15.124403 24.58456
11 20.197259 15.300626 25.09389
12 20.540040 15.467505 25.61257
13 20.540040 15.467505 25.61257
14 21.568380 15.896738 27.24002
15 22.596721 16.243213 28.95023
16 25.681742 17.508646 33.85484
17 25.681742 17.508646 33.85484
18 27.052863 18.435857 35.66987
19 28.423983 19.537481 37.31049
20 28.766764 19.830369 37.70316
21 30.080913 21.059261 39.10256
22 31.395063 22.299109 40.49102
23 33.366287 24.156085 42.57649
24 43.222408 33.353500 53.09132
25 45.193632 35.187814 55.19945
26 51.764379 41.190650 62.33811
27 53.078529 42.363566 63.79349
28 55.706828 44.683386 66.73027
29 56.363903 45.260369 67.46744
30 56.363903 45.260369 67.46744
31 73.447846 60.314769 86.58092
detach("package:gam", unload=TRUE)
===varmod.method="gam"
skipping mgcv tests
===varmod.method="x.gam"
skipping mgcv tests
> # test varmod.exponent
> set.seed(6)
> earth.exponent <- earth(Volume~Girth, data=trees, nfold=3, ncross=3,
+                         varmod.method="lm", varmod.exponent=.5)
> printh("summary(earth.exponent)")
===summary(earth.exponent)
> print(summary(earth.exponent))
Call: earth(formula=Volume~Girth, data=trees, nfold=3, ncross=3,
            varmod.method="lm", varmod.exponent=0.5)

              coefficients
(Intercept)      28.766764
h(13.8-Girth)    -3.427802
h(Girth-13.8)     6.570747

Selected 3 of 4 terms, and 1 of 1 predictors
Termination condition: RSq changed by less than 0.001 at 4 terms
Importance: Girth
Number of terms at each degree of interaction: 1 2 (additive model)
GCV 14.20145  RSS 309.6832  GRSq 0.949137  RSq 0.9617962  CVRSq 0.9266989

Note: the cross-validation sd's below are standard deviations across folds

Cross validation:   nterms 3.00 sd 0.00    nvars 1.00 sd 0.00

     CVRSq    sd     MaxErr   sd
     0.927 0.043       9.81 7.21

varmod: method "lm"  exponent 0.500  min.sd 0.374  iter.rsq 0.339

stddev of predictions:
             coefficients iter.stderr iter.stderr%
(Intercept)     -2.801211     1.36234           49
sqrt(Volume)     1.229319    0.318489           26

                             mean   smallest    largest      ratio
95% prediction interval   14.6542   4.192195   30.31777   7.231956

                                         68%    80%    90%    95% 
response values in prediction interval   71     90     97     97  
> 
> par(org.par)
> 
> source("test.epilog.R")
