> # test.glm.R: tests glm and factors added for earth release 2.0
> 
> source("test.prolog.R")
> library(earth)
Loading required package: Formula
Loading required package: plotmo
Loading required package: plotrix
Loading required package: TeachingDemos
> data(ozone1)
> data(trees)
> data(etitanic)
> source("check.models.equal.R")
> 
> printh <- function(x, expect.warning=FALSE, max.print=0) # like print but with a header
+ {
+     cat("===", deparse(substitute(x)))
+     if(expect.warning)
+         cat(" expect warning -->")
+     else if (NROW(x) > 1)
+         cat("\n")
+     if (max.print > 0)
+         print(head(x, n=max.print))
+     else
+         print(x)
+ }
> 
> model.count <- 0
> 
> show.earth.models <- function(a, nresponse=NA, legend.pos=NULL, ...)
+ {
+     model.name <- deparse(substitute(a))
+     cat("\nPrint", model.name, "\n\n")
+     print(a)
+     cat("\nSummary", model.name, "\n\n")
+     print(summary(a))
+     model.count <<- model.count + 1
+     if (model.count %% 2 == 0) {  # an attempt at trying different parameters without combin explosion.
+         cat("\nSummary", model.name, "decomp=\"none\", digits=5, fixed.point=FALSE, details=TRUE\n\n")
+         print(summary(a, decomp="none", digits=5, fixed.point=FALSE, details=TRUE))
+     } else {
+         cat("\nSummary", model.name, "digits=3, details=TRUE\n\n")
+         print(summary(a, decomp="none", digits=3, details=TRUE))
+     }
+     cat("\nevimp", model.name, "\n\n")
+     print(evimp(a))
+     cat("\nevimp", model.name, "trim=FALSE\n\n")
+     ev <- evimp(a, trim=FALSE)
+     print(ev)
+     plot(a, nresponse=nresponse, legend.pos=legend.pos,
+          caption=if(is.na(nresponse)) model.name
+                  else paste("Response ", nresponse, ": ", model.name, sep=""))
+     plot(ev)
+     if (!is.null(a$glm.list)) {
+         control <- a$glm.list[[1]]$control
+         family <- a$glm.list[[1]]$family
+         cat("\nglm params: epsilon", control$epsilon,
+             "maxit", control$maxit, "trace", control$trace,
+             "family", family$family, "link", family$link, "\n")
+     }
+     cat("\nplotmo", model.name, "\n")
+     if(is.na(nresponse))
+         plotmo(a, clip=FALSE)
+     else
+         plotmo(a, nresponse=nresponse, clip=FALSE)
+     cat("-------------------------------------------------------------------------------\n\n")
+ }
> 
> # print contents of earth.model, for sanity checking that all fields are present as usual
> # but strip big fields to reduce amount of printing
> 
> print.stripped.earth.model <- function(a, model.name)
+ {
+     a$bx <- NULL
+     a$fitted.values <- NULL
+     a$residuals <- NULL
+     cat("print.stripped.earth.model(", model.name, ")\n", sep="")
+     print.default(a)
+     cat("-------------------------------------------------------------------------------\n\n")
+ }
> 
> # binomial models
> 
> ldose  <- rep(0:5, 2) - 2
> # ldose1 <- c(0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 0.3, 1.4, 2.5, 3.6, 4.7, 5.8)
> ldose1 <- c(0.1, 1.2, 0.1, 1.2, 1.0, 0.1, 0.3, 1.4, 0.1, 1.2, 0.1, 0.9)
> sex <- factor(rep(c("male", "female"), times=c(6,6)))
> numdead <- c(1,4,9,13,18,20,0,2,6,10,12,16)
> numalive=20 - numdead
> SF <- cbind(numdead, numalive)
> numdead2 <- c(2,3,10,13,19,20,0,3,7,11,13,17)
> SF2 <- cbind(numdead2, numalive2=20 - numdead2)
> 
> PMETHOD <- "none" # avoid intercept only models
> NK <- 6           # avoid infinite GCV models (since pmethod="none")
> 
> # single response glm model but with a binomial pair of y columns
> cat("a1: single response glm model but with a binomial pair of y columns, with ldose1 data degree=2\n\n")
a1: single response glm model but with a binomial pair of y columns, with ldose1 data degree=2

> a1 <-  earth(SF ~ sex + ldose + ldose1, glm=list(family="binomial"), trace=4, pmethod=PMETHOD, nk=NK, degree=2)
Call: earth(formula=SF~sex+ldose+ldose1, pmethod=PMETHOD, trace=4,
            glm=list(family="binomial"), degree=2, nk=NK)

x[12,3]:
    sexmale ldose ldose1
1         1    -2    0.1
2         1    -1    1.2
3         1     0    0.1
...       1     1    1.2
12        0     3    0.9

y[12,2]:
    numdead numalive
1         1       19
2         4       16
3         9       11
...      13        7
12       16        4

earth and glm: unweighted
Response columns numdead and numalive are a binomial pair (240 obs in total)

yfrac[12,1]:
    numdead
1      0.05
2      0.20
3      0.45
...    0.65
12     0.80

Forward pass: minspan 3 endspan 5   x[12,3] 288 Bytes   bx[12,6] 576 Bytes

         GRSq    RSq     DeltaRSq Pred     PredName         Cut  Terms   Par Deg
1      0.0000 0.0000                    (Intercept)
2      0.8679 0.9211       0.9211    2        ldose          -2< 2             1 
4      0.9353 0.9808      0.05966    1      sexmale           0< 3             1 final (reached nk 6)

Reached nk 6
After forward pass GRSq 0.935 RSq 0.981
Forward pass complete: 5 terms, 3 terms used

Subset size        GRSq     RSq  DeltaGRSq nPreds  Terms (col nbr in bx)
          1      0.0000  0.0000     0.0000      0  1
          2      0.8679  0.9211     0.8679      1  1 2
chosen    3      0.9353  0.9808     0.0675      2  1 2 3

Prune none penalty 3 nprune null: selected 3 of 3 terms, and 2 of 3 preds
After pruning pass GRSq 0.935 RSq 0.981

glm y[12,2]:
    numdead numalive
1         1       19
2         4       16
3         9       11
...      13        7
12       16        4

glm weights: NULL

GLM numdead devratio 0.95 dof 9/11 iters 4
> show.earth.models(a1, legend.pos="topleft")

Print a1 

GLM (family binomial, link logit):
 nulldev df       dev df   devratio     AIC iters converged
 124.876 11   6.75706  9      0.946   42.87     4         1

Earth selected 3 of 3 terms, and 2 of 3 predictors (pmethod="none")
Termination condition: Reached nk 6
Importance: ldose, sexmale, ldose1-unused
Number of terms at each degree of interaction: 1 2 (additive model)
Earth GCV 0.008085317    RSS 0.02425595    GRSq 0.9353281    RSq 0.9807588

Summary a1 

Call: earth(formula=SF~sex+ldose+ldose1, pmethod=PMETHOD, trace=4,
            glm=list(family="binomial"), degree=2, nk=NK)

GLM coefficients
              numdead
(Intercept) -1.344727
sexmale      1.100743
ldose        1.064214

GLM (family binomial, link logit):
 nulldev df       dev df   devratio     AIC iters converged
 124.876 11   6.75706  9      0.946   42.87     4         1

Earth selected 3 of 3 terms, and 2 of 3 predictors (pmethod="none")
Termination condition: Reached nk 6
Importance: ldose, sexmale, ldose1-unused
Number of terms at each degree of interaction: 1 2 (additive model)
Earth GCV 0.008085317    RSS 0.02425595    GRSq 0.9353281    RSq 0.9807588

Summary a1 digits=3, details=TRUE

Call: earth(formula=SF~sex+ldose+ldose1, pmethod=PMETHOD, trace=4,
            glm=list(family="binomial"), degree=2, nk=NK)

Earth coefficients
            numdead
(Intercept)   0.292
ldose         0.182
sexmale       0.158

GLM coefficients
            numdead
(Intercept)   -1.34
ldose          1.06
sexmale        1.10

GLM deviance residuals:
    Min       1Q   Median       3Q      Max  
-1.1054  -0.6534  -0.0222   0.4847   1.4294  

GLM coefficients (family binomial, link logit)
            Estimate Std. Error z value Pr(>|z|)
(Intercept)   -1.345      0.280   -4.81  1.5e-06
ldose          1.064      0.131    8.12  4.7e-16
sexmale        1.101      0.356    3.09    0.002

GLM (family binomial, link logit):
 nulldev df       dev df   devratio     AIC iters converged
     125 11      6.76  9       0.95    42.9     4         1

Earth selected 3 of 3 terms, and 2 of 3 predictors (pmethod="none")
Termination condition: Reached nk 6
Importance: ldose, sexmale, ldose1-unused
Number of terms at each degree of interaction: 1 2 (additive model)
Earth GCV 0.00809    RSS 0.0243    GRSq 0.935    RSq 0.981

evimp a1 

        nsubsets   gcv    rss
ldose          2 100.0  100.0
sexmale        1  26.9   24.7

evimp a1 trim=FALSE

              nsubsets   gcv    rss
ldose                2 100.0  100.0
sexmale              1  26.9   24.7
ldose1-unused        0   0.0    0.0

glm params: epsilon 1e-08 maxit 25 trace FALSE family binomial link logit 

plotmo a1 
 plotmo grid:    sex ldose ldose1
              female   0.5    0.6
-------------------------------------------------------------------------------

> printh(evimp(a1, trim=FALSE, sqrt=FALSE))
=== evimp(a1, trim = FALSE, sqrt = FALSE)
              nsubsets   gcv    rss
ldose                2 100.0  100.0
sexmale              1   7.2    6.1
ldose1-unused        0   0.0    0.0
> printh(evimp(a1, trim=FALSE, sqrt=TRUE)) # this tests sqrt param with negative evimps
=== evimp(a1, trim = FALSE, sqrt = TRUE)
              nsubsets   gcv    rss
ldose                2 100.0  100.0
sexmale              1  26.9   24.7
ldose1-unused        0   0.0    0.0
> a1update <- update(a1, trace=0)
> check.models.equal(a1, a1update, msg="a1update a1", newdata=data.frame(sex="female", ldose=10, ldose1=11))
a1update a1: models not identical

a1update a1: glm submodel formula strings are identical: yarg ~ ldose + sexmale
a1update a1: but the actual glm submodel formulas differ (classes are "formula" and "formula")
a1update a1: glm submodels not identical (but coefs, residuals, fitted.values are the same)
a1update a1: Models are equivalent, within numerical tolerances

> 
> # test some different but equivalent glm specs
> a1a <-  earth(SF ~ sex + ldose + ldose1, glm=list(family="binomial"), trace=1, pmethod=PMETHOD, nk=NK, degree=2)
x[12,3] with colnames sexmale ldose ldose1
y[12,2] with colnames numdead numalive
earth and glm: unweighted
Response columns numdead and numalive are a binomial pair (240 obs in total)
yfrac[12,1] with colname numdead, and values 0.05, 0.2, 0.45, 0.65, 0.9, 1...
Forward pass term 1, 2, 4
Reached nk 6
After forward pass GRSq 0.935 RSq 0.981
Prune none penalty 3 nprune null: selected 3 of 3 terms, and 2 of 3 preds
After pruning pass GRSq 0.935 RSq 0.981
GLM numdead devratio 0.95 dof 9/11 iters 4
> check.models.equal(a1a, a1, msg="a1 a1a", newdata=data.frame(sex="female", ldose=10, ldose1=11))
a1 a1a: models not identical

a1 a1a: glm submodel formula strings are identical: yarg ~ ldose + sexmale
a1 a1a: but the actual glm submodel formulas differ (classes are "formula" and "formula")
a1 a1a: glm submodels not identical (but coefs, residuals, fitted.values are the same)
a1 a1a: Models are equivalent, within numerical tolerances

> a1b <-  earth(SF ~ sex + ldose + ldose1, glm=list(family=binomial), trace=1, pmethod=PMETHOD, nk=NK, degree=2)
x[12,3] with colnames sexmale ldose ldose1
y[12,2] with colnames numdead numalive
earth and glm: unweighted
Response columns numdead and numalive are a binomial pair (240 obs in total)
yfrac[12,1] with colname numdead, and values 0.05, 0.2, 0.45, 0.65, 0.9, 1...
Forward pass term 1, 2, 4
Reached nk 6
After forward pass GRSq 0.935 RSq 0.981
Prune none penalty 3 nprune null: selected 3 of 3 terms, and 2 of 3 preds
After pruning pass GRSq 0.935 RSq 0.981
GLM numdead devratio 0.95 dof 9/11 iters 4
> check.models.equal(a1, a1b, msg="a1 a1b", newdata=data.frame(sex="female", ldose=10, ldose1=11))
a1 a1b: models not identical

a1 a1b: glm submodel formula strings are identical: yarg ~ ldose + sexmale
a1 a1b: but the actual glm submodel formulas differ (classes are "formula" and "formula")
a1 a1b: glm submodels not identical (but coefs, residuals, fitted.values are the same)
a1 a1b: Models are equivalent, within numerical tolerances

> a1c <-  earth(SF ~ sex + ldose + ldose1, glm=list(family=binomial()), trace=1, pmethod=PMETHOD, nk=NK, degree=2)
x[12,3] with colnames sexmale ldose ldose1
y[12,2] with colnames numdead numalive
earth and glm: unweighted
Response columns numdead and numalive are a binomial pair (240 obs in total)
yfrac[12,1] with colname numdead, and values 0.05, 0.2, 0.45, 0.65, 0.9, 1...
Forward pass term 1, 2, 4
Reached nk 6
After forward pass GRSq 0.935 RSq 0.981
Prune none penalty 3 nprune null: selected 3 of 3 terms, and 2 of 3 preds
After pruning pass GRSq 0.935 RSq 0.981
GLM numdead devratio 0.95 dof 9/11 iters 4
> check.models.equal(a1, a1c, msg="a1 a1c", newdata=data.frame(sex="female", ldose=10, ldose1=11))
a1 a1c: models not identical

a1 a1c: glm submodel formula strings are identical: yarg ~ ldose + sexmale
a1 a1c: but the actual glm submodel formulas differ (classes are "formula" and "formula")
a1 a1c: glm submodels not identical (but coefs, residuals, fitted.values are the same)
a1 a1c: Models are equivalent, within numerical tolerances

> a1d <-  earth(SF ~ sex + ldose + ldose1, glm=list(family=binomial(link="logit")), trace=1, pmethod=PMETHOD, nk=NK, degree=2)
x[12,3] with colnames sexmale ldose ldose1
y[12,2] with colnames numdead numalive
earth and glm: unweighted
Response columns numdead and numalive are a binomial pair (240 obs in total)
yfrac[12,1] with colname numdead, and values 0.05, 0.2, 0.45, 0.65, 0.9, 1...
Forward pass term 1, 2, 4
Reached nk 6
After forward pass GRSq 0.935 RSq 0.981
Prune none penalty 3 nprune null: selected 3 of 3 terms, and 2 of 3 preds
After pruning pass GRSq 0.935 RSq 0.981
GLM numdead devratio 0.95 dof 9/11 iters 4
> check.models.equal(a1, a1d, msg="a1 a1d", newdata=data.frame(sex="female", ldose=10, ldose1=11))
a1 a1d: models not identical

a1 a1d: glm submodel formula strings are identical: yarg ~ ldose + sexmale
a1 a1d: but the actual glm submodel formulas differ (classes are "formula" and "formula")
a1 a1d: glm submodels not identical (but coefs, residuals, fitted.values are the same)
a1 a1d: Models are equivalent, within numerical tolerances

> expect.err(try(earth(SF ~ sex + ldose + ldose1, glm=list(family=binomial(link="logit"),offset=NULL), trace=1, pmethod=PMETHOD, nk=NK, degree=2)), "earth: 'offset' is not supported in glm argument to earth")
x[12,3] with colnames sexmale ldose ldose1
y[12,2] with colnames numdead numalive
Error : earth: 'offset' is not supported in glm argument to earth
Got error as expected from try(earth(SF ~ sex + ldose + ldose1, glm = list(family = binomial(link = "logit"),     offset = NULL), trace = 1, pmethod = PMETHOD, nk = NK, degree = 2))
> a1g <-  earth(SF ~ sex + ldose + ldose1, glm=list(family=binomial(link="logit"),control=glm.control()), trace=1, pmethod=PMETHOD, nk=NK, degree=2)
x[12,3] with colnames sexmale ldose ldose1
y[12,2] with colnames numdead numalive
earth and glm: unweighted
Response columns numdead and numalive are a binomial pair (240 obs in total)
yfrac[12,1] with colname numdead, and values 0.05, 0.2, 0.45, 0.65, 0.9, 1...
Forward pass term 1, 2, 4
Reached nk 6
After forward pass GRSq 0.935 RSq 0.981
Prune none penalty 3 nprune null: selected 3 of 3 terms, and 2 of 3 preds
After pruning pass GRSq 0.935 RSq 0.981
GLM numdead devratio 0.95 dof 9/11 iters 4
> check.models.equal(a1, a1g, msg="a1 a1g", newdata=data.frame(sex="female", ldose=10, ldose1=11))
a1 a1g: models not identical

a1 a1g: glm submodel formula strings are identical: yarg ~ ldose + sexmale
a1 a1g: but the actual glm submodel formulas differ (classes are "formula" and "formula")
a1 a1g: glm submodels not identical (but coefs, residuals, fitted.values are the same)
a1 a1g: Models are equivalent, within numerical tolerances

> # following should cause a "did not converge warning" because maxit=2
> a1h <-  earth(SF ~ sex + ldose + ldose1, glm=list(family=binomial(link="logit"),control=glm.control(epsilon=1e-8, maxit=2, trace=TRUE)), trace=1, pmethod=PMETHOD, nk=NK, degree=2)
x[12,3] with colnames sexmale ldose ldose1
y[12,2] with colnames numdead numalive
earth and glm: unweighted
Response columns numdead and numalive are a binomial pair (240 obs in total)
yfrac[12,1] with colname numdead, and values 0.05, 0.2, 0.45, 0.65, 0.9, 1...
Forward pass term 1, 2, 4
Reached nk 6
After forward pass GRSq 0.935 RSq 0.981
Prune none penalty 3 nprune null: selected 3 of 3 terms, and 2 of 3 preds
After pruning pass GRSq 0.935 RSq 0.981
Deviance = 6.811649 Iterations - 1
Deviance = 6.757094 Iterations - 2
Warning: glm.fit: algorithm did not converge
GLM numdead devratio 0.95 dof 9/11 iters 2
Warning: the glm algorithm did not converge for response "numdead"
> show.earth.models(a1h, legend.pos="topleft") # show non convergence (and maxit)

Print a1h 

GLM (family binomial, link logit, maxit=2):
 nulldev df       dev df   devratio     AIC iters converged
 124.876 11   6.75709  9      0.946   42.87     2         0

Earth selected 3 of 3 terms, and 2 of 3 predictors (pmethod="none")
Termination condition: Reached nk 6
Importance: ldose, sexmale, ldose1-unused
Number of terms at each degree of interaction: 1 2 (additive model)
Earth GCV 0.008085317    RSS 0.02425595    GRSq 0.9353281    RSq 0.9807588

Summary a1h 

Call: earth(formula=SF~sex+ldose+ldose1, pmethod=PMETHOD, trace=1,
            glm=list(family=binomial(link="logit"),control=glm.con...),
            degree=2, nk=NK)

GLM coefficients
              numdead
(Intercept) -1.343835
sexmale      1.099751
ldose        1.063528

GLM (family binomial, link logit, maxit=2):
 nulldev df       dev df   devratio     AIC iters converged
 124.876 11   6.75709  9      0.946   42.87     2         0

Earth selected 3 of 3 terms, and 2 of 3 predictors (pmethod="none")
Termination condition: Reached nk 6
Importance: ldose, sexmale, ldose1-unused
Number of terms at each degree of interaction: 1 2 (additive model)
Earth GCV 0.008085317    RSS 0.02425595    GRSq 0.9353281    RSq 0.9807588

Summary a1h decomp="none", digits=5, fixed.point=FALSE, details=TRUE

Call: earth(formula=SF~sex+ldose+ldose1, pmethod=PMETHOD, trace=1,
            glm=list(family=binomial(link="logit"),control=glm.con...),
            degree=2, nk=NK)

Earth coefficients
            numdead
(Intercept) 0.29226
ldose       0.18214
sexmale     0.15833

GLM coefficients
            numdead
(Intercept) -1.3438
ldose        1.0635
sexmale      1.0998

GLM deviance residuals:
      Min         1Q     Median         3Q        Max  
-1.106632  -0.654066  -0.022671   0.486200   1.430948  

GLM coefficients (family binomial, link logit)
            Estimate Std. Error z value  Pr(>|z|)
(Intercept) -1.34383    0.27542 -4.8793 1.065e-06
ldose        1.06353    0.12814  8.3000 < 2.2e-16
sexmale      1.09975    0.35113  3.1320  0.001736

GLM (family binomial, link logit, maxit=2):
 nulldev df       dev df   devratio     AIC iters converged
   124.9 11     6.757  9       0.95    42.9     2         0

Earth selected 3 of 3 terms, and 2 of 3 predictors (pmethod="none")
Termination condition: Reached nk 6
Importance: ldose, sexmale, ldose1-unused
Number of terms at each degree of interaction: 1 2 (additive model)
Earth GCV 0.0080853    RSS 0.024256    GRSq 0.93533    RSq 0.98076

evimp a1h 

        nsubsets   gcv    rss
ldose          2 100.0  100.0
sexmale        1  26.9   24.7

evimp a1h trim=FALSE

              nsubsets   gcv    rss
ldose                2 100.0  100.0
sexmale              1  26.9   24.7
ldose1-unused        0   0.0    0.0

glm params: epsilon 1e-08 maxit 2 trace TRUE family binomial link logit 

plotmo a1h 
 plotmo grid:    sex ldose ldose1
              female   0.5    0.6
-------------------------------------------------------------------------------

> check.models.equal(a1, a1g, msg="a1 a1h", newdata=data.frame(sex="female", ldose=10, ldose1=11)) # models should still be equal within numeric tolerance
a1 a1h: models not identical

a1 a1h: glm submodel formula strings are identical: yarg ~ ldose + sexmale
a1 a1h: but the actual glm submodel formulas differ (classes are "formula" and "formula")
a1 a1h: glm submodels not identical (but coefs, residuals, fitted.values are the same)
a1 a1h: Models are equivalent, within numerical tolerances

> stopifnot(a1h$glm.list[[1]]$control$maxit == 2)
> # equivalent way of specifying maxit
> a1h2 <-  earth(SF ~ sex + ldose + ldose1, glm=list(family=binomial(link="logit"),control=glm.control(epsilon=1e-8),maxit=2), pmethod=PMETHOD, nk=NK, degree=2)
Warning: glm.fit: algorithm did not converge
Warning: the glm algorithm did not converge for response "numdead"
> check.models.equal(a1h, a1h2, msg="a1h a1h2", newdata=data.frame(sex="female", ldose=10, ldose1=11))
a1h a1h2: models not identical

a1h a1h2: glm submodel formula strings are identical: yarg ~ ldose + sexmale
a1h a1h2: but the actual glm submodel formulas differ (classes are "formula" and "formula")
a1h a1h2: glm submodels not identical (but coefs, residuals, fitted.values are the same)
a1h a1h2: Models are equivalent, within numerical tolerances

> stopifnot(a1h2$glm.list[[1]]$control$maxit == 2)
> expect.err(try(earth(SF ~ sex + ldose + ldose1, family=binomial)), "illegal 'family' argument to earth\nTry something like earth(y~x, glm=list(family=binomial))")
Error : illegal 'family' argument to earth
Try something like earth(y~x, glm=list(family=binomial))
Got error as expected from try(earth(SF ~ sex + ldose + ldose1, family = binomial))
> expect.err(try(earth(SF ~ sex + ldose + ldose1, glm=list(family=binomial(link="logit")), maxi=123)), "illegal 'maxit' argument to earth\nTry something like earth(y~x, glm=list(family=binomial, control=list(maxit=99)))")
Error : illegal 'maxit' argument to earth
Try something like earth(y~x, glm=list(family=binomial, control=list(maxit=99)))
Got error as expected from try(earth(SF ~ sex + ldose + ldose1, glm = list(family = binomial(link = "logit")),     maxi = 123))
> expect.err(try(earth(SF ~ sex + ldose + ldose1, glm=list(family=binomial(link="logit")), eps=123)), "illegal 'epsilon' argument to earth\nTry something like earth(y~x, glm=list(family=binomial, control=list(epsilon=1e-9)))")
Error : illegal 'epsilon' argument to earth
Try something like earth(y~x, glm=list(family=binomial, control=list(epsilon=1e-9)))
Got error as expected from try(earth(SF ~ sex + ldose + ldose1, glm = list(family = binomial(link = "logit")),     eps = 123))
> expect.err(try(earth(SF ~ sex + ldose + ldose1, glm=list(family=binomial(link="logit"), weights=1:nrow(SF)))), "earth: illegal 'weights' in 'glm' argument")
Error : earth: illegal 'weights' in 'glm' argument
       Use earth's 'weights' argument instead (which will be passed on to glm internally)
Got error as expected from try(earth(SF ~ sex + ldose + ldose1, glm = list(family = binomial(link = "logit"),     weights = 1:nrow(SF))))
> expect.err(try(earth(SF ~ sex + ldose + ldose1, glm=list(family=binomial(link="logit"), subset=1:nrow(SF)))), "earth: illegal 'subset' in 'glm' argument")
Error : earth: illegal 'subset' in 'glm' argument
       Use earth's 'subset' argument instead (which will be passed on to glm internally)
Got error as expected from try(earth(SF ~ sex + ldose + ldose1, glm = list(family = binomial(link = "logit"),     subset = 1:nrow(SF))))
> expect.err(try(earth(SF ~ sex + ldose + ldose1, glm=list(family=binomial(link="logit"), formula=SF~sex))), "earth: illegal 'formula' in 'glm' argument")
Error : earth: illegal 'formula' in 'glm' argument
       Use earth's 'formula' argument instead
Got error as expected from try(earth(SF ~ sex + ldose + ldose1, glm = list(family = binomial(link = "logit"),     formula = SF ~ sex)))
> 
> plotres(a1h,                  caption="a1h: default type", legend.pos="topleft")
> plotres(a1h, type="response", caption="a1h: type=\"response\" (same as default type)", legend.pos="topleft")
> plotres(a1h, type="earth",    caption="a1h: type=\"earth\"", legend.pos="topleft")
> 
> # check update, also check params are carried forward properly with update
> a1h.update1 <- update(a1h, glm=list(family=binomial(link="probit"), maxit=8))
x[12,3] with colnames sexmale ldose ldose1
y[12,2] with colnames numdead numalive
earth and glm: unweighted
Response columns numdead and numalive are a binomial pair (240 obs in total)
yfrac[12,1] with colname numdead, and values 0.05, 0.2, 0.45, 0.65, 0.9, 1...
Skipped forward pass
Prune none penalty 3 nprune null: selected 3 of 3 terms, and 2 of 3 preds
After pruning pass GRSq 0.935 RSq 0.981
GLM numdead devratio 0.96 dof 9/11 iters 4
> stopifnot(a1h.update1$glm.list[[1]]$control$maxit == 8)
> show.earth.models(a1h.update1, legend.pos="topleft")

Print a1h.update1 

GLM (family binomial, link probit):
 nulldev df       dev df   devratio     AIC iters converged
 124.876 11   5.56596  9      0.955   41.68     4         1

Earth selected 3 of 3 terms, and 2 of 3 predictors (pmethod="none")
Termination condition: Reached nk 6
Importance: ldose, sexmale, ldose1-unused
Number of terms at each degree of interaction: 1 2 (additive model)
Earth GCV 0.008085317    RSS 0.02425595    GRSq 0.9353281    RSq 0.9807588

Summary a1h.update1 

Call: earth(formula=SF~sex+ldose+ldose1, pmethod=PMETHOD, trace=1,
            glm=list(family=binomial(link="probit"),maxit=8), degree=2, nk=NK,
            Object=a1h)

GLM coefficients
               numdead
(Intercept) -0.7954325
sexmale      0.6536447
ldose        0.6324486

GLM (family binomial, link probit):
 nulldev df       dev df   devratio     AIC iters converged
 124.876 11   5.56596  9      0.955   41.68     4         1

Earth selected 3 of 3 terms, and 2 of 3 predictors (pmethod="none")
Termination condition: Reached nk 6
Importance: ldose, sexmale, ldose1-unused
Number of terms at each degree of interaction: 1 2 (additive model)
Earth GCV 0.008085317    RSS 0.02425595    GRSq 0.9353281    RSq 0.9807588

Summary a1h.update1 digits=3, details=TRUE

Call: earth(formula=SF~sex+ldose+ldose1, pmethod=PMETHOD, trace=1,
            glm=list(family=binomial(link="probit"),maxit=8), degree=2, nk=NK,
            Object=a1h)

Earth coefficients
            numdead
(Intercept)   0.292
ldose         0.182
sexmale       0.158

GLM coefficients
            numdead
(Intercept)  -0.795
ldose         0.632
sexmale       0.654

GLM deviance residuals:
    Min       1Q   Median       3Q      Max  
-0.8917  -0.5833  -0.0773   0.4622   1.2710  

GLM coefficients (family binomial, link probit)
            Estimate Std. Error z value Pr(>|z|)
(Intercept)  -0.7954     0.1562   -5.09  3.5e-07
ldose         0.6324     0.0697    9.07  < 2e-16
sexmale       0.6536     0.2024    3.23   0.0012

GLM (family binomial, link probit):
 nulldev df       dev df   devratio     AIC iters converged
     125 11      5.57  9       0.96    41.7     4         1

Earth selected 3 of 3 terms, and 2 of 3 predictors (pmethod="none")
Termination condition: Reached nk 6
Importance: ldose, sexmale, ldose1-unused
Number of terms at each degree of interaction: 1 2 (additive model)
Earth GCV 0.00809    RSS 0.0243    GRSq 0.935    RSq 0.981

evimp a1h.update1 

        nsubsets   gcv    rss
ldose          2 100.0  100.0
sexmale        1  26.9   24.7

evimp a1h.update1 trim=FALSE

              nsubsets   gcv    rss
ldose                2 100.0  100.0
sexmale              1  26.9   24.7
ldose1-unused        0   0.0    0.0

glm params: epsilon 1e-08 maxit 8 trace FALSE family binomial link probit 

plotmo a1h.update1 
 plotmo grid:    sex ldose ldose1
              female   0.5    0.6
-------------------------------------------------------------------------------

> a1h.update2 <- update(a1h, glm=list(family=gaussian, maxit=9), degree=1)
x[12,3] with colnames sexmale ldose ldose1
y[12,2] with colnames numdead numalive
Forward pass term 1, 2, 4
Reached nk 6
After forward pass GRSq 0.952 RSq 0.981
Prune none penalty 2 nprune null: selected 3 of 3 terms, and 2 of 3 preds
After pruning pass GRSq 0.952 RSq 0.981
GLM numdead devratio 0.98 dof 9/11 iters 2
GLM numalive devratio 0.98 dof 9/11 iters 2
> stopifnot(a1h.update2$glm.list[[1]]$control$maxit == 9)
> show.earth.models(a1h.update2, nresponse="numdea", legend.pos="topleft")

Print a1h.update2 

GLM (family gaussian, link identity):
         nulldev df       dev df   devratio     AIC iters converged
numdead   504.25 11   9.70238  9      0.981    39.5     2         1
numalive  504.25 11   9.70238  9      0.981    39.5     2         1

Earth selected 3 of 3 terms, and 2 of 3 predictors (pmethod="none")
Termination condition: Reached nk 6
Importance: ldose, sexmale, ldose1-unused
Number of terms at each degree of interaction: 1 2 (additive model)

Earth
              GCV       RSS     GRSq       RSq
numdead  2.376093  9.702381 0.952486 0.9807588
numalive 2.376093  9.702381 0.952486 0.9807588
All      4.752187 19.404762 0.952486 0.9807588

Summary a1h.update2 

Call: earth(formula=SF~sex+ldose+ldose1, pmethod=PMETHOD, trace=1,
            glm=list(family=gaussian,maxit=9), degree=1, nk=NK)

GLM coefficients
             numdead  numalive
(Intercept) 5.845238 14.154762
sexmale     3.166667 -3.166667
ldose       3.642857 -3.642857

GLM (family gaussian, link identity):
         nulldev df       dev df   devratio     AIC iters converged
numdead   504.25 11   9.70238  9      0.981    39.5     2         1
numalive  504.25 11   9.70238  9      0.981    39.5     2         1

Earth selected 3 of 3 terms, and 2 of 3 predictors (pmethod="none")
Termination condition: Reached nk 6
Importance: ldose, sexmale, ldose1-unused
Number of terms at each degree of interaction: 1 2 (additive model)

Earth
              GCV       RSS     GRSq       RSq
numdead  2.376093  9.702381 0.952486 0.9807588
numalive 2.376093  9.702381 0.952486 0.9807588
All      4.752187 19.404762 0.952486 0.9807588

Summary a1h.update2 decomp="none", digits=5, fixed.point=FALSE, details=TRUE

Call: earth(formula=SF~sex+ldose+ldose1, pmethod=PMETHOD, trace=1,
            glm=list(family=gaussian,maxit=9), degree=1, nk=NK)

Earth coefficients
            numdead numalive
(Intercept)  5.8452  14.1548
ldose        3.6429  -3.6429
sexmale      3.1667  -3.1667

GLM coefficients
            numdead numalive
(Intercept)  5.8452  14.1548
ldose        3.6429  -3.6429
sexmale      3.1667  -3.1667

GLM numdead deviance residuals:
     Min        1Q    Median        3Q       Max  
-1.36905  -0.73810   0.02381   0.38690   1.70238  

GLM numdead coefficients (family gaussian, link identity)
            Estimate Std. Error t value  Pr(>|t|)
(Intercept)  5.84524    0.43287 13.5035 2.800e-07
ldose        3.64286    0.17550 20.7567 6.542e-09
sexmale      3.16667    0.59946  5.2826 0.0005054

GLM numdead dispersion parameter for gaussian family taken to be 1.078042

GLM numalive deviance residuals:
     Min        1Q    Median        3Q       Max  
-1.70238  -0.38690  -0.02381   0.73810   1.36905  

GLM numalive coefficients (family gaussian, link identity)
            Estimate Std. Error  t value  Pr(>|t|)
(Intercept) 14.15476    0.43287  32.7000 1.151e-10
ldose       -3.64286    0.17550 -20.7567 6.542e-09
sexmale     -3.16667    0.59946  -5.2826 0.0005054

GLM numalive dispersion parameter for gaussian family taken to be 1.078042

GLM (family gaussian, link identity):
         nulldev df       dev df   devratio     AIC iters converged
numdead    504.2 11     9.702  9       0.98    39.5     2         1
numalive   504.2 11     9.702  9       0.98    39.5     2         1

Earth selected 3 of 3 terms, and 2 of 3 predictors (pmethod="none")
Termination condition: Reached nk 6
Importance: ldose, sexmale, ldose1-unused
Number of terms at each degree of interaction: 1 2 (additive model)

Earth
            GCV     RSS    GRSq     RSq
numdead  2.3761  9.7024 0.95249 0.98076
numalive 2.3761  9.7024 0.95249 0.98076
All      4.7522 19.4048 0.95249 0.98076

evimp a1h.update2 

        nsubsets   gcv    rss
ldose          2 100.0  100.0
sexmale        1  27.2   24.7

evimp a1h.update2 trim=FALSE

              nsubsets   gcv    rss
ldose                2 100.0  100.0
sexmale              1  27.2   24.7
ldose1-unused        0   0.0    0.0

glm params: epsilon 1e-08 maxit 9 trace FALSE family gaussian link identity 

plotmo a1h.update2 
 plotmo grid:    sex ldose ldose1
              female   0.5    0.6
-------------------------------------------------------------------------------

> 
> # basic check with an I in formula
> a1i <-  earth(SF ~ sex + ldose + I(ldose1-3), glm=list(family="binomial"), trace=1, pmethod=PMETHOD, nk=NK, degree=2)
x[12,3] with colnames sexmale ldose I(ldose1-3)
y[12,2] with colnames numdead numalive
earth and glm: unweighted
Response columns numdead and numalive are a binomial pair (240 obs in total)
yfrac[12,1] with colname numdead, and values 0.05, 0.2, 0.45, 0.65, 0.9, 1...
Forward pass term 1, 2, 4
Reached nk 6
After forward pass GRSq 0.935 RSq 0.981
Prune none penalty 3 nprune null: selected 3 of 3 terms, and 2 of 3 preds
After pruning pass GRSq 0.935 RSq 0.981
GLM numdead devratio 0.95 dof 9/11 iters 4
> print(summary(a1i))
Call: earth(formula=SF~sex+ldose+I(ldose1-3), pmethod=PMETHOD, trace=1,
            glm=list(family="binomial"), degree=2, nk=NK)

GLM coefficients
              numdead
(Intercept) -1.344727
sexmale      1.100743
ldose        1.064214

GLM (family binomial, link logit):
 nulldev df       dev df   devratio     AIC iters converged
 124.876 11   6.75706  9      0.946   42.87     4         1

Earth selected 3 of 3 terms, and 2 of 3 predictors (pmethod="none")
Termination condition: Reached nk 6
Importance: ldose, sexmale, I(ldose1-3)-unused
Number of terms at each degree of interaction: 1 2 (additive model)
Earth GCV 0.008085317    RSS 0.02425595    GRSq 0.9353281    RSq 0.9807588
> 
> cat("a2: single response glm model but with a binomial pair of y columns, degree=1\n\n")
a2: single response glm model but with a binomial pair of y columns, degree=1

> a2 <-  earth(SF ~ sex*ldose, glm=list(fa="b"), trace=3, pmethod=PMETHOD)
x[12,3] with colnames sexmale ldose sexmale:ldose
y[12,2] with colnames numdead numalive
earth and glm: unweighted
Response columns numdead and numalive are a binomial pair (240 obs in total)
yfrac[12,1] with colname numdead, and values 0.05, 0.2, 0.45, 0.65, 0.9, 1...
Forward pass: minspan 3 endspan 5   x[12,3] 288 Bytes   bx[12,21] 1.97 kB

         GRSq    RSq     DeltaRSq Pred     PredName         Cut  Terms   Par Deg
1      0.0000 0.0000                    (Intercept)
2      0.8821 0.9211       0.9211    2        ldose          -2< 2             1 
4      0.9525 0.9808      0.05966    1      sexmale           0< 3             1 
6      0.8826 0.9913      0.01051    3 sexmale:ldos           0  4   5         1 
8     -0.0568 0.9913            0    -                                       reject (no DeltaRsq)

RSq changed by less than 0.001 at 7 terms, 5 terms used (DeltaRSq 0)
After forward pass GRSq -0.057 RSq 0.991
Forward pass complete: 7 terms, 5 terms used

Subset size        GRSq     RSq  DeltaGRSq nPreds
          1      0.0000  0.0000     0.0000      0  
          2      0.8821  0.9211     0.8821      1  
          3      0.9525  0.9808     0.0704      2  
          4      0.9402  0.9876    -0.0123      3  
chosen    5      0.8826  0.9913    -0.0576      3  

Prune none penalty 2 nprune null: selected 5 of 5 terms, and 3 of 3 preds
After pruning pass GRSq 0.883 RSq 0.991
GLM numdead devratio 0.96 dof 7/11 iters 4
> show.earth.models(a2, legend.pos="topleft")

Print a2 

GLM (family binomial, link logit):
 nulldev df       dev df   devratio     AIC iters converged
 124.876 11   4.96002  7       0.96   45.07     4         1

Earth selected 5 of 5 terms, and 3 of 3 predictors (pmethod="none")
Termination condition: RSq changed by less than 0.001 at 5 terms
Importance: ldose, sexmale, sexmale:ldose
Number of terms at each degree of interaction: 1 4 (additive model)
Earth GCV 0.01468087    RSS 0.01101065    GRSq 0.8825725    RSq 0.9912657

Summary a2 

Call: earth(formula=SF~sex*ldose, pmethod=PMETHOD, trace=3, glm=list(fa="b"))

GLM coefficients
                      numdead
(Intercept)        -1.1814689
sexmale             0.8263579
ldose               0.9060364
h(0-sexmale:ldose) -0.2777279
h(sexmale:ldose-0)  0.4011671

GLM (family binomial, link logit):
 nulldev df       dev df   devratio     AIC iters converged
 124.876 11   4.96002  7       0.96   45.07     4         1

Earth selected 5 of 5 terms, and 3 of 3 predictors (pmethod="none")
Termination condition: RSq changed by less than 0.001 at 5 terms
Importance: ldose, sexmale, sexmale:ldose
Number of terms at each degree of interaction: 1 4 (additive model)
Earth GCV 0.01468087    RSS 0.01101065    GRSq 0.8825725    RSq 0.9912657

Summary a2 digits=3, details=TRUE

Call: earth(formula=SF~sex*ldose, pmethod=PMETHOD, trace=3, glm=list(fa="b"))

Earth coefficients
                   numdead
(Intercept)         0.3019
ldose               0.1629
sexmale             0.1490
h(sexmale:ldose-0)  0.0332
h(0-sexmale:ldose) -0.0477

GLM coefficients
                   numdead
(Intercept)         -1.181
ldose                0.906
sexmale              0.826
h(sexmale:ldose-0)   0.401
h(0-sexmale:ldose)  -0.278

GLM deviance residuals:
   Min      1Q  Median      3Q     Max  
-1.398  -0.321  -0.116   0.411   1.056  

GLM coefficients (family binomial, link logit)
                   Estimate Std. Error z value Pr(>|z|)
(Intercept)          -1.181      0.285   -4.14  3.5e-05
ldose                 0.906      0.167    5.42  5.9e-08
sexmale               0.826      0.489    1.69    0.091
h(sexmale:ldose-0)    0.401      0.380    1.06    0.291
h(0-sexmale:ldose)   -0.278      0.486   -0.57    0.568

GLM (family binomial, link logit):
 nulldev df       dev df   devratio     AIC iters converged
     125 11      4.96  7       0.96    45.1     4         1

Earth selected 5 of 5 terms, and 3 of 3 predictors (pmethod="none")
Termination condition: RSq changed by less than 0.001 at 5 terms
Importance: ldose, sexmale, sexmale:ldose
Number of terms at each degree of interaction: 1 4 (additive model)
Earth GCV 0.0147    RSS 0.011    GRSq 0.883    RSq 0.991

evimp a2 

              nsubsets   gcv    rss
ldose                4 100.0  100.0
sexmale              3   2.2   26.6
sexmale:ldose        2 -28.1   10.3

evimp a2 trim=FALSE

              nsubsets   gcv    rss
ldose                4 100.0  100.0
sexmale              3   2.2   26.6
sexmale:ldose        2 -28.1   10.3

glm params: epsilon 1e-08 maxit 25 trace FALSE family binomial link logit 

plotmo a2 
 plotmo grid:    sex ldose
              female   0.5
-------------------------------------------------------------------------------

> # repeat with bpairs arg
> a2a <- earth(SF ~ sex*ldose, glm=list(family="binomial", bpairs=c(TRUE,FALSE)), trace=3, pmethod=PMETHOD)
x[12,3] with colnames sexmale ldose sexmale:ldose
y[12,2] with colnames numdead numalive
Warning: earth: the 'bpairs' argument is no longer supported
         (binomial pairs are determined automatically)
         See comments for 'bpairs' in the earth NEWS file (earth version 5.0.0)
earth and glm: unweighted
Response columns numdead and numalive are a binomial pair (240 obs in total)
yfrac[12,1] with colname numdead, and values 0.05, 0.2, 0.45, 0.65, 0.9, 1...
Forward pass: minspan 3 endspan 5   x[12,3] 288 Bytes   bx[12,21] 1.97 kB

         GRSq    RSq     DeltaRSq Pred     PredName         Cut  Terms   Par Deg
1      0.0000 0.0000                    (Intercept)
2      0.8821 0.9211       0.9211    2        ldose          -2< 2             1 
4      0.9525 0.9808      0.05966    1      sexmale           0< 3             1 
6      0.8826 0.9913      0.01051    3 sexmale:ldos           0  4   5         1 
8     -0.0568 0.9913            0    -                                       reject (no DeltaRsq)

RSq changed by less than 0.001 at 7 terms, 5 terms used (DeltaRSq 0)
After forward pass GRSq -0.057 RSq 0.991
Forward pass complete: 7 terms, 5 terms used

Subset size        GRSq     RSq  DeltaGRSq nPreds
          1      0.0000  0.0000     0.0000      0  
          2      0.8821  0.9211     0.8821      1  
          3      0.9525  0.9808     0.0704      2  
          4      0.9402  0.9876    -0.0123      3  
chosen    5      0.8826  0.9913    -0.0576      3  

Prune none penalty 2 nprune null: selected 5 of 5 terms, and 3 of 3 preds
After pruning pass GRSq 0.883 RSq 0.991
GLM numdead devratio 0.96 dof 7/11 iters 4
> stopifnot(identical(a2$glm.list[[1]]$coefficients, a2a$glm.list[[1]]$coefficients))
> stopifnot(isTRUE(all.equal(coef(a2), coefficients(a2))))
> stopifnot(isTRUE(all.equal(coef(a2, type="glm"), coefficients(a2, type="glm"))))
> stopifnot(isTRUE(all.equal(coef(a2, type="earth"), coefficients(a2, type="earth"))))
> stopifnot(identical(names(coef(a2)), rownames(a2$coefficients)))
> stopifnot(identical(names(coef(a2)), rownames(a2$glm.coefficients)))
> stopifnot(identical(names(coef(a2, type="glm")), rownames(a2$glm.coefficients)))
> stopifnot(max(abs(coef(a2) - a2$glm.coefficients)) == 0)
> stopifnot(max(abs(coef(a2, type="earth") - a2$coefficients)) == 0)
> stopifnot(max(abs(coef(a2) - a2$glm.list[[1]]$coefficients)) == 0)
> a2b <- earth(numdead+numalive~sex*ldose, glm=list(family="binomial"), pmethod=PMETHOD)
> predict.a2 <- predict(a2,newdata=data.frame(sex=sex[1],ldose=3))
> predict.a2a <- predict(a2a,newdata=data.frame(sex=sex[1],ldose=3))
> predict.a2b <- predict(a2b,newdata=data.frame(sex=sex[1],ldose=3))
> stopifnot(identical(predict.a2a, predict.a2))
> stopifnot(identical(predict.a2b, predict.a2))
> 
> a2c <- earth(SF ~ sex, glm=list(family="binomial"), trace=0, pmethod=PMETHOD)
> a2update <- update(a2, SF ~ sex, trace=0)
> check.models.equal(a2c, a2update, msg="a2c a2update", newdata=data.frame(sex="female", ldose=10, ldose1=11))
a2c a2update: models not identical

a2c a2update: glm submodel formula strings are identical: yarg ~ sexmale
a2c a2update: but the actual glm submodel formulas differ (classes are "formula" and "formula")
a2c a2update: glm submodels not identical (but coefs, residuals, fitted.values are the same)
a2c a2update: Models are equivalent, within numerical tolerances

> 
> # build a standard GLM model for comparison
> cat("a3: direct GLM a3:\n\n")
a3: direct GLM a3:

> a3 <- glm(SF ~ sex * ldose, family="binomial")
> print(summary(a3))

Call:
glm(formula = SF ~ sex * ldose, family = "binomial")

Deviance Residuals: 
     Min        1Q    Median        3Q       Max  
-1.39849  -0.32094  -0.07592   0.38220   1.10375  

Coefficients:
              Estimate Std. Error z value Pr(>|z|)    
(Intercept)    -1.1815     0.2853  -4.141 3.46e-05 ***
sexmale         0.8808     0.3884   2.268   0.0234 *  
ldose           0.9060     0.1671   5.422 5.89e-08 ***
sexmale:ldose   0.3529     0.2700   1.307   0.1912    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 124.8756  on 11  degrees of freedom
Residual deviance:   4.9937  on  8  degrees of freedom
AIC: 43.104

Number of Fisher Scoring iterations: 4

> plotmo(a3, caption="a3 <- glm(SF ~ sex * ldose, family=\"binomial\")")
 plotmo grid:    sex ldose
              female   0.5
> cat("-------------------------------------------------------------------------------\n\n")
-------------------------------------------------------------------------------

> 
> # double response glm model with two binomial paired cols
> SF.both <- cbind(SF, SF2)
> cat("a4: double response glm model with two binomial paired cols\n\n")
a4: double response glm model with two binomial paired cols

> expect.err(try(earth(SF.both ~ sex*ldose, linpreds=TRUE, glm=list(family="binomial"), trace=1)), "Binomial response (see above): all values should be between 0 and 1, or a binomial pair")
x[12,3] with colnames sexmale ldose sexmale:ldose
y[12,4] with colnames numdead numalive numdead2 numalive2

print(head(y)):
     numdead numalive numdead2 numalive2
[1,]       1       19        2        18
[2,]       4       16        3        17
[3,]       9       11       10        10
[4,]      13        7       13         7
[5,]      18        2       19         1
[6,]      20        0       20         0

Error : Binomial response (see above): all values should be between 0 and 1, or a binomial pair
Got error as expected from try(earth(SF.both ~ sex * ldose, linpreds = TRUE, glm = list(family = "binomial"),     trace = 1))
> 
> # titanic data, multiple responses (i.e. 3 level factor)
> cat("a5: titanic data, multiple responses (i.e. 3 level factor)\n\n")
a5: titanic data, multiple responses (i.e. 3 level factor)

> a5 <- earth(pclass ~ ., data=etitanic, degree=2, glm=list(family="binomial"), trace=0)
> show.earth.models(a5, nresponse=1)

Print a5 

GLM (family binomial, link logit):
    nulldev   df       dev   df   devratio     AIC iters converged
1st 1223.31 1045   894.814 1037     0.2690   912.8     5         1
2nd 1175.31 1045  1126.944 1037     0.0411  1145.0     5         1
3rd 1448.21 1045  1118.941 1037     0.2270  1137.0     5         1

Earth selected 9 of 17 terms, and 5 of 5 predictors
Termination condition: Reached nk 21
Importance: age, parch, survived, sibsp, sexmale
Number of terms at each degree of interaction: 1 4 4

Earth
          GCV      RSS        GRSq        RSq
1st 0.1478715 148.5253 0.253819943 0.28210854
2nd 0.1869804 187.8072 0.003405389 0.04118751
3rd 0.1895587 190.3968 0.241872961 0.27061448
All 0.5244105 526.7293 0.175229617 0.20649767

Summary a5 

Call: earth(formula=pclass~., data=etitanic, trace=0,
            glm=list(family="binomial"), degree=2)

GLM coefficients
                                1st         2nd         3rd
(Intercept)             -2.66307135 -1.93136147  1.37992944
survived                 2.84788552  1.06418271 -2.84378575
sexmale                  1.42483431  0.96598862 -1.45239590
h(sibsp-1)              -0.52879762 -0.64928949  0.79974678
h(2-parch)               1.25518755  0.06534587 -1.29855706
survived * sexmale      -1.25498201 -1.95099222  2.28554497
survived * h(16-age)    -0.17824991  0.09390085  0.02011681
h(55-age) * h(2-parch)  -0.04946408  0.00043737  0.04146455
h(1-sibsp) * h(1-parch) -1.02162885 -0.21902436  1.12490799

GLM (family binomial, link logit):
    nulldev   df       dev   df   devratio     AIC iters converged
1st 1223.31 1045   894.814 1037     0.2690   912.8     5         1
2nd 1175.31 1045  1126.944 1037     0.0411  1145.0     5         1
3rd 1448.21 1045  1118.941 1037     0.2270  1137.0     5         1

Earth selected 9 of 17 terms, and 5 of 5 predictors
Termination condition: Reached nk 21
Importance: age, parch, survived, sibsp, sexmale
Number of terms at each degree of interaction: 1 4 4

Earth
          GCV      RSS        GRSq        RSq
1st 0.1478715 148.5253 0.253819943 0.28210854
2nd 0.1869804 187.8072 0.003405389 0.04118751
3rd 0.1895587 190.3968 0.241872961 0.27061448
All 0.5244105 526.7293 0.175229617 0.20649767

Summary a5 decomp="none", digits=5, fixed.point=FALSE, details=TRUE

Call: earth(formula=pclass~., data=etitanic, trace=0,
            glm=list(family="binomial"), degree=2)

Earth coefficients
                               1st         2nd        3rd
(Intercept)              0.1396780  1.3822e-01  0.7221057
survived                 0.3518559  1.6023e-01 -0.5120905
h(sibsp-1)              -0.0479585 -6.7564e-02  0.1155224
h(2-parch)               0.2173334  9.4235e-03 -0.2267568
survived * h(16-age)    -0.0232585  1.8686e-02  0.0045728
survived * sexmale      -0.0959323 -3.0327e-01  0.3992025
sexmale                  0.1093674  1.3653e-01 -0.2458963
h(55-age) * h(2-parch)  -0.0078473  3.5599e-05  0.0078117
h(1-sibsp) * h(1-parch) -0.1623930 -3.2878e-02  0.1952714

GLM coefficients
                              1st         2nd       3rd
(Intercept)             -2.663071 -1.93136147  1.379929
survived                 2.847886  1.06418271 -2.843786
h(sibsp-1)              -0.528798 -0.64928949  0.799747
h(2-parch)               1.255188  0.06534587 -1.298557
survived * h(16-age)    -0.178250  0.09390085  0.020117
survived * sexmale      -1.254982 -1.95099222  2.285545
sexmale                  1.424834  0.96598862 -1.452396
h(55-age) * h(2-parch)  -0.049464  0.00043737  0.041465
h(1-sibsp) * h(1-parch) -1.021629 -0.21902436  1.124908

GLM 1st deviance residuals:
     Min        1Q    Median        3Q       Max  
-2.02122  -0.68435  -0.35766   0.56892   2.66017  

GLM 1st coefficients (family binomial, link logit)
                          Estimate Std. Error  z value  Pr(>|z|)
(Intercept)             -2.6630714  0.5298325  -5.0263 5.002e-07
survived                 2.8478855  0.5104917   5.5787 2.423e-08
h(sibsp-1)              -0.5287976  0.2365149  -2.2358 0.0253656
h(2-parch)               1.2551876  0.1875848   6.6913 2.212e-11
survived * h(16-age)    -0.1782499  0.0515714  -3.4564 0.0005475
survived * sexmale      -1.2549820  0.5640362  -2.2250 0.0260811
sexmale                  1.4248343  0.5092679   2.7978 0.0051451
h(55-age) * h(2-parch)  -0.0494641  0.0044068 -11.2244 < 2.2e-16
h(1-sibsp) * h(1-parch) -1.0216289  0.2129941  -4.7965 1.615e-06

GLM 2nd deviance residuals:
     Min        1Q    Median        3Q       Max  
-1.45407  -0.80675  -0.77534  -0.10402   2.07089  

GLM 2nd coefficients (family binomial, link logit)
                           Estimate  Std. Error z value  Pr(>|z|)
(Intercept)             -1.93136147  0.37697795 -5.1233 3.003e-07
survived                 1.06418271  0.34979070  3.0423 0.0023475
h(sibsp-1)              -0.64928949  0.22307746 -2.9106 0.0036073
h(2-parch)               0.06534587  0.17330956  0.3770 0.7061386
survived * h(16-age)     0.09390085  0.02842944  3.3029 0.0009568
survived * sexmale      -1.95099222  0.43722003 -4.4623 8.110e-06
sexmale                  0.96598862  0.34300568  2.8162 0.0048588
h(55-age) * h(2-parch)   0.00043737  0.00357988  0.1222 0.9027599
h(1-sibsp) * h(1-parch) -0.21902436  0.19299092 -1.1349 0.2564195

GLM 3rd deviance residuals:
     Min        1Q    Median        3Q       Max  
-2.32939  -0.83909  -0.32160   0.89944   2.61933  

GLM 3rd coefficients (family binomial, link logit)
                          Estimate Std. Error z value  Pr(>|z|)
(Intercept)              1.3799294  0.3534087  3.9046 9.437e-05
survived                -2.8437858  0.3383356 -8.4052 < 2.2e-16
h(sibsp-1)               0.7997468  0.1912028  4.1827 2.880e-05
h(2-parch)              -1.2985571  0.1912192 -6.7909 1.114e-11
survived * h(16-age)     0.0201168  0.0284533  0.7070    0.4796
survived * sexmale       2.2855450  0.3990264  5.7278 1.017e-08
sexmale                 -1.4523959  0.3219393 -4.5114 6.440e-06
h(55-age) * h(2-parch)   0.0414645  0.0040611 10.2101 < 2.2e-16
h(1-sibsp) * h(1-parch)  1.1249080  0.2035671  5.5260 3.276e-08

GLM (family binomial, link logit):
    nulldev   df       dev   df   devratio     AIC iters converged
1st    1223 1045     894.8 1037      0.270     913     5         1
2nd    1175 1045    1126.9 1037      0.041    1140     5         1
3rd    1448 1045    1118.9 1037      0.230    1140     5         1

Earth selected 9 of 17 terms, and 5 of 5 predictors
Termination condition: Reached nk 21
Importance: age, parch, survived, sibsp, sexmale
Number of terms at each degree of interaction: 1 4 4

Earth
        GCV    RSS      GRSq      RSq
1st 0.14787 148.53 0.2538199 0.282108
2nd 0.18698 187.81 0.0034054 0.041188
3rd 0.18956 190.40 0.2418730 0.270614
All 0.52441 526.73 0.1752296 0.206498

evimp a5 

         nsubsets   gcv    rss
age             8 100.0  100.0
parch           8 100.0  100.0
survived        7  79.7   81.7
sibsp           5  40.3   48.0
sexmale         4  34.4   41.7

evimp a5 trim=FALSE

         nsubsets   gcv    rss
age             8 100.0  100.0
parch           8 100.0  100.0
survived        7  79.7   81.7
sibsp           5  40.3   48.0
sexmale         4  34.4   41.7

glm params: epsilon 1e-08 maxit 25 trace FALSE family binomial link logit 

plotmo a5 
 plotmo grid:    survived  sex age sibsp parch
                        0 male  28     0     0
-------------------------------------------------------------------------------

> printh(a5$levels)
=== a5$levels
[1] "1st" "2nd" "3rd"
> print.stripped.earth.model(a5, "a5")
print.stripped.earth.model(a5)
$rss
[1] 526.7293

$rsq
[1] 0.2064977

$gcv
[1] 0.5244105

$grsq
[1] 0.1752296

$dirs
                      survived sexmale age sibsp parch
(Intercept)                  0       0   0     0     0
h(age-26)                    0       0   1     0     0
h(26-age)                    0       0  -1     0     0
survived                     2       0   0     0     0
h(sibsp-1)                   0       0   0     1     0
h(1-sibsp)                   0       0   0    -1     0
h(parch-2)                   0       0   0     0     1
h(2-parch)                   0       0   0     0    -1
survived*h(age-16)           2       0   1     0     0
survived*h(16-age)           2       0  -1     0     0
survived*sexmale             2       2   0     0     0
sexmale                      0       2   0     0     0
h(age-55)*h(2-parch)         0       0   1     0    -1
h(55-age)*h(2-parch)         0       0  -1     0    -1
h(1-sibsp)*h(parch-1)        0       0   0    -1     1
h(1-sibsp)*h(1-parch)        0       0   0    -1    -1
h(age-54)                    0       0   1     0     0

$cuts
                      survived sexmale age sibsp parch
(Intercept)                  0       0   0     0     0
h(age-26)                    0       0  26     0     0
h(26-age)                    0       0  26     0     0
survived                     0       0   0     0     0
h(sibsp-1)                   0       0   0     1     0
h(1-sibsp)                   0       0   0     1     0
h(parch-2)                   0       0   0     0     2
h(2-parch)                   0       0   0     0     2
survived*h(age-16)           0       0  16     0     0
survived*h(16-age)           0       0  16     0     0
survived*sexmale             0       0   0     0     0
sexmale                      0       0   0     0     0
h(age-55)*h(2-parch)         0       0  55     0     2
h(55-age)*h(2-parch)         0       0  55     0     2
h(1-sibsp)*h(parch-1)        0       0   0     1     1
h(1-sibsp)*h(1-parch)        0       0   0     1     1
h(age-54)                    0       0  54     0     0

$selected.terms
[1]  1  4  5  8 10 11 12 14 16

$prune.terms
      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
 [1,]    1    0    0    0    0    0    0    0    0     0     0     0     0
 [2,]    1   14    0    0    0    0    0    0    0     0     0     0     0
 [3,]    1    4   14    0    0    0    0    0    0     0     0     0     0
 [4,]    1    4    8   14    0    0    0    0    0     0     0     0     0
 [5,]    1    4    8   14   16    0    0    0    0     0     0     0     0
 [6,]    1    4    8   11   14   16    0    0    0     0     0     0     0
 [7,]    1    4    8   11   12   14   16    0    0     0     0     0     0
 [8,]    1    4    5    8   11   12   14   16    0     0     0     0     0
 [9,]    1    4    5    8   10   11   12   14   16     0     0     0     0
[10,]    1    4    5    8   10   11   12   14   16    17     0     0     0
[11,]    1    4    5    8   10   11   12   13   14    16    17     0     0
[12,]    1    4    5    7    8   10   11   12   13    14    16    17     0
[13,]    1    3    4    5    7    8   10   11   12    13    14    16    17
[14,]    1    3    4    5    7    8    9   10   11    12    13    14    16
[15,]    1    3    4    5    6    7    8    9   10    11    12    13    14
[16,]    1    3    4    5    6    7    8    9   10    11    12    13    14
[17,]    1    2    3    4    5    6    7    8    9    10    11    12    13
      [,14] [,15] [,16] [,17]
 [1,]     0     0     0     0
 [2,]     0     0     0     0
 [3,]     0     0     0     0
 [4,]     0     0     0     0
 [5,]     0     0     0     0
 [6,]     0     0     0     0
 [7,]     0     0     0     0
 [8,]     0     0     0     0
 [9,]     0     0     0     0
[10,]     0     0     0     0
[11,]     0     0     0     0
[12,]     0     0     0     0
[13,]     0     0     0     0
[14,]    17     0     0     0
[15,]    16    17     0     0
[16,]    15    16    17     0
[17,]    14    15    16    17

$coefficients
                               1st           2nd          3rd
(Intercept)            0.139677983  0.1382163301  0.722105687
survived               0.351855854  0.1602346217 -0.512090476
h(sibsp-1)            -0.047958497 -0.0675639271  0.115522424
h(2-parch)             0.217333399  0.0094234505 -0.226756850
survived*h(16-age)    -0.023258457  0.0186856516  0.004572806
survived*sexmale      -0.095932289 -0.3032702269  0.399202516
sexmale                0.109367428  0.1365288369 -0.245896265
h(55-age)*h(2-parch)  -0.007847314  0.0000355992  0.007811715
h(1-sibsp)*h(1-parch) -0.162393009 -0.0328783910  0.195271400

$rss.per.response
[1] 148.5253 187.8072 190.3968

$rsq.per.response
[1] 0.28210854 0.04118751 0.27061448

$gcv.per.response
[1] 0.1478715 0.1869804 0.1895587

$grsq.per.response
[1] 0.253819943 0.003405389 0.241872961

$rss.per.subset
 [1] 663.8031 618.3144 587.1155 558.2529 550.5473 546.0083 539.0533 532.1400
 [9] 526.7293 526.1097 522.0963 519.3960 516.5436 515.0676 514.2161 513.5054
[17] 513.3259

$gcv.per.subset
 [1] 0.6358261 0.5950986 0.5677911 0.5424834 0.5375831 0.5357360 0.5314825
 [8] 0.5272225 0.5244105 0.5263582 0.5249065 0.5247609 0.5244530 0.5255400
[15] 0.5272719 0.5291595 0.5316095

$leverages
   [1] 0.005158606 0.033494707 0.017266066 0.011963928 0.017266066 0.011263458
   [7] 0.011670960 0.002889399 0.014370755 0.007592325 0.008274991 0.008886300
  [13] 0.005594526 0.005363932 0.013850834 0.005386378 0.005441478 0.005121957
  [19] 0.002541748 0.010859171 0.005243409 0.009110406 0.006218027 0.005158606
  [25] 0.002710161 0.012630619 0.008624204 0.005253987 0.008931298 0.004090736
  [31] 0.009430977 0.005127648 0.010444850 0.003405728 0.006912318 0.005232760
  [37] 0.003214876 0.004944421 0.006662146 0.015229279 0.010444850 0.006024081
  [43] 0.004090736 0.009776645 0.009588407 0.010855244 0.005865304 0.002362774
  [49] 0.002439326 0.004257037 0.014508881 0.009550159 0.017792581 0.010894224
  [55] 0.005266467 0.006450345 0.011670960 0.008015404 0.008894797 0.012364077
  [61] 0.006922784 0.005335481 0.005127648 0.010435712 0.006644234 0.007314315
  [67] 0.005900089 0.004641118 0.004921387 0.005128157 0.010894224 0.015229279
  [73] 0.006077876 0.010894224 0.005865304 0.006723071 0.007205379 0.012259881
  [79] 0.009011481 0.005147225 0.006370641 0.010894224 0.012055896 0.009167137
  [85] 0.011559223 0.024055130 0.005771168 0.009166204 0.005000615 0.009176221
  [91] 0.009176221 0.014380004 0.002889399 0.005176960 0.005554695 0.011258343
  [97] 0.012825352 0.008964545 0.002352479 0.014998031 0.014998031 0.014998031
 [103] 0.013529385 0.011963928 0.010894224 0.005127648 0.017721685 0.012930589
 [109] 0.010894224 0.011731068 0.005304747 0.006522512 0.006979596 0.004641118
 [115] 0.005253987 0.005232760 0.005134791 0.002837924 0.014380004 0.007592325
 [121] 0.013017873 0.006498998 0.005141092 0.005865304 0.011230581 0.005134791
 [127] 0.004356556 0.012630619 0.007445216 0.014091580 0.009476386 0.007774559
 [133] 0.006979596 0.003042767 0.009011481 0.005594526 0.006077876 0.005596952
 [139] 0.003405728 0.007592325 0.005665956 0.005087510 0.010132943 0.007164476
 [145] 0.006979596 0.008894792 0.012238148 0.006979596 0.005554695 0.016839282
 [151] 0.011576857 0.004356556 0.005607255 0.002349345 0.007592325 0.006998599
 [157] 0.012754617 0.008388177 0.005692415 0.008100426 0.005127648 0.008894792
 [163] 0.003405728 0.010444850 0.005665956 0.005516873 0.002386532 0.006080983
 [169] 0.002352479 0.010444850 0.005177299 0.002352479 0.007266584 0.008091037
 [175] 0.008886300 0.005594526 0.004356556 0.007157827 0.008964545 0.006547723
 [181] 0.007592325 0.009555430 0.006922784 0.007111376 0.012104828 0.007592325
 [187] 0.004641118 0.005128157 0.006940939 0.007763244 0.011963928 0.010894224
 [193] 0.007592325 0.005692415 0.005232760 0.006077876 0.002410586 0.004221303
 [199] 0.002984428 0.006469953 0.007950371 0.008356226 0.009167137 0.005127648
 [205] 0.012629506 0.004641118 0.005865304 0.002754773 0.003149675 0.005044914
 [211] 0.002337169 0.010435712 0.005147225 0.004356556 0.002541748 0.005147225
 [217] 0.011026399 0.011258343 0.002362774 0.013933400 0.010020765 0.010020765
 [223] 0.011963928 0.010894224 0.005594526 0.006979596 0.005127648 0.008843781
 [229] 0.005848877 0.008894792 0.009166204 0.007318124 0.013850834 0.008931298
 [235] 0.007592325 0.007592325 0.007046220 0.008886300 0.012792003 0.007763244
 [241] 0.019643889 0.011059261 0.004945241 0.011026399 0.008797985 0.007592325
 [247] 0.016103256 0.007956525 0.010489334 0.010444850 0.011026399 0.021013236
 [253] 0.007592325 0.007775286 0.010894224 0.005814165 0.004921387 0.014091580
 [259] 0.005592625 0.017792581 0.004921387 0.008803201 0.003042767 0.007592325
 [265] 0.004641118 0.005253987 0.011026399 0.011670960 0.007592325 0.005985287
 [271] 0.005558420 0.010444850 0.010894224 0.006077876 0.005134791 0.005661786
 [277] 0.011963928 0.005441478 0.006080983 0.005735633 0.011358608 0.005115432
 [283] 0.007592325 0.005335481 0.006410926 0.007108739 0.002352479 0.003998081
 [289] 0.002710161 0.006362237 0.007036115 0.007592325 0.003998081 0.002984428
 [295] 0.005335481 0.002439326 0.005966785 0.012025706 0.008624204 0.002439326
 [301] 0.033505449 0.023497806 0.006963553 0.010894224 0.008843781 0.006498998
 [307] 0.002984428 0.002601141 0.003405728 0.002510862 0.005594526 0.010053817
 [313] 0.006077876 0.004945241 0.008380851 0.006893482 0.005335481 0.002710161
 [319] 0.003405728 0.006218027 0.033794505 0.011073682 0.005232760 0.005253987
 [325] 0.003757866 0.016794103 0.010616876 0.006345057 0.006522512 0.014695434
 [331] 0.005079416 0.010894224 0.006469953 0.007108739 0.002386532 0.002439326
 [337] 0.009364483 0.013599923 0.005148940 0.004899238 0.005900089 0.012229617
 [343] 0.003333663 0.013085174 0.003998081 0.010894224 0.005208306 0.002340601
 [349] 0.004257037 0.006469953 0.007594859 0.002710161 0.003998081 0.005502815
 [355] 0.004872402 0.007157827 0.016579641 0.005239689 0.004872402 0.007202156
 [361] 0.006978130 0.002984428 0.003333663 0.003998081 0.006851464 0.007034064
 [367] 0.003998081 0.002541748 0.013173866 0.002463348 0.006613420 0.006362237
 [373] 0.005191235 0.004534736 0.002601141 0.004641118 0.007616884 0.007616884
 [379] 0.002837924 0.002837924 0.002403690 0.002352479 0.006345057 0.002352479
 [385] 0.032582313 0.010894224 0.003843658 0.015413122 0.005222587 0.013850834
 [391] 0.002352479 0.015453503 0.005276052 0.005134791 0.010894224 0.010894224
 [397] 0.011963928 0.010894224 0.010444850 0.008528887 0.008039888 0.009021505
 [403] 0.012163845 0.006245578 0.005096049 0.002541748 0.010894224 0.005607255
 [409] 0.007552456 0.007034064 0.003333663 0.009776645 0.011026399 0.021013236
 [415] 0.002362774 0.006991980 0.007164476 0.006065037 0.004641118 0.008528887
 [421] 0.008838557 0.002340601 0.005737937 0.006362237 0.007594859 0.012484856
 [427] 0.002463348 0.006912318 0.007592325 0.002337169 0.011957304 0.005168804
 [433] 0.033646698 0.026235307 0.011963928 0.010894224 0.006991980 0.005191235
 [439] 0.002541748 0.002837924 0.007592325 0.009166204 0.007768811 0.019163075
 [445] 0.033197605 0.005148940 0.005125845 0.002352479 0.003042767 0.002340601
 [451] 0.002352479 0.004356556 0.005175567 0.004973780 0.010327659 0.002889399
 [457] 0.004944421 0.007592325 0.002510862 0.007157827 0.002889399 0.004534736
 [463] 0.007592325 0.006345354 0.009798160 0.027736707 0.024481800 0.011963928
 [469] 0.002601141 0.005696542 0.002439326 0.010097540 0.005158606 0.002889399
 [475] 0.009693527 0.002984428 0.008869857 0.002439326 0.005441478 0.003757866
 [481] 0.003214876 0.005293246 0.006498998 0.005276052 0.005121957 0.002403690
 [487] 0.008827158 0.002510862 0.028417425 0.010862136 0.010894224 0.002541748
 [493] 0.006362237 0.018644724 0.005208306 0.002984428 0.031945235 0.024481800
 [499] 0.010020765 0.008444309 0.003757866 0.006080983 0.002601141 0.002710161
 [505] 0.002510862 0.005079416 0.010894224 0.006280619 0.005127648 0.007592325
 [511] 0.005127648 0.002463348 0.005848877 0.002710161 0.003214876 0.002710161
 [517] 0.003875631 0.005146359 0.008444309 0.002984428 0.005208306 0.005276748
 [523] 0.006469953 0.014734225 0.003042767 0.005115432 0.006410926 0.007217699
 [529] 0.005115432 0.009630894 0.005848877 0.005132249 0.006644234 0.007034064
 [535] 0.027736707 0.021264885 0.010894224 0.033984602 0.020170908 0.011963928
 [541] 0.010894224 0.007592325 0.008803201 0.005363932 0.012308595 0.003405728
 [547] 0.011963928 0.005938866 0.004872828 0.007266584 0.009228074 0.010097540
 [553] 0.006736118 0.002352479 0.002601141 0.015822134 0.031945235 0.005502815
 [559] 0.009110406 0.002601141 0.003536394 0.002837924 0.002710161 0.002463348
 [565] 0.003998081 0.002340601 0.008624204 0.023088199 0.028683036 0.028683036
 [571] 0.025826021 0.028683036 0.028683036 0.028683036 0.011963928 0.009011481
 [577] 0.002601141 0.017266066 0.003536394 0.002601141 0.006893482 0.015836517
 [583] 0.002837924 0.002463348 0.023088199 0.023088199 0.045566605 0.023088199
 [589] 0.039375881 0.011963928 0.009519634 0.010894224 0.006912318 0.003333663
 [595] 0.002984428 0.013253497 0.002352479 0.002984428 0.008555300 0.003536394
 [601] 0.006349098 0.018745469 0.036159802 0.036159802 0.020292844 0.010894224
 [607] 0.006736118 0.003042767 0.002601141 0.010097540 0.012163845 0.012668599
 [613] 0.012184767 0.003149675 0.003757866 0.002601141 0.003149675 0.003536394
 [619] 0.008797985 0.003333663 0.003998081 0.002601141 0.007051171 0.012754646
 [625] 0.005181020 0.011999189 0.003333663 0.005900089 0.012736086 0.006469953
 [631] 0.007407921 0.003149675 0.002463348 0.012973707 0.009886162 0.003757866
 [637] 0.013062285 0.012601100 0.012229617 0.003998081 0.002754773 0.004257037
 [643] 0.004257037 0.012601100 0.003333663 0.003333663 0.002439326 0.002837924
 [649] 0.007266584 0.012990238 0.002439326 0.002837924 0.003333663 0.008797985
 [655] 0.002386532 0.006759487 0.008356226 0.003536394 0.010576520 0.002837924
 [661] 0.002541748 0.002837924 0.002337169 0.002337169 0.005900089 0.012229617
 [667] 0.007592325 0.003615322 0.002463348 0.002510862 0.003757866 0.002352479
 [673] 0.011781432 0.024481800 0.010894224 0.007592325 0.003757866 0.005582043
 [679] 0.005317100 0.004257037 0.003064709 0.010435712 0.012484856 0.003757866
 [685] 0.005127648 0.008869857 0.011963928 0.005117464 0.011952523 0.002510862
 [691] 0.002710161 0.008528887 0.003149675 0.009021505 0.009940717 0.012121784
 [697] 0.007036115 0.008827158 0.004534736 0.033197605 0.037132184 0.011963928
 [703] 0.010894224 0.002710161 0.003149675 0.002541748 0.006498998 0.004257037
 [709] 0.003405728 0.003615322 0.002340601 0.010327659 0.005127648 0.012308595
 [715] 0.005737937 0.002362774 0.007592325 0.009364483 0.007217699 0.007950371
 [721] 0.003998081 0.004534736 0.004090736 0.011963928 0.005853406 0.006029012
 [727] 0.004641118 0.026204360 0.003126479 0.003126479 0.003998081 0.002601141
 [733] 0.015220999 0.015220999 0.009821294 0.011963928 0.017266066 0.002710161
 [739] 0.003149675 0.007266584 0.015552639 0.005123271 0.003214876 0.004899238
 [745] 0.002754773 0.038497738 0.038497738 0.038497738 0.044190141 0.044190141
 [751] 0.038497738 0.011963928 0.017266066 0.005966785 0.002340601 0.003536394
 [757] 0.008343378 0.008134451 0.003757866 0.012308595 0.013253497 0.006547723
 [763] 0.007594859 0.003536394 0.002908833 0.008923527 0.006759487 0.003333663
 [769] 0.008388177 0.002710161 0.006204359 0.009011481 0.013062285 0.005363932
 [775] 0.012387354 0.005900089 0.002439326 0.012180975 0.028417425 0.005232760
 [781] 0.003615322 0.002439326 0.005276748 0.003405728 0.002352479 0.014734225
 [787] 0.014847985 0.008869857 0.009886162 0.003536394 0.004944421 0.008640158
 [793] 0.002403690 0.009110406 0.003149675 0.002362774 0.002337169 0.002386532
 [799] 0.021552086 0.032481486 0.005266467 0.002362774 0.003757866 0.010894224
 [805] 0.002984428 0.008797985 0.002510862 0.015460369 0.015300409 0.008797985
 [811] 0.004257037 0.003333663 0.002352479 0.009886162 0.002362774 0.003149675
 [817] 0.021264885 0.010881080 0.003875631 0.002431176 0.003843658 0.016687392
 [823] 0.008294185 0.023034733 0.018030683 0.005037673 0.013598416 0.005772631
 [829] 0.017266066 0.009228074 0.012990238 0.005900089 0.009110406 0.002386532
 [835] 0.002386532 0.003149675 0.009693527 0.002340601 0.002431176 0.002541748
 [841] 0.002889399 0.002837924 0.012248577 0.014984041 0.006450345 0.014704151
 [847] 0.013624959 0.002439326 0.006410926 0.014781734 0.003432686 0.009011481
 [853] 0.005966785 0.005737937 0.008797985 0.009364483 0.003149675 0.002386532
 [859] 0.012253491 0.002463348 0.002362774 0.007373145 0.012679208 0.007046220
 [865] 0.015639072 0.007592325 0.009886162 0.002837924 0.003333663 0.002439326
 [871] 0.002710161 0.016668242 0.005000615 0.002403690 0.005594526 0.003998081
 [877] 0.003149675 0.007373145 0.033646698 0.011429649 0.005428273 0.002362774
 [883] 0.014800364 0.009798160 0.012195925 0.002439326 0.006736118 0.005363932
 [889] 0.003333663 0.003214876 0.009286256 0.003333663 0.002410586 0.005900089
 [895] 0.007592325 0.002984428 0.005900089 0.011781432 0.002439326 0.005239689
 [901] 0.012282051 0.002439326 0.008797985 0.003536394 0.012387354 0.012736086
 [907] 0.003536394 0.004534736 0.005115432 0.012245706 0.011773651 0.018198928
 [913] 0.017813362 0.017266066 0.023447722 0.022817686 0.023331002 0.022188904
 [919] 0.022295835 0.017266066 0.003333663 0.003757866 0.002340601 0.007822697
 [925] 0.013359360 0.017266066 0.003333663 0.002710161 0.003149675 0.012630619
 [931] 0.002837924 0.012180975 0.003757866 0.006893482 0.013062285 0.008797985
 [937] 0.004257037 0.002837924 0.002754773 0.003333663 0.022565922 0.023111619
 [943] 0.022817686 0.023331002 0.022729079 0.017266066 0.012484856 0.002463348
 [949] 0.009166204 0.017719872 0.013476545 0.005772631 0.017266066 0.005607255
 [955] 0.004534736 0.002710161 0.002819743 0.119830700 0.002837924 0.006080983
 [961] 0.002889399 0.032481486 0.010894224 0.021264885 0.009228074 0.003536394
 [967] 0.002771700 0.008869857 0.003149675 0.003042767 0.003333663 0.006736118
 [973] 0.013529385 0.013529385 0.019026655 0.019026655 0.011963928 0.017266066
 [979] 0.003757866 0.002352479 0.002340601 0.002362774 0.005737937 0.003333663
 [985] 0.007592325 0.003757866 0.012484856 0.008803201 0.002510862 0.013476545
 [991] 0.011957161 0.011130469 0.010197281 0.002710161 0.007592325 0.010710424
 [997] 0.002837924 0.009228074 0.002403690 0.033555247 0.005665956 0.002340601
[1003] 0.002342481 0.003843658 0.009228074 0.014714111 0.009074434 0.010894224
[1009] 0.002541748 0.006736118 0.010444850 0.006381420 0.011963928 0.017266066
[1015] 0.005119907 0.011966485 0.002362774 0.002439326 0.002439326 0.004641118
[1021] 0.017260659 0.015550914 0.010217375 0.014731610 0.009693527 0.003536394
[1027] 0.013939585 0.003149675 0.003149675 0.002349345 0.005554695 0.005966785
[1033] 0.008356226 0.007616884 0.008894797 0.002410586 0.003333663 0.002510862
[1039] 0.002541748 0.006644234 0.009470932 0.004221303 0.016675168 0.002553659
[1045] 0.002510862 0.002386532

$pmethod
[1] "backward"

$nprune
NULL

$penalty
[1] 3

$nk
[1] 21

$thresh
[1] 0.001

$termcond
[1] 7

$weights
NULL

$glm.list
$glm.list[[1]]

Call:  glm(formula = yarg ~ ., family = family, data = bx.data.frame, 
    weights = weights, na.action = na.action, offset = offset, 
    control = control, model = TRUE, method = "glm.fit", x = TRUE, 
    y = TRUE, contrasts = NULL, trace = (trace >= 2))

Coefficients:
            (Intercept)                 survived             `h(sibsp-1)`  
               -2.66307                  2.84789                 -0.52880  
           `h(2-parch)`     `survived*h(16-age)`       `survived*sexmale`  
                1.25519                 -0.17825                 -1.25498  
                sexmale   `h(55-age)*h(2-parch)`  `h(1-sibsp)*h(1-parch)`  
                1.42483                 -0.04946                 -1.02163  

Degrees of Freedom: 1045 Total (i.e. Null);  1037 Residual
Null Deviance:	    1223 
Residual Deviance: 894.8 	AIC: 912.8

$glm.list[[2]]

Call:  glm(formula = yarg ~ ., family = family, data = bx.data.frame, 
    weights = weights, na.action = na.action, offset = offset, 
    control = control, model = TRUE, method = "glm.fit", x = TRUE, 
    y = TRUE, contrasts = NULL, trace = (trace >= 2))

Coefficients:
            (Intercept)                 survived             `h(sibsp-1)`  
             -1.9313615                1.0641827               -0.6492895  
           `h(2-parch)`     `survived*h(16-age)`       `survived*sexmale`  
              0.0653459                0.0939009               -1.9509922  
                sexmale   `h(55-age)*h(2-parch)`  `h(1-sibsp)*h(1-parch)`  
              0.9659886                0.0004374               -0.2190244  

Degrees of Freedom: 1045 Total (i.e. Null);  1037 Residual
Null Deviance:	    1175 
Residual Deviance: 1127 	AIC: 1145

$glm.list[[3]]

Call:  glm(formula = yarg ~ ., family = family, data = bx.data.frame, 
    weights = weights, na.action = na.action, offset = offset, 
    control = control, model = TRUE, method = "glm.fit", x = TRUE, 
    y = TRUE, contrasts = NULL, trace = (trace >= 2))

Coefficients:
            (Intercept)                 survived             `h(sibsp-1)`  
                1.37993                 -2.84379                  0.79975  
           `h(2-parch)`     `survived*h(16-age)`       `survived*sexmale`  
               -1.29856                  0.02012                  2.28554  
                sexmale   `h(55-age)*h(2-parch)`  `h(1-sibsp)*h(1-parch)`  
               -1.45240                  0.04146                  1.12491  

Degrees of Freedom: 1045 Total (i.e. Null);  1037 Residual
Null Deviance:	    1448 
Residual Deviance: 1119 	AIC: 1137


$glm.coefficients
                              1st          2nd         3rd
(Intercept)           -2.66307135 -1.931361472  1.37992944
survived               2.84788552  1.064182711 -2.84378575
h(sibsp-1)            -0.52879762 -0.649289486  0.79974678
h(2-parch)             1.25518755  0.065345867 -1.29855706
survived*h(16-age)    -0.17824991  0.093900852  0.02011681
survived*sexmale      -1.25498201 -1.950992216  2.28554497
sexmale                1.42483431  0.965988623 -1.45239590
h(55-age)*h(2-parch)  -0.04946408  0.000437374  0.04146455
h(1-sibsp)*h(1-parch) -1.02162885 -0.219024356  1.12490799

$glm.stats
     nulldev   df       dev   df  devratio       AIC iters converged
1st 1223.308 1045  894.8141 1037 0.2685294  912.8141     5         1
2nd 1175.305 1045 1126.9441 1037 0.0411477 1144.9441     5         1
3rd 1448.212 1045 1118.9411 1037 0.2273640 1136.9411     5         1

$call
earth(formula = pclass ~ ., data = etitanic, trace = 0, glm = list(family = "binomial"), 
    degree = 2)

$namesx.org
[1] "survived" "sex"      "age"      "sibsp"    "parch"   

$namesx
[1] "survived" "sex"      "age"      "sibsp"    "parch"   

$terms
pclass ~ survived + sex + age + sibsp + parch
attr(,"variables")
list(pclass, survived, sex, age, sibsp, parch)
attr(,"factors")
         survived sex age sibsp parch
pclass          0   0   0     0     0
survived        1   0   0     0     0
sex             0   1   0     0     0
age             0   0   1     0     0
sibsp           0   0   0     1     0
parch           0   0   0     0     1
attr(,"term.labels")
[1] "survived" "sex"      "age"      "sibsp"    "parch"   
attr(,"order")
[1] 1 1 1 1 1
attr(,"intercept")
[1] 1
attr(,"response")
[1] 1
attr(,".Environment")
<environment: R_GlobalEnv>
attr(,"predvars")
list(pclass, survived, sex, age, sibsp, parch)
attr(,"dataClasses")
   pclass  survived       sex       age     sibsp     parch 
 "factor" "numeric"  "factor" "numeric" "numeric" "numeric" 

$xlevels
$xlevels$sex
[1] "female" "male"  


$levels
[1] "1st" "2nd" "3rd"

attr(,"class")
[1] "earth"
-------------------------------------------------------------------------------

> # variance models are not supported for multiple response models
> expect.err(try(earth(pclass ~ ., data=etitanic, ncross=3, nfold=3, varmod.method="lm")), "variance models are not supported for multiple response models")
Error : variance models are not supported for multiple response models
Got error as expected from try(earth(pclass ~ ., data = etitanic, ncross = 3, nfold = 3,     varmod.method = "lm"))
> 
> a5d <- earth(pclass ~ .-age, data=etitanic, degree=2, glm=list(family="binomial"), trace=0)
> a5update <- update(a5, form=pclass ~ .-age)
> check.models.equal(a5update, a5d, msg="a5update a5d", newdata=etitanic[5,])
a5update a5d: models not identical

Formulas differ: pclass ~ survived + sex + sibsp + parch
and:             pclass ~ (survived + sex + age + sibsp + parch) - age

a5update a5d: glm submodel formula strings are identical: yarg ~ survived + `h(sibsp-1)` + `survived*sexmale` + sexmale +     `h(1-sibsp)*h(1-parch)` + `survived*h(1-parch)`
a5update a5d: but the actual glm submodel formulas differ (classes are "formula" and "formula")
a5update a5d: glm submodels not identical (but coefs, residuals, fitted.values are the same)
a5update a5d: Models are equivalent, within numerical tolerances

> 
> a5d <- earth(pclass ~ .-age, data=etitanic, degree=2, glm=list(family="binomial"), trace=0, keepxy=1)
> a5update <- update(a5, form=pclass ~ .-age)
> check.models.equal(a5update, a5d, msg="a5update a5d with keepxy", newdata=etitanic[5,])
a5update a5d with keepxy: models not identical

Formulas differ: pclass ~ survived + sex + sibsp + parch
and:             pclass ~ (survived + sex + age + sibsp + parch) - age

a5update a5d with keepxy: glm submodel formula strings are identical: yarg ~ survived + `h(sibsp-1)` + `survived*sexmale` + sexmale +     `h(1-sibsp)*h(1-parch)` + `survived*h(1-parch)`
a5update a5d with keepxy: but the actual glm submodel formulas differ (classes are "formula" and "formula")
a5update a5d with keepxy: glm submodels not identical (but coefs, residuals, fitted.values are the same)
a5update a5d with keepxy: Models are equivalent, within numerical tolerances

> 
> # titanic data, one logical response
> cat("a6: titanic data, one logical response\n\n")
a6: titanic data, one logical response

> pclass1 = (etitanic[,1] == "1st")
> a6 <- earth(pclass1 ~ ., data=etitanic[,-1], degree=2, glm=list(family="binomial"), trace=1)
x[1046,5] with colnames survived sexmale age sibsp parch
y[1046,1] with colname pclass1, and values 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,...
Forward pass term 1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20
Reached nk 21
After forward pass GRSq 0.253 RSq 0.309
Prune backward penalty 3 nprune null: selected 8 of 17 terms, and 4 of 5 preds
After pruning pass GRSq 0.27 RSq 0.294
GLM pclass1 devratio 0.26 dof 1038/1045 iters 5
> show.earth.models(a6)

Print a6 

GLM (family binomial, link logit):
 nulldev   df       dev   df   devratio     AIC iters converged
 1223.31 1045   902.306 1038      0.262   918.3     5         1

Earth selected 8 of 17 terms, and 4 of 5 predictors
Termination condition: Reached nk 21
Importance: age, survived, parch, sibsp, sexmale-unused
Number of terms at each degree of interaction: 1 3 4
Earth GCV 0.1446768    RSS 146.0263    GRSq 0.2699404    RSq 0.2941874

Summary a6 

Call: earth(formula=pclass1~., data=etitanic[,-1], trace=1,
            glm=list(family="binomial"), degree=2)

GLM coefficients
                            pclass1
(Intercept)             -2.25778086
survived                 1.88576461
h(age-44)                0.20634617
h(2-parch)               1.24353020
survived * h(52-age)    -0.01132281
h(48-age) * h(2-parch)  -0.04760841
h(age-48) * h(2-parch)  -0.11771604
h(1-sibsp) * h(1-parch) -0.87090239

GLM (family binomial, link logit):
 nulldev   df       dev   df   devratio     AIC iters converged
 1223.31 1045   902.306 1038      0.262   918.3     5         1

Earth selected 8 of 17 terms, and 4 of 5 predictors
Termination condition: Reached nk 21
Importance: age, survived, parch, sibsp, sexmale-unused
Number of terms at each degree of interaction: 1 3 4
Earth GCV 0.1446768    RSS 146.0263    GRSq 0.2699404    RSq 0.2941874

Summary a6 digits=3, details=TRUE

Call: earth(formula=pclass1~., data=etitanic[,-1], trace=1,
            glm=list(family="binomial"), degree=2)

Earth coefficients
                        pclass1
(Intercept)              0.1112
survived                 0.3690
survived * h(52-age)    -0.0053
h(2-parch)               0.1793
h(age-48) * h(2-parch)  -0.0203
h(48-age) * h(2-parch)  -0.0063
h(age-44)                0.0381
h(1-sibsp) * h(1-parch) -0.1313

GLM coefficients
                        pclass1
(Intercept)             -2.2578
survived                 1.8858
survived * h(52-age)    -0.0113
h(2-parch)               1.2435
h(age-48) * h(2-parch)  -0.1177
h(48-age) * h(2-parch)  -0.0476
h(age-44)                0.2063
h(1-sibsp) * h(1-parch) -0.8709

GLM deviance residuals:
   Min      1Q  Median      3Q     Max  
-2.304  -0.644  -0.407   0.382   2.691  

GLM coefficients (family binomial, link logit)
                        Estimate Std. Error z value Pr(>|z|)
(Intercept)             -2.25778    0.27314   -8.27  < 2e-16
survived                 1.88576    0.28847    6.54  6.3e-11
survived * h(52-age)    -0.01132    0.01132   -1.00  0.31722
h(2-parch)               1.24353    0.19891    6.25  4.1e-10
h(age-48) * h(2-parch)  -0.11772    0.03372   -3.49  0.00048
h(48-age) * h(2-parch)  -0.04761    0.00663   -7.18  6.9e-13
h(age-44)                0.20635    0.05265    3.92  8.9e-05
h(1-sibsp) * h(1-parch) -0.87090    0.21192   -4.11  4.0e-05

GLM (family binomial, link logit):
 nulldev   df       dev   df   devratio     AIC iters converged
    1220 1045       902 1038       0.26     918     5         1

Earth selected 8 of 17 terms, and 4 of 5 predictors
Termination condition: Reached nk 21
Importance: age, survived, parch, sibsp, sexmale-unused
Number of terms at each degree of interaction: 1 3 4
Earth GCV 0.145    RSS 146    GRSq 0.27    RSq 0.294

evimp a6 

         nsubsets   gcv    rss
age             7 100.0  100.0
survived        6  64.6   67.2
parch           4  45.6   48.7
sibsp           2  22.7   26.4

evimp a6 trim=FALSE

               nsubsets   gcv    rss
age                   7 100.0  100.0
survived              6  64.6   67.2
parch                 4  45.6   48.7
sibsp                 2  22.7   26.4
sexmale-unused        0   0.0    0.0

glm params: epsilon 1e-08 maxit 25 trace FALSE family binomial link logit 

plotmo a6 
 plotmo grid:    survived  sex age sibsp parch
                        0 male  28     0     0
-------------------------------------------------------------------------------

> printh(a6$levels) # expect levels to be NULL
=== a6$levels
[1] FALSE  TRUE
> print.stripped.earth.model(a6, "a6")
print.stripped.earth.model(a6)
$rss
[1] 146.0263

$rsq
[1] 0.2941874

$gcv
[1] 0.1446768

$grsq
[1] 0.2699404

$dirs
                      survived sexmale age sibsp parch
(Intercept)                  0       0   0     0     0
h(age-26)                    0       0   1     0     0
h(26-age)                    0       0  -1     0     0
survived                     2       0   0     0     0
survived*h(age-52)           2       0   1     0     0
survived*h(52-age)           2       0  -1     0     0
h(parch-2)                   0       0   0     0     1
h(2-parch)                   0       0   0     0    -1
h(sibsp-1)                   0       0   0     1     0
h(1-sibsp)                   0       0   0    -1     0
h(age-48)*h(2-parch)         0       0   1     0    -1
h(48-age)*h(2-parch)         0       0  -1     0    -1
h(age-44)                    0       0   1     0     0
h(1-sibsp)*h(parch-1)        0       0   0    -1     1
h(1-sibsp)*h(1-parch)        0       0   0    -1    -1
survived*h(age-16)           2       0   1     0     0
sexmale*h(age-26)            0       2   1     0     0

$cuts
                      survived sexmale age sibsp parch
(Intercept)                  0       0   0     0     0
h(age-26)                    0       0  26     0     0
h(26-age)                    0       0  26     0     0
survived                     0       0   0     0     0
survived*h(age-52)           0       0  52     0     0
survived*h(52-age)           0       0  52     0     0
h(parch-2)                   0       0   0     0     2
h(2-parch)                   0       0   0     0     2
h(sibsp-1)                   0       0   0     1     0
h(1-sibsp)                   0       0   0     1     0
h(age-48)*h(2-parch)         0       0  48     0     2
h(48-age)*h(2-parch)         0       0  48     0     2
h(age-44)                    0       0  44     0     0
h(1-sibsp)*h(parch-1)        0       0   0     1     1
h(1-sibsp)*h(1-parch)        0       0   0     1     1
survived*h(age-16)           0       0  16     0     0
sexmale*h(age-26)            0       0  26     0     0

$selected.terms
[1]  1  4  6  8 11 12 13 15

$prune.terms
      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
 [1,]    1    0    0    0    0    0    0    0    0     0     0     0     0
 [2,]    1    2    0    0    0    0    0    0    0     0     0     0     0
 [3,]    1    4   12    0    0    0    0    0    0     0     0     0     0
 [4,]    1    2    3    4    0    0    0    0    0     0     0     0     0
 [5,]    1    2    3    4    5    0    0    0    0     0     0     0     0
 [6,]    1    4    8   11   12   13    0    0    0     0     0     0     0
 [7,]    1    4    8   11   12   13   15    0    0     0     0     0     0
 [8,]    1    4    6    8   11   12   13   15    0     0     0     0     0
 [9,]    1    4    6    8   11   12   13   15   16     0     0     0     0
[10,]    1    4    6    8   10   11   12   13   15    16     0     0     0
[11,]    1    4    6    8   10   11   12   13   14    15    16     0     0
[12,]    1    4    6    8   10   11   12   13   14    15    16    17     0
[13,]    1    4    6    8    9   10   11   12   13    14    15    16    17
[14,]    1    4    5    6    8    9   10   11   12    13    14    15    16
[15,]    1    3    4    5    6    8    9   10   11    12    13    14    15
[16,]    1    2    3    4    5    6    8    9   10    11    12    13    14
[17,]    1    2    3    4    5    6    7    8    9    10    11    12    13
      [,14] [,15] [,16] [,17]
 [1,]     0     0     0     0
 [2,]     0     0     0     0
 [3,]     0     0     0     0
 [4,]     0     0     0     0
 [5,]     0     0     0     0
 [6,]     0     0     0     0
 [7,]     0     0     0     0
 [8,]     0     0     0     0
 [9,]     0     0     0     0
[10,]     0     0     0     0
[11,]     0     0     0     0
[12,]     0     0     0     0
[13,]     0     0     0     0
[14,]    17     0     0     0
[15,]    16    17     0     0
[16,]    15    16    17     0
[17,]    14    15    16    17

$coefficients
                           pclass1
(Intercept)            0.111229445
survived               0.368959879
survived*h(52-age)    -0.005272714
h(2-parch)             0.179260948
h(age-48)*h(2-parch)  -0.020341897
h(48-age)*h(2-parch)  -0.006316595
h(age-44)              0.038123994
h(1-sibsp)*h(1-parch) -0.131302863

$rss.per.response
[1] 146.0263

$rsq.per.response
[1] 0.2941874

$gcv.per.response
[1] 0.1446768

$grsq.per.response
[1] 0.2699404

$rss.per.subset
 [1] 206.8910 173.4973 167.2214 154.2267 154.1736 150.2618 147.5346 146.0263
 [9] 145.3576 145.0403 144.4600 144.0982 143.8546 143.6294 143.3491 143.0633
[17] 142.9648

$gcv.per.subset
 [1] 0.1981713 0.1669830 0.1617175 0.1498702 0.1505432 0.1474349 0.1454625
 [8] 0.1446768 0.1447177 0.1451088 0.1452376 0.1455866 0.1460573 0.1465497
[15] 0.1469887 0.1474246 0.1480569

$leverages
   [1] 0.003717914 0.017486700 0.009079130 0.009079130 0.009079130 0.011482760
   [7] 0.027832614 0.004190842 0.012199910 0.049504115 0.013149033 0.008652007
  [13] 0.004181112 0.003866615 0.113251604 0.003888758 0.011730700 0.003956867
  [19] 0.003200293 0.005382715 0.008585463 0.003866615 0.007553097 0.003717914
  [25] 0.002531799 0.006412039 0.008202794 0.004583473 0.003724408 0.006896782
  [31] 0.006489270 0.003754492 0.015131693 0.005527777 0.008520378 0.003595773
  [37] 0.005043645 0.011958601 0.008789215 0.018409717 0.018768659 0.006999647
  [43] 0.006896782 0.007553097 0.010661926 0.005051158 0.022533846 0.002556130
  [49] 0.002252269 0.004970653 0.010927470 0.009699422 0.010831477 0.010831477
  [55] 0.010685351 0.007061468 0.087645749 0.011586773 0.011603271 0.006159702
  [61] 0.006436433 0.004878488 0.003754492 0.008520378 0.006063996 0.006264334
  [67] 0.004667899 0.009570331 0.006136868 0.004210022 0.128951415 0.013213240
  [73] 0.059135967 0.010831477 0.036825827 0.008086729 0.007851540 0.010302463
  [79] 0.003773975 0.004122663 0.006122444 0.008211789 0.006171899 0.009144293
  [85] 0.015238332 0.015083175 0.016361837 0.013147818 0.003432751 0.013070304
  [91] 0.013070304 0.012336549 0.004190842 0.003502475 0.005597734 0.012574499
  [97] 0.003200293 0.004878488 0.002258351 0.008002121 0.008355407 0.008005961
 [103] 0.009079130 0.133333091 0.084456314 0.003754492 0.011928492 0.010343462
 [109] 0.008046665 0.026626644 0.009891924 0.007364734 0.006873258 0.009570331
 [115] 0.004583473 0.003595773 0.007916162 0.002701951 0.012336549 0.049504115
 [121] 0.010661926 0.005721125 0.004302087 0.022533846 0.003502475 0.007916162
 [127] 0.007883058 0.006412039 0.006412039 0.013070304 0.012336549 0.010725509
 [133] 0.006873258 0.004598000 0.003773975 0.004181112 0.015205067 0.014282627
 [139] 0.005527777 0.008593024 0.004792842 0.008553321 0.011846133 0.009458375
 [145] 0.006873258 0.004583473 0.007851540 0.006873258 0.005597734 0.009676251
 [151] 0.010763630 0.007883058 0.009676251 0.002482445 0.011112903 0.008962673
 [157] 0.009758932 0.010553651 0.006021966 0.010763630 0.003754492 0.004583473
 [163] 0.005527777 0.011657378 0.004792842 0.012917519 0.002236066 0.004975902
 [169] 0.002258351 0.015131693 0.005098567 0.002258351 0.007162004 0.007794488
 [175] 0.008652007 0.004181112 0.007883058 0.008281367 0.004878488 0.006020877
 [181] 0.026237917 0.010565243 0.006436433 0.007482373 0.006104241 0.008593024
 [187] 0.009570331 0.004210022 0.006171899 0.006836667 0.065505659 0.008389965
 [193] 0.023284747 0.006021966 0.003595773 0.040297360 0.002239357 0.007302295
 [199] 0.002910589 0.006016246 0.007113590 0.008183993 0.009144293 0.003754492
 [205] 0.010560426 0.009570331 0.019112243 0.003822172 0.003157715 0.008009337
 [211] 0.002319124 0.008520378 0.004122663 0.007883058 0.003200293 0.004122663
 [217] 0.012109284 0.012574499 0.002556130 0.010071907 0.008578128 0.008124234
 [223] 0.096146027 0.017529616 0.004181112 0.006873258 0.003754492 0.004331532
 [229] 0.006489270 0.004583473 0.013147818 0.008263779 0.012551332 0.003724408
 [235] 0.009168832 0.009168832 0.006424276 0.008652007 0.006602817 0.006836667
 [241] 0.013711508 0.007916162 0.006559465 0.013542930 0.003956867 0.018170860
 [247] 0.012574499 0.010343462 0.012089471 0.023462230 0.036560237 0.024183499
 [253] 0.016010144 0.011482760 0.008578128 0.010949459 0.006136868 0.013070304
 [259] 0.008204042 0.008803154 0.006136868 0.003834143 0.004598000 0.016010144
 [265] 0.009570331 0.004583473 0.026881456 0.020369214 0.014113579 0.013618732
 [271] 0.004045543 0.011657378 0.009007450 0.018881134 0.007916162 0.008951382
 [277] 0.009079130 0.011730700 0.004975902 0.009866521 0.003719417 0.003834143
 [283] 0.018170860 0.004878488 0.006050101 0.006098142 0.002258351 0.004531091
 [289] 0.002531799 0.006570397 0.007156279 0.010008792 0.004531091 0.002910589
 [295] 0.004878488 0.002252269 0.008931303 0.006282630 0.008202794 0.002252269
 [301] 0.012565128 0.010464429 0.006197823 0.010831477 0.004331532 0.005721125
 [307] 0.002910589 0.002400135 0.005527777 0.002306958 0.004181112 0.009363802
 [313] 0.025653727 0.006559465 0.007796653 0.006265696 0.004878488 0.002531799
 [319] 0.005527777 0.007553097 0.017556581 0.003404662 0.003595773 0.004583473
 [325] 0.004130016 0.010565243 0.011788689 0.008450506 0.007364734 0.006016246
 [331] 0.003406920 0.015102299 0.006016246 0.006098142 0.002236066 0.002252269
 [337] 0.004181112 0.012487300 0.003859688 0.003848575 0.004667899 0.002258351
 [343] 0.003443328 0.008088352 0.004531091 0.017529616 0.003724408 0.002418383
 [349] 0.004970653 0.006016246 0.006602817 0.002531799 0.004531091 0.004272432
 [355] 0.004479085 0.008281367 0.012487300 0.004766567 0.004479085 0.006159702
 [361] 0.006104241 0.002910589 0.003443328 0.004531091 0.008505457 0.006079655
 [367] 0.004531091 0.003200293 0.003822172 0.002947085 0.007706488 0.006570397
 [373] 0.004331532 0.005448703 0.002400135 0.009570331 0.007130942 0.007130942
 [379] 0.002701951 0.002701951 0.002732364 0.002258351 0.008450506 0.002258351
 [385] 0.012815373 0.008002121 0.006611502 0.009215697 0.003814416 0.023462230
 [391] 0.002258351 0.013080972 0.004906741 0.007916162 0.008002121 0.008002121
 [397] 0.012864724 0.017529616 0.011657378 0.006424276 0.006233274 0.007130942
 [403] 0.004288925 0.003873409 0.003931398 0.003200293 0.039535981 0.009676251
 [409] 0.010565243 0.006079655 0.003443328 0.007553097 0.024183499 0.017674534
 [415] 0.002556130 0.006638639 0.009458375 0.003439524 0.009570331 0.006424276
 [421] 0.006856899 0.002418383 0.004402969 0.006570397 0.006602817 0.003157715
 [427] 0.002947085 0.008520378 0.010008792 0.002319124 0.003832343 0.003834976
 [433] 0.017417159 0.015824305 0.009079130 0.008046665 0.006638639 0.004331532
 [439] 0.003200293 0.002701951 0.016010144 0.013147818 0.009758932 0.010008792
 [445] 0.017417159 0.003859688 0.003439524 0.002258351 0.004598000 0.002418383
 [451] 0.002258351 0.007883058 0.005801057 0.007012409 0.005721125 0.004190842
 [457] 0.011958601 0.044966037 0.002306958 0.008281367 0.004190842 0.005448703
 [463] 0.018170860 0.006303122 0.010879586 0.011834548 0.011134315 0.009079130
 [469] 0.002400135 0.004198176 0.002252269 0.005326977 0.003717914 0.004190842
 [475] 0.004667899 0.002910589 0.003717914 0.002252269 0.011730700 0.004130016
 [481] 0.005043645 0.003719417 0.005721125 0.004906741 0.003956867 0.002732364
 [487] 0.003754492 0.002306958 0.011834548 0.008088352 0.009626467 0.003200293
 [493] 0.006570397 0.006104241 0.003724408 0.002910589 0.012689867 0.011134315
 [499] 0.008002121 0.010370197 0.004130016 0.004975902 0.002400135 0.002531799
 [505] 0.002306958 0.003406920 0.008578128 0.005326977 0.003754492 0.012481166
 [511] 0.003754492 0.002947085 0.006489270 0.002531799 0.005043645 0.002531799
 [517] 0.004325743 0.006520264 0.010370197 0.002910589 0.003724408 0.003773975
 [523] 0.006016246 0.006063996 0.004598000 0.003834143 0.006050101 0.006621344
 [529] 0.003834143 0.009686194 0.006489270 0.004034381 0.006063996 0.006079655
 [535] 0.011834548 0.010464429 0.008535890 0.017486700 0.014378909 0.009079130
 [541] 0.009626467 0.029455238 0.003834143 0.003866615 0.002701951 0.005527777
 [547] 0.009079130 0.004499289 0.004749948 0.007162004 0.004002327 0.005326977
 [553] 0.006158345 0.002258351 0.002400135 0.008505457 0.012689867 0.004272432
 [559] 0.003866615 0.002400135 0.003767429 0.002701951 0.002531799 0.002947085
 [565] 0.004531091 0.002418383 0.008202794 0.009079130 0.009079130 0.009079130
 [571] 0.008803154 0.009079130 0.009079130 0.009079130 0.009079130 0.003773975
 [577] 0.002400135 0.009079130 0.003767429 0.002400135 0.006265696 0.008183993
 [583] 0.002701951 0.002947085 0.009079130 0.009079130 0.015824305 0.009079130
 [589] 0.014378909 0.009079130 0.004402969 0.011819139 0.008520378 0.003443328
 [595] 0.002910589 0.004970653 0.002258351 0.002910589 0.008990537 0.003767429
 [601] 0.006233274 0.006436433 0.012752515 0.012752515 0.009824890 0.008002121
 [607] 0.006158345 0.004598000 0.002400135 0.005326977 0.004288925 0.004641655
 [613] 0.002306958 0.003157715 0.004130016 0.002400135 0.003157715 0.003767429
 [619] 0.003956867 0.003443328 0.004531091 0.002400135 0.006128417 0.005538649
 [625] 0.004515084 0.003894023 0.003443328 0.004667899 0.003767429 0.006016246
 [631] 0.006856899 0.003157715 0.002947085 0.004325743 0.004975902 0.004130016
 [637] 0.004531091 0.003443328 0.002258351 0.004531091 0.003822172 0.004970653
 [643] 0.004970653 0.003443328 0.003443328 0.003443328 0.002252269 0.002701951
 [649] 0.007162004 0.003491989 0.002252269 0.002701951 0.003443328 0.003956867
 [655] 0.002236066 0.006145602 0.008183993 0.003767429 0.006158345 0.002701951
 [661] 0.003200293 0.002701951 0.002319124 0.002319124 0.004667899 0.002258351
 [667] 0.047202057 0.006050396 0.002947085 0.002306958 0.004130016 0.002258351
 [673] 0.007570199 0.011134315 0.010831477 0.012481166 0.004130016 0.004517463
 [679] 0.005056538 0.004970653 0.003029341 0.008520378 0.003157715 0.004130016
 [685] 0.003754492 0.003717914 0.009079130 0.003991557 0.003814416 0.002306958
 [691] 0.002531799 0.006424276 0.003157715 0.007130942 0.008611984 0.007313942
 [697] 0.007156279 0.003754492 0.005448703 0.017417159 0.018124340 0.009079130
 [703] 0.009626467 0.002531799 0.003157715 0.003200293 0.005721125 0.004970653
 [709] 0.005527777 0.006050396 0.002418383 0.005721125 0.003754492 0.002701951
 [715] 0.004402969 0.002556130 0.026237917 0.004181112 0.006621344 0.007113590
 [721] 0.004531091 0.005448703 0.006896782 0.009079130 0.004389296 0.004618904
 [727] 0.009570331 0.015761821 0.004816011 0.004816011 0.004531091 0.002400135
 [733] 0.009079130 0.009079130 0.009079130 0.009079130 0.010652784 0.002531799
 [739] 0.003157715 0.007162004 0.011930492 0.003937979 0.005043645 0.003848575
 [745] 0.003822172 0.009079130 0.009079130 0.009079130 0.009079130 0.009079130
 [751] 0.009079130 0.009079130 0.009079130 0.008931303 0.002418383 0.003767429
 [757] 0.007364734 0.006020877 0.004130016 0.002701951 0.004970653 0.006020877
 [763] 0.006602817 0.003767429 0.002801459 0.008962673 0.006145602 0.003443328
 [769] 0.010553651 0.002531799 0.008416259 0.003773975 0.004531091 0.003866615
 [775] 0.002910589 0.004667899 0.002252269 0.002252269 0.011834548 0.003595773
 [781] 0.006050396 0.002252269 0.003773975 0.005527777 0.002258351 0.006063996
 [787] 0.006265696 0.003717914 0.004975902 0.003767429 0.011958601 0.008611984
 [793] 0.002732364 0.003866615 0.003157715 0.002556130 0.002319124 0.002236066
 [799] 0.010464429 0.012565128 0.010685351 0.002556130 0.004130016 0.008211789
 [805] 0.002910589 0.003956867 0.002306958 0.007443472 0.007130942 0.003956867
 [811] 0.004970653 0.003443328 0.002258351 0.004975902 0.002556130 0.003157715
 [817] 0.010464429 0.006136868 0.004325743 0.002834913 0.006611502 0.006856899
 [823] 0.006145602 0.015083175 0.003579970 0.003404662 0.007303799 0.004288925
 [829] 0.009079130 0.004002327 0.003491989 0.004667899 0.003866615 0.002236066
 [835] 0.002236066 0.003157715 0.004667899 0.002418383 0.002834913 0.003200293
 [841] 0.004190842 0.002701951 0.002531799 0.006896782 0.007061468 0.006050101
 [847] 0.007796653 0.002252269 0.006050101 0.006145602 0.003600568 0.003773975
 [853] 0.008931303 0.004402969 0.003956867 0.004181112 0.003157715 0.002236066
 [859] 0.002283927 0.002947085 0.002556130 0.007728443 0.002947085 0.006424276
 [865] 0.007794488 0.008847909 0.004975902 0.002701951 0.003443328 0.002252269
 [871] 0.002531799 0.009215697 0.003432751 0.002732364 0.004181112 0.004531091
 [877] 0.003157715 0.007728443 0.017417159 0.003873409 0.004057747 0.002556130
 [883] 0.012251812 0.010879586 0.002236066 0.002252269 0.006158345 0.003866615
 [889] 0.003443328 0.005043645 0.006021966 0.003443328 0.002239357 0.004667899
 [895] 0.016010144 0.002910589 0.004667899 0.007570199 0.002252269 0.004766567
 [901] 0.002319124 0.002252269 0.003956867 0.003767429 0.002910589 0.003767429
 [907] 0.003767429 0.005448703 0.003834143 0.007049479 0.006128417 0.006804780
 [913] 0.005725617 0.009079130 0.007303799 0.005922206 0.007049479 0.004499289
 [919] 0.004748140 0.009079130 0.003443328 0.004130016 0.002418383 0.007368882
 [925] 0.006804780 0.009079130 0.003443328 0.002531799 0.003157715 0.006412039
 [931] 0.002701951 0.002252269 0.004130016 0.006265696 0.004531091 0.003956867
 [937] 0.004970653 0.002701951 0.003822172 0.003443328 0.005361304 0.006569704
 [943] 0.005922206 0.007049479 0.005725617 0.009079130 0.003157715 0.002947085
 [949] 0.013147818 0.013149033 0.007049479 0.004288925 0.009079130 0.009676251
 [955] 0.005448703 0.002531799 0.004001696 0.009079130 0.002701951 0.004975902
 [961] 0.004190842 0.012565128 0.008002121 0.010464429 0.004002327 0.003767429
 [967] 0.002612064 0.003717914 0.003157715 0.004598000 0.003443328 0.006158345
 [973] 0.009079130 0.009079130 0.009079130 0.009079130 0.009079130 0.008381427
 [979] 0.004130016 0.002258351 0.002418383 0.002556130 0.004402969 0.003443328
 [985] 0.015028843 0.004130016 0.003157715 0.003834143 0.002306958 0.007049479
 [991] 0.003819885 0.007162004 0.008789215 0.002531799 0.064703256 0.008337954
 [997] 0.002701951 0.004002327 0.002732364 0.013005288 0.004792842 0.002418383
[1003] 0.002283927 0.006611502 0.004002327 0.008636851 0.007570199 0.008535890
[1009] 0.003200293 0.006158345 0.026205242 0.005113327 0.009079130 0.009079130
[1015] 0.004127579 0.003834976 0.002556130 0.002252269 0.002252269 0.009570331
[1021] 0.008183993 0.006122444 0.009078463 0.006122444 0.004667899 0.003767429
[1027] 0.006520264 0.003157715 0.003157715 0.002482445 0.005597734 0.008931303
[1033] 0.008183993 0.007130942 0.011603271 0.002239357 0.003443328 0.002306958
[1039] 0.003200293 0.006063996 0.010258083 0.007302295 0.009850345 0.002348736
[1045] 0.002306958 0.002236066

$pmethod
[1] "backward"

$nprune
NULL

$penalty
[1] 3

$nk
[1] 21

$thresh
[1] 0.001

$termcond
[1] 7

$weights
NULL

$glm.list
$glm.list[[1]]

Call:  glm(formula = yarg ~ ., family = family, data = bx.data.frame, 
    weights = weights, na.action = na.action, offset = offset, 
    control = control, model = TRUE, method = "glm.fit", x = TRUE, 
    y = TRUE, contrasts = NULL, trace = (trace >= 2))

Coefficients:
            (Intercept)                 survived     `survived*h(52-age)`  
               -2.25778                  1.88576                 -0.01132  
           `h(2-parch)`   `h(age-48)*h(2-parch)`   `h(48-age)*h(2-parch)`  
                1.24353                 -0.11772                 -0.04761  
            `h(age-44)`  `h(1-sibsp)*h(1-parch)`  
                0.20635                 -0.87090  

Degrees of Freedom: 1045 Total (i.e. Null);  1038 Residual
Null Deviance:	    1223 
Residual Deviance: 902.3 	AIC: 918.3


$glm.coefficients
                          pclass1
(Intercept)           -2.25778086
survived               1.88576461
survived*h(52-age)    -0.01132281
h(2-parch)             1.24353020
h(age-48)*h(2-parch)  -0.11771604
h(48-age)*h(2-parch)  -0.04760841
h(age-44)              0.20634617
h(1-sibsp)*h(1-parch) -0.87090239

$glm.stats
  nulldev   df      dev   df  devratio      AIC iters converged
 1223.308 1045 902.3064 1038 0.2624048 918.3064     5         1

$call
earth(formula = pclass1 ~ ., data = etitanic[, -1], trace = 1, 
    glm = list(family = "binomial"), degree = 2)

$namesx.org
[1] "survived" "sex"      "age"      "sibsp"    "parch"   

$namesx
[1] "survived" "sex"      "age"      "sibsp"    "parch"   

$terms
pclass1 ~ survived + sex + age + sibsp + parch
attr(,"variables")
list(pclass1, survived, sex, age, sibsp, parch)
attr(,"factors")
         survived sex age sibsp parch
pclass1         0   0   0     0     0
survived        1   0   0     0     0
sex             0   1   0     0     0
age             0   0   1     0     0
sibsp           0   0   0     1     0
parch           0   0   0     0     1
attr(,"term.labels")
[1] "survived" "sex"      "age"      "sibsp"    "parch"   
attr(,"order")
[1] 1 1 1 1 1
attr(,"intercept")
[1] 1
attr(,"response")
[1] 1
attr(,".Environment")
<environment: R_GlobalEnv>
attr(,"predvars")
list(pclass1, survived, sex, age, sibsp, parch)
attr(,"dataClasses")
  pclass1  survived       sex       age     sibsp     parch 
"logical" "numeric"  "factor" "numeric" "numeric" "numeric" 

$xlevels
$xlevels$sex
[1] "female" "male"  


$levels
[1] FALSE  TRUE

attr(,"class")
[1] "earth"
-------------------------------------------------------------------------------

> 
> # titanic data, one response which is a two level factor
> cat("a7: titanic data, one response which is a two level factor\n\n")
a7: titanic data, one response which is a two level factor

> a7 <- earth(sex ~ ., data=etitanic, degree=2, glm=list(family="binomial"), trace=1)
x[1046,6] with colnames pclass2nd pclass3rd survived age sibsp parch
y[1046,1] with colname male, and values 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,...
Forward pass term 1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20
Reached nk 21
After forward pass GRSq 0.340 RSq 0.384
Prune backward penalty 3 nprune null: selected 10 of 15 terms, and 6 of 6 preds
After pruning pass GRSq 0.352 RSq 0.38
GLM male devratio 0.32 dof 1036/1045 iters 5
> show.earth.models(a7, nresponse=1)

Print a7 

GLM (family binomial, link logit):
 nulldev   df       dev   df   devratio     AIC iters converged
 1379.57 1045   941.167 1036      0.318   961.2     5         1

Earth selected 10 of 15 terms, and 6 of 6 predictors
Termination condition: Reached nk 21
Importance: survived, parch, age, pclass3rd, sibsp, pclass2nd
Number of terms at each degree of interaction: 1 1 8
Earth GCV 0.1513968    RSS 151.3254    GRSq 0.3524225    RSq 0.3800084

Summary a7 

Call: earth(formula=sex~., data=etitanic, trace=1, glm=list(family="binomial"),
            degree=2)

GLM coefficients
                              male
(Intercept)              1.6414456
pclass3rd               -2.9192836
pclass2nd * survived    -0.9900858
pclass3rd * survived     1.2824017
pclass3rd * h(4-parch)   0.5357947
survived * h(age-15)     0.9421209
survived * h(age-11.5)  -0.9446345
h(25-age) * h(4-parch)  -0.0267240
h(2-sibsp) * h(4-parch)  0.1645457
h(sibsp-2) * h(4-parch)  0.3810006

GLM (family binomial, link logit):
 nulldev   df       dev   df   devratio     AIC iters converged
 1379.57 1045   941.167 1036      0.318   961.2     5         1

Earth selected 10 of 15 terms, and 6 of 6 predictors
Termination condition: Reached nk 21
Importance: survived, parch, age, pclass3rd, sibsp, pclass2nd
Number of terms at each degree of interaction: 1 1 8
Earth GCV 0.1513968    RSS 151.3254    GRSq 0.3524225    RSq 0.3800084

Summary a7 decomp="none", digits=5, fixed.point=FALSE, details=TRUE

Call: earth(formula=sex~., data=etitanic, trace=1, glm=list(family="binomial"),
            degree=2)

Earth coefficients
                              male
(Intercept)              0.7868343
survived * h(age-15)     0.1722326
pclass3rd * survived     0.2100380
h(25-age) * h(4-parch)  -0.0045394
h(sibsp-2) * h(4-parch)  0.0651053
h(2-sibsp) * h(4-parch)  0.0243171
pclass3rd               -0.5470414
pclass3rd * h(4-parch)   0.1182762
pclass2nd * survived    -0.1638962
survived * h(age-11.5)  -0.1724967

GLM coefficients
                             male
(Intercept)              1.641446
survived * h(age-15)     0.942121
pclass3rd * survived     1.282402
h(25-age) * h(4-parch)  -0.026724
h(sibsp-2) * h(4-parch)  0.381001
h(2-sibsp) * h(4-parch)  0.164546
pclass3rd               -2.919284
pclass3rd * h(4-parch)   0.535795
pclass2nd * survived    -0.990086
survived * h(age-11.5)  -0.944635

GLM deviance residuals:
     Min        1Q    Median        3Q       Max  
-2.45293  -0.71226   0.37332   0.56500   2.14246  

GLM coefficients (family binomial, link logit)
                          Estimate Std. Error  z value  Pr(>|z|)
(Intercept)              1.6414456  0.3063579   5.3579 8.418e-08
survived * h(age-15)     0.9421209  0.0996551   9.4538 < 2.2e-16
pclass3rd * survived     1.2824017  0.3265418   3.9272 8.593e-05
h(25-age) * h(4-parch)  -0.0267240  0.0054184  -4.9321 8.136e-07
h(sibsp-2) * h(4-parch)  0.3810006  0.0944226   4.0351 5.459e-05
h(2-sibsp) * h(4-parch)  0.1645457  0.0382249   4.3047 1.672e-05
pclass3rd               -2.9192836  0.6046060  -4.8284 1.376e-06
pclass3rd * h(4-parch)   0.5357947  0.1546537   3.4645 0.0005313
pclass2nd * survived    -0.9900858  0.2985006  -3.3169 0.0009103
survived * h(age-11.5)  -0.9446345  0.0928577 -10.1729 < 2.2e-16

GLM (family binomial, link logit):
 nulldev   df       dev   df   devratio     AIC iters converged
    1380 1045     941.2 1036       0.32     961     5         1

Earth selected 10 of 15 terms, and 6 of 6 predictors
Termination condition: Reached nk 21
Importance: survived, parch, age, pclass3rd, sibsp, pclass2nd
Number of terms at each degree of interaction: 1 1 8
Earth GCV 0.1514    RSS 151.33    GRSq 0.35242    RSq 0.38001

evimp a7 

          nsubsets   gcv    rss
survived         9 100.0  100.0
parch            8  43.4   48.8
age              6  36.5   41.2
pclass3rd        5  36.6   40.2
sibsp            3  24.4   27.9
pclass2nd        1  12.1   14.5

evimp a7 trim=FALSE

          nsubsets   gcv    rss
survived         9 100.0  100.0
parch            8  43.4   48.8
age              6  36.5   41.2
pclass3rd        5  36.6   40.2
sibsp            3  24.4   27.9
pclass2nd        1  12.1   14.5

glm params: epsilon 1e-08 maxit 25 trace FALSE family binomial link logit 

plotmo a7 
 plotmo grid:    pclass survived age sibsp parch
                    3rd        0  28     0     0
-------------------------------------------------------------------------------

> printh(a7$levels)
=== a7$levels
[1] "female" "male"  
> print.stripped.earth.model(a7, "a7")
print.stripped.earth.model(a7)
$rss
[1] 151.3254

$rsq
[1] 0.3800084

$gcv
[1] 0.1513968

$grsq
[1] 0.3524225

$dirs
                      pclass2nd pclass3rd survived age sibsp parch
(Intercept)                   0         0        0   0     0     0
survived                      0         0        2   0     0     0
h(parch-4)                    0         0        0   0     0     1
h(4-parch)                    0         0        0   0     0    -1
survived*h(age-15)            0         0        2   1     0     0
survived*h(15-age)            0         0        2  -1     0     0
pclass3rd*survived            0         2        2   0     0     0
h(age-25)*h(4-parch)          0         0        0   1     0    -1
h(25-age)*h(4-parch)          0         0        0  -1     0    -1
h(sibsp-2)*h(4-parch)         0         0        0   0     1    -1
h(2-sibsp)*h(4-parch)         0         0        0   0    -1    -1
pclass3rd                     0         2        0   0     0     0
pclass3rd*h(4-parch)          0         2        0   0     0    -1
pclass2nd*survived            2         0        2   0     0     0
survived*h(age-11.5)          0         0        2   1     0     0

$cuts
                      pclass2nd pclass3rd survived  age sibsp parch
(Intercept)                   0         0        0  0.0     0     0
survived                      0         0        0  0.0     0     0
h(parch-4)                    0         0        0  0.0     0     4
h(4-parch)                    0         0        0  0.0     0     4
survived*h(age-15)            0         0        0 15.0     0     0
survived*h(15-age)            0         0        0 15.0     0     0
pclass3rd*survived            0         0        0  0.0     0     0
h(age-25)*h(4-parch)          0         0        0 25.0     0     4
h(25-age)*h(4-parch)          0         0        0 25.0     0     4
h(sibsp-2)*h(4-parch)         0         0        0  0.0     2     4
h(2-sibsp)*h(4-parch)         0         0        0  0.0     2     4
pclass3rd                     0         0        0  0.0     0     0
pclass3rd*h(4-parch)          0         0        0  0.0     0     4
pclass2nd*survived            0         0        0  0.0     0     0
survived*h(age-11.5)          0         0        0 11.5     0     0

$selected.terms
 [1]  1  5  7  9 10 11 12 13 14 15

$prune.terms
      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
 [1,]    1    0    0    0    0    0    0    0    0     0     0     0     0
 [2,]    1    2    0    0    0    0    0    0    0     0     0     0     0
 [3,]    1    2    3    0    0    0    0    0    0     0     0     0     0
 [4,]    1    2    3    4    0    0    0    0    0     0     0     0     0
 [5,]    1    2    3    4    5    0    0    0    0     0     0     0     0
 [6,]    1    5    9   12   13   15    0    0    0     0     0     0     0
 [7,]    1    5    7    9   12   13   15    0    0     0     0     0     0
 [8,]    1    5    7    9   10   12   13   15    0     0     0     0     0
 [9,]    1    5    7    9   10   11   12   13   15     0     0     0     0
[10,]    1    5    7    9   10   11   12   13   14    15     0     0     0
[11,]    1    3    5    7    9   10   11   12   13    14    15     0     0
[12,]    1    2    3    5    7    9   10   11   12    13    14    15     0
[13,]    1    2    3    5    6    7    9   10   11    12    13    14    15
[14,]    1    2    3    4    5    6    7    9   10    11    12    13    14
[15,]    1    2    3    4    5    6    7    8    9    10    11    12    13
      [,14] [,15]
 [1,]     0     0
 [2,]     0     0
 [3,]     0     0
 [4,]     0     0
 [5,]     0     0
 [6,]     0     0
 [7,]     0     0
 [8,]     0     0
 [9,]     0     0
[10,]     0     0
[11,]     0     0
[12,]     0     0
[13,]     0     0
[14,]    15     0
[15,]    14    15

$coefficients
                              male
(Intercept)            0.786834343
survived*h(age-15)     0.172232564
pclass3rd*survived     0.210037978
h(25-age)*h(4-parch)  -0.004539399
h(sibsp-2)*h(4-parch)  0.065105306
h(2-sibsp)*h(4-parch)  0.024317117
pclass3rd             -0.547041393
pclass3rd*h(4-parch)   0.118276153
pclass2nd*survived    -0.163896221
survived*h(age-11.5)  -0.172496699

$rss.per.response
[1] 151.3254

$rsq.per.response
[1] 0.3800084

$gcv.per.response
[1] 0.1513968

$grsq.per.response
[1] 0.3524225

$rss.per.subset
 [1] 244.0765 173.4300 172.3216 167.0752 166.3467 162.1420 158.5482 156.2928
 [9] 153.2833 151.3254 150.8940 150.5522 150.4688 150.3932 150.3774

$gcv.per.subset
 [1] 0.2337895 0.1669182 0.1666498 0.1623556 0.1624296 0.1590915 0.1563215
 [8] 0.1548485 0.1526086 0.1513968 0.1517062 0.1521072 0.1527728 0.1534511
[15] 0.1541954

$leverages
   [1] 0.006833739 0.012041802 0.011374780 0.007810055 0.007810055 0.009159163
   [7] 0.019828087 0.004608382 0.016778909 0.004608382 0.005031322 0.015743860
  [13] 0.008925468 0.007810807 0.046315070 0.003732806 0.008895001 0.006223281
  [19] 0.004608382 0.006489974 0.008623226 0.007810807 0.006836171 0.006833739
  [25] 0.004608382 0.008233466 0.014142568 0.005979435 0.007118693 0.004608382
  [31] 0.006387716 0.006589518 0.016289582 0.004608382 0.007814361 0.009427613
  [37] 0.004608382 0.004608382 0.007447563 0.021294672 0.018204481 0.006591576
  [43] 0.004608382 0.006836171 0.012215191 0.004904418 0.014759976 0.004608382
  [49] 0.004608382 0.007396820 0.007569355 0.012301154 0.007888534 0.007888534
  [55] 0.004608382 0.005031322 0.037298175 0.005031322 0.007776859 0.007377265
  [61] 0.005786292 0.005979622 0.006589518 0.007814361 0.005031322 0.007784999
  [67] 0.010868851 0.004608382 0.006590748 0.006206750 0.020927533 0.018121225
  [73] 0.006206750 0.005540722 0.021598336 0.005031322 0.005580681 0.010870576
  [79] 0.007444383 0.006101265 0.005031322 0.009910970 0.006153678 0.017521279
  [85] 0.011858436 0.008555015 0.012540209 0.005031322 0.008430179 0.008224551
  [91] 0.008224551 0.008712978 0.004608382 0.008628148 0.006102200 0.011766133
  [97] 0.004608382 0.005979622 0.004608382 0.016832516 0.015225008 0.017200442
 [103] 0.012976847 0.012300297 0.022189870 0.006589518 0.015070945 0.006393434
 [109] 0.009937182 0.017486270 0.009060591 0.005031322 0.005581844 0.004608382
 [115] 0.005979435 0.009427613 0.006553265 0.004421263 0.008712978 0.004608382
 [121] 0.012215191 0.015104874 0.003964098 0.014759976 0.008628148 0.006553265
 [127] 0.004608382 0.008233466 0.008233466 0.008224551 0.008712978 0.005031322
 [133] 0.005581844 0.004608382 0.007444383 0.008925468 0.006206750 0.011217398
 [139] 0.004608382 0.004608382 0.016609618 0.006207121 0.009812036 0.005031322
 [145] 0.005581844 0.005979435 0.005580681 0.005581844 0.006102200 0.004608382
 [151] 0.009688899 0.004608382 0.004608382 0.004608382 0.004608382 0.005031322
 [157] 0.006149414 0.007003677 0.006224591 0.009688899 0.006589518 0.005979435
 [163] 0.004608382 0.013722744 0.016609618 0.009485552 0.004608382 0.012104732
 [169] 0.004608382 0.016289582 0.018204154 0.004608382 0.020926033 0.004978690
 [175] 0.015743860 0.008925468 0.004608382 0.004608382 0.005979622 0.005031322
 [181] 0.004608382 0.012300297 0.005786292 0.005540334 0.006398473 0.004608382
 [187] 0.004608382 0.003964098 0.006153678 0.009498662 0.005031322 0.012272410
 [193] 0.004608382 0.006224591 0.009427613 0.003964098 0.004608382 0.004608382
 [199] 0.004387194 0.005031322 0.010395449 0.005505592 0.017521279 0.006589518
 [205] 0.011522516 0.004608382 0.013049325 0.004608382 0.004506174 0.005901713
 [211] 0.004608382 0.007814361 0.006101265 0.004608382 0.004608382 0.006101265
 [217] 0.005031322 0.011766133 0.004608382 0.012354337 0.019626885 0.017263642
 [223] 0.009841237 0.012016303 0.008925468 0.005581844 0.006589518 0.006019983
 [229] 0.006387716 0.005979435 0.005031322 0.005661762 0.014537622 0.007118693
 [235] 0.004608382 0.004608382 0.004639926 0.015743860 0.008778001 0.009498662
 [241] 0.007492439 0.007870699 0.006702237 0.005031322 0.006223281 0.004608382
 [247] 0.011766133 0.006393434 0.010422667 0.020282317 0.005031322 0.005031322
 [253] 0.004608382 0.009159163 0.013191155 0.006206750 0.006590748 0.008224551
 [259] 0.006206750 0.014180068 0.006590748 0.006386033 0.004608382 0.004608382
 [265] 0.004608382 0.005979435 0.005031322 0.016774158 0.004608382 0.003964098
 [271] 0.003555474 0.013722744 0.006153678 0.006206750 0.007870699 0.006206750
 [277] 0.005031322 0.010057526 0.012104732 0.003964098 0.010340660 0.006386033
 [283] 0.004608382 0.005979622 0.005031322 0.010550133 0.004608382 0.006512591
 [289] 0.004608382 0.005031322 0.010415841 0.004608382 0.006512591 0.004387194
 [295] 0.011541110 0.004608382 0.004608382 0.010157111 0.012744442 0.004608382
 [301] 0.026097909 0.023087686 0.017312016 0.012420470 0.011247657 0.014393116
 [307] 0.004387194 0.004608382 0.004608382 0.004608382 0.011911437 0.014875285
 [313] 0.006206750 0.012073391 0.012058822 0.005031322 0.011541110 0.004608382
 [319] 0.004608382 0.013399098 0.015728056 0.011882701 0.012191312 0.011374016
 [325] 0.005781412 0.005031322 0.005031322 0.004608382 0.005031322 0.005031322
 [331] 0.012174589 0.013380957 0.005031322 0.010550133 0.004608382 0.004608382
 [337] 0.011911437 0.013812476 0.006206750 0.011034277 0.012375729 0.004608382
 [343] 0.004778204 0.016653951 0.006512591 0.015102551 0.011344928 0.004608382
 [349] 0.007396820 0.005031322 0.011077602 0.004608382 0.006512591 0.012968921
 [355] 0.009870578 0.004608382 0.013812476 0.006206750 0.011014037 0.010750225
 [361] 0.010272153 0.004387194 0.004778204 0.006512591 0.005031322 0.010390776
 [367] 0.006512591 0.004608382 0.004608382 0.004608382 0.005031322 0.005031322
 [373] 0.011247657 0.008434098 0.004608382 0.004608382 0.004384035 0.004384035
 [379] 0.004421263 0.004421263 0.004608382 0.004608382 0.004608382 0.004608382
 [385] 0.023697435 0.011317124 0.004608382 0.018571098 0.003964098 0.030183378
 [391] 0.004608382 0.013961789 0.006206750 0.014076387 0.013518539 0.013518539
 [397] 0.007810055 0.016859324 0.022455457 0.011704623 0.012300297 0.010835902
 [403] 0.005591267 0.017623940 0.011464180 0.004608382 0.022736656 0.004608382
 [409] 0.005031322 0.010390776 0.004778204 0.013399098 0.005031322 0.005031322
 [415] 0.004608382 0.016618672 0.005031322 0.017255849 0.004608382 0.011704623
 [421] 0.010972426 0.004608382 0.012055520 0.005031322 0.011077602 0.004506174
 [427] 0.004608382 0.014878008 0.004608382 0.004608382 0.006206750 0.006206750
 [433] 0.016871062 0.016253689 0.007810055 0.013757236 0.016618672 0.011247657
 [439] 0.004608382 0.004421263 0.004608382 0.005031322 0.012025974 0.004608382
 [445] 0.015661175 0.006206750 0.012066582 0.004608382 0.004608382 0.004608382
 [451] 0.004608382 0.004608382 0.011360649 0.011465935 0.014393116 0.004608382
 [457] 0.004608382 0.004608382 0.004608382 0.004608382 0.004608382 0.008434098
 [463] 0.004608382 0.005031322 0.014031952 0.022072474 0.020954161 0.005031322
 [469] 0.004608382 0.005420921 0.004608382 0.013544527 0.011226880 0.004608382
 [475] 0.012375729 0.004387194 0.011226880 0.004608382 0.016449997 0.005781412
 [481] 0.004608382 0.011337448 0.014393116 0.003964098 0.011117142 0.004608382
 [487] 0.011149566 0.004608382 0.022072474 0.016653951 0.010160691 0.004608382
 [493] 0.005031322 0.033519092 0.011344928 0.004387194 0.023486024 0.020954161
 [499] 0.017616641 0.018157551 0.005781412 0.012872065 0.004608382 0.004608382
 [505] 0.004608382 0.010752292 0.013057719 0.013544527 0.011149566 0.004608382
 [511] 0.011149566 0.004608382 0.012616830 0.004608382 0.004608382 0.004608382
 [517] 0.006127871 0.010967804 0.018157551 0.004387194 0.011344928 0.011503711
 [523] 0.005031322 0.005031322 0.004608382 0.011112987 0.005031322 0.004401579
 [529] 0.011112987 0.018085278 0.012616830 0.011134495 0.005031322 0.010390776
 [535] 0.022072474 0.019921938 0.010390776 0.016900095 0.015789365 0.007810055
 [541] 0.012227284 0.004608382 0.011112987 0.011703228 0.004421263 0.003709070
 [547] 0.012946738 0.006126070 0.012189365 0.013093342 0.009833896 0.009883436
 [553] 0.011136137 0.003709070 0.003709070 0.006226728 0.023307982 0.011368319
 [559] 0.009723625 0.003709070 0.003969043 0.003454965 0.003709070 0.003709070
 [565] 0.005144381 0.003709070 0.012137490 0.018658577 0.018302336 0.019167867
 [571] 0.030096659 0.022551408 0.018054944 0.018081328 0.047845941 0.009654088
 [577] 0.003709070 0.047845941 0.003969043 0.003709070 0.006226728 0.006232099
 [583] 0.003454965 0.003709070 0.018461325 0.018054944 0.029791958 0.018260762
 [589] 0.030045166 0.047845941 0.009325333 0.051969049 0.015368043 0.003610949
 [595] 0.003353910 0.005961624 0.003709070 0.003353910 0.012652204 0.003969043
 [601] 0.006226728 0.038806395 0.024995469 0.024995469 0.021328713 0.031825357
 [607] 0.011136137 0.003709070 0.003709070 0.009883436 0.005163892 0.005138529
 [613] 0.003709070 0.003405905 0.004480187 0.003709070 0.003405905 0.003969043
 [619] 0.009917425 0.003610949 0.005144381 0.003709070 0.014052742 0.010770791
 [625] 0.006352800 0.006352800 0.003610949 0.009335241 0.003969043 0.006226728
 [631] 0.005310732 0.003405905 0.003709070 0.004793153 0.009521276 0.004480187
 [637] 0.005144381 0.003610949 0.003709070 0.005144381 0.003709070 0.005961624
 [643] 0.005961624 0.003610949 0.003610949 0.003610949 0.003709070 0.003454965
 [649] 0.013093342 0.003709070 0.003709070 0.003454965 0.003610949 0.009917425
 [655] 0.003709070 0.006226728 0.006232099 0.003969043 0.011136137 0.003454965
 [661] 0.003709070 0.003454965 0.003709070 0.003709070 0.009335241 0.003709070
 [667] 0.003709070 0.003709070 0.003709070 0.003709070 0.004480187 0.003709070
 [673] 0.015633954 0.019885789 0.018378193 0.003709070 0.004480187 0.011912196
 [679] 0.005138529 0.005961624 0.003360776 0.015368043 0.003405905 0.004480187
 [685] 0.009689886 0.009637219 0.018898425 0.006352800 0.006352800 0.003709070
 [691] 0.003709070 0.014927762 0.003405905 0.013858083 0.014574541 0.013243646
 [697] 0.013100487 0.009689886 0.006931917 0.020861992 0.021119127 0.013331359
 [703] 0.018083391 0.003709070 0.003405905 0.003709070 0.010421723 0.005961624
 [709] 0.003709070 0.003709070 0.003709070 0.010421723 0.009689886 0.003454965
 [715] 0.009325333 0.003709070 0.003709070 0.009491551 0.005463014 0.011539911
 [721] 0.005144381 0.006931917 0.003709070 0.012971160 0.005806901 0.006531330
 [727] 0.003709070 0.028066251 0.003709070 0.003709070 0.005144381 0.003709070
 [733] 0.014374173 0.014960685 0.014004258 0.026243500 0.027162406 0.003709070
 [739] 0.003405905 0.013093342 0.019910563 0.006352800 0.003709070 0.011659872
 [745] 0.003709070 0.036081112 0.036492552 0.036360876 0.036201863 0.037729879
 [751] 0.037067490 0.047845941 0.047845941 0.003709070 0.003709070 0.003969043
 [757] 0.015590420 0.015590420 0.004480187 0.003454965 0.005961624 0.006226728
 [763] 0.012022157 0.003969043 0.003385306 0.015590420 0.006226728 0.003610949
 [769] 0.017235431 0.003709070 0.014079127 0.009654088 0.005144381 0.009723625
 [775] 0.003353910 0.009335241 0.003709070 0.003709070 0.021886792 0.011423061
 [781] 0.003709070 0.003709070 0.009654088 0.003709070 0.003709070 0.006226728
 [787] 0.006226728 0.009637219 0.009521276 0.003969043 0.003709070 0.006845065
 [793] 0.003709070 0.009723625 0.003405905 0.003709070 0.003709070 0.003709070
 [799] 0.018961924 0.021991791 0.003709070 0.003709070 0.004480187 0.017744860
 [805] 0.003353910 0.009917425 0.003709070 0.005465316 0.005311499 0.009917425
 [811] 0.005961624 0.003610949 0.003709070 0.009521276 0.003709070 0.003405905
 [817] 0.019723160 0.012458150 0.004793153 0.003709070 0.003709070 0.014061593
 [823] 0.015590420 0.020576854 0.023192495 0.011914533 0.021244470 0.005573821
 [829] 0.012971160 0.009833896 0.003709070 0.009335241 0.009723625 0.003709070
 [835] 0.003709070 0.003405905 0.009335241 0.003709070 0.003709070 0.003709070
 [841] 0.003709070 0.003454965 0.003709070 0.003709070 0.006226728 0.006226728
 [847] 0.011762171 0.003709070 0.006226728 0.006226728 0.003770865 0.009654088
 [853] 0.003709070 0.009325333 0.009917425 0.009491551 0.003405905 0.003709070
 [859] 0.003709070 0.003709070 0.003709070 0.014336135 0.003709070 0.005768346
 [865] 0.005772183 0.003709070 0.009521276 0.003454965 0.003610949 0.003709070
 [871] 0.003709070 0.017903889 0.010497888 0.003709070 0.009491551 0.005144381
 [877] 0.003405905 0.014336135 0.021435778 0.011547897 0.011780687 0.003709070
 [883] 0.016040246 0.013090910 0.003709070 0.003709070 0.011136137 0.009723625
 [889] 0.003610949 0.003709070 0.011996947 0.003610949 0.003709070 0.009335241
 [895] 0.003709070 0.003353910 0.009335241 0.015820661 0.003709070 0.005138529
 [901] 0.003709070 0.003709070 0.009917425 0.003969043 0.003353910 0.003969043
 [907] 0.003969043 0.006931917 0.009783288 0.018923656 0.014942288 0.017799178
 [913] 0.013468147 0.047845941 0.041435110 0.037173375 0.040509595 0.036591877
 [919] 0.036118466 0.047845941 0.003610949 0.004480187 0.003709070 0.021660554
 [925] 0.018109508 0.012971160 0.003610949 0.003709070 0.003405905 0.012527469
 [931] 0.003454965 0.003709070 0.004480187 0.006226728 0.005144381 0.009917425
 [937] 0.005961624 0.003454965 0.003709070 0.003610949 0.036204728 0.038916835
 [943] 0.037173375 0.040509595 0.036764402 0.047845941 0.003405905 0.003709070
 [949] 0.006226728 0.006226728 0.019633944 0.005573821 0.012971160 0.003709070
 [955] 0.006931917 0.003709070 0.003709070 0.159303782 0.003454965 0.009521276
 [961] 0.003709070 0.021991791 0.017934870 0.018961924 0.009833896 0.003969043
 [967] 0.003562886 0.009637219 0.003405905 0.003709070 0.003610949 0.011136137
 [973] 0.012251885 0.010882173 0.011014802 0.013014555 0.047845941 0.047845941
 [979] 0.004480187 0.003709070 0.003709070 0.003709070 0.009325333 0.003610949
 [985] 0.003709070 0.004480187 0.003405905 0.009783288 0.003709070 0.021062507
 [991] 0.006352800 0.013093342 0.014704357 0.003709070 0.003709070 0.012232907
 [997] 0.003454965 0.009833896 0.003709070 0.023843847 0.013160547 0.003709070
[1003] 0.003709070 0.003709070 0.009833896 0.016706870 0.015633954 0.017600459
[1009] 0.003709070 0.011136137 0.034279995 0.008627703 0.012971160 0.013801537
[1015] 0.006352800 0.006352800 0.003709070 0.003709070 0.003709070 0.003709070
[1021] 0.014165852 0.028557684 0.015136280 0.006226728 0.009335241 0.003969043
[1027] 0.009331652 0.003405905 0.003405905 0.003709070 0.011577669 0.003709070
[1033] 0.006232099 0.005311499 0.018602388 0.003709070 0.003610949 0.003709070
[1039] 0.003709070 0.006226728 0.015400030 0.003709070 0.009047073 0.003709070
[1045] 0.003709070 0.003709070

$pmethod
[1] "backward"

$nprune
NULL

$penalty
[1] 3

$nk
[1] 21

$thresh
[1] 0.001

$termcond
[1] 7

$weights
NULL

$glm.list
$glm.list[[1]]

Call:  glm(formula = yarg ~ ., family = family, data = bx.data.frame, 
    weights = weights, na.action = na.action, offset = offset, 
    control = control, model = TRUE, method = "glm.fit", x = TRUE, 
    y = TRUE, contrasts = NULL, trace = (trace >= 2))

Coefficients:
            (Intercept)     `survived*h(age-15)`     `pclass3rd*survived`  
                1.64145                  0.94212                  1.28240  
 `h(25-age)*h(4-parch)`  `h(sibsp-2)*h(4-parch)`  `h(2-sibsp)*h(4-parch)`  
               -0.02672                  0.38100                  0.16455  
              pclass3rd   `pclass3rd*h(4-parch)`     `pclass2nd*survived`  
               -2.91928                  0.53579                 -0.99009  
 `survived*h(age-11.5)`  
               -0.94463  

Degrees of Freedom: 1045 Total (i.e. Null);  1036 Residual
Null Deviance:	    1380 
Residual Deviance: 941.2 	AIC: 961.2


$glm.coefficients
                            male
(Intercept)            1.6414456
survived*h(age-15)     0.9421209
pclass3rd*survived     1.2824017
h(25-age)*h(4-parch)  -0.0267240
h(sibsp-2)*h(4-parch)  0.3810006
h(2-sibsp)*h(4-parch)  0.1645457
pclass3rd             -2.9192836
pclass3rd*h(4-parch)   0.5357947
pclass2nd*survived    -0.9900858
survived*h(age-11.5)  -0.9446345

$glm.stats
  nulldev   df      dev   df  devratio      AIC iters converged
 1379.574 1045 941.1673 1036 0.3177844 961.1673     5         1

$call
earth(formula = sex ~ ., data = etitanic, trace = 1, glm = list(family = "binomial"), 
    degree = 2)

$namesx.org
[1] "pclass"   "survived" "age"      "sibsp"    "parch"   

$namesx
[1] "pclass"   "survived" "age"      "sibsp"    "parch"   

$terms
sex ~ pclass + survived + age + sibsp + parch
attr(,"variables")
list(sex, pclass, survived, age, sibsp, parch)
attr(,"factors")
         pclass survived age sibsp parch
sex           0        0   0     0     0
pclass        1        0   0     0     0
survived      0        1   0     0     0
age           0        0   1     0     0
sibsp         0        0   0     1     0
parch         0        0   0     0     1
attr(,"term.labels")
[1] "pclass"   "survived" "age"      "sibsp"    "parch"   
attr(,"order")
[1] 1 1 1 1 1
attr(,"intercept")
[1] 1
attr(,"response")
[1] 1
attr(,".Environment")
<environment: R_GlobalEnv>
attr(,"predvars")
list(sex, pclass, survived, age, sibsp, parch)
attr(,"dataClasses")
      sex    pclass  survived       age     sibsp     parch 
 "factor"  "factor" "numeric" "numeric" "numeric" "numeric" 

$xlevels
$xlevels$pclass
[1] "1st" "2nd" "3rd"


$levels
[1] "female" "male"  

attr(,"class")
[1] "earth"
-------------------------------------------------------------------------------

> 
> a7d <- earth(sex ~ .-pclass, data=etitanic, degree=2, glm=list(family="binomial"), trace=0)
> a7dupdate <- update(a7, form=sex ~ .-pclass)
update.earth: using 1046 by 6 data argument from original call to earth
x[1046,4] with colnames survived age sibsp parch
y[1046,1] with colname male, and values 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,...
Forward pass term 1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20
Reached nk 21
After forward pass GRSq 0.310 RSq 0.368
Prune backward penalty 3 nprune null: selected 8 of 19 terms, and 4 of 4 preds
After pruning pass GRSq 0.335 RSq 0.357
GLM male devratio 0.30 dof 1038/1045 iters 4
> check.models.equal(a7dupdate, a7d, msg="a7update a7d", newdata=etitanic[5,])
a7update a7d: models not identical

Formulas differ: sex ~ survived + age + sibsp + parch
and:             sex ~ (pclass + survived + age + sibsp + parch) - pclass

a7update a7d: glm submodel formula strings are identical: yarg ~ `survived*h(age-15)` + `h(25-age)*h(4-parch)` + `h(sibsp-2)*h(4-parch)` +     `h(2-sibsp)*h(4-parch)` + `h(sibsp-2)` + `h(2-sibsp)` + `survived*h(age-11.5)`
a7update a7d: but the actual glm submodel formulas differ (classes are "formula" and "formula")
a7update a7d: glm submodels not identical (but coefs, residuals, fitted.values are the same)
a7update a7d: Models are equivalent, within numerical tolerances

> printh(a7d$levels)
=== a7d$levels
[1] "female" "male"  
> 
> a7d <- earth(sex ~ .-pclass, data=etitanic, degree=2, glm=list(family="binomial"), trace=0, keepxy=1)
> a7dupdate <- update(a7, form=sex ~ .-pclass)
update.earth: using 1046 by 6 data argument from original call to earth
x[1046,4] with colnames survived age sibsp parch
y[1046,1] with colname male, and values 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,...
Forward pass term 1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20
Reached nk 21
After forward pass GRSq 0.310 RSq 0.368
Prune backward penalty 3 nprune null: selected 8 of 19 terms, and 4 of 4 preds
After pruning pass GRSq 0.335 RSq 0.357
GLM male devratio 0.30 dof 1038/1045 iters 4
> check.models.equal(a7dupdate, a7d, msg="a7update a7d with keepxy", newdata=etitanic[5,])
a7update a7d with keepxy: models not identical

Formulas differ: sex ~ survived + age + sibsp + parch
and:             sex ~ (pclass + survived + age + sibsp + parch) - pclass

a7update a7d with keepxy: glm submodel formula strings are identical: yarg ~ `survived*h(age-15)` + `h(25-age)*h(4-parch)` + `h(sibsp-2)*h(4-parch)` +     `h(2-sibsp)*h(4-parch)` + `h(sibsp-2)` + `h(2-sibsp)` + `survived*h(age-11.5)`
a7update a7d with keepxy: but the actual glm submodel formulas differ (classes are "formula" and "formula")
a7update a7d with keepxy: glm submodels not identical (but coefs, residuals, fitted.values are the same)
a7update a7d with keepxy: Models are equivalent, within numerical tolerances

> 
> subset. <- rep(TRUE, nrow(etitanic))
> subset.[1:10] <- FALSE
> a7e <- earth(sex ~ ., subset=subset., data=etitanic, degree=2, glm=list(family="binomial"), trace=0)
> a7eupdate <- update(a7, subset=subset.)
update.earth: using 1046 by 6 data argument from original call to earth
x[1046,6] with colnames pclass2nd pclass3rd survived age sibsp parch
y[1046,1] with colname male, and values 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,...
1036 cases after taking subset
Forward pass term 1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20
Reached nk 21
After forward pass GRSq 0.345 RSq 0.389
Prune backward penalty 3 nprune null: selected 11 of 15 terms, and 6 of 6 preds
After pruning pass GRSq 0.358 RSq 0.389
GLM male devratio 0.33 dof 1025/1035 iters 5
> check.models.equal(a7eupdate, a7e, msg="a7update a7e", newdata=etitanic[5,])
a7update a7e: models not identical

a7update a7e: glm submodel formula strings are identical: yarg ~ survived + `survived*h(age-15)` + `pclass3rd*survived` +     pclass3rd + `h(sibsp-1)*h(4-parch)` + `h(1-sibsp)*h(4-parch)` +     `pclass3rd*h(2-parch)` + `survived*h(age-26)` + `pclass2nd*survived` +     `survived*h(age-12)`
a7update a7e: but the actual glm submodel formulas differ (classes are "formula" and "formula")
a7update a7e: glm submodels not identical (but coefs, residuals, fitted.values are the same)
a7update a7e: Models are equivalent, within numerical tolerances

> 
> subset. <- 1:nrow(etitanic) # another way of specifying a subset
> subset.[1:10] <- 0
> a7eeupdate <- update(a7, subset=subset.)
update.earth: using 1046 by 6 data argument from original call to earth
x[1046,6] with colnames pclass2nd pclass3rd survived age sibsp parch
y[1046,1] with colname male, and values 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,...
1036 cases after taking subset
Forward pass term 1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20
Reached nk 21
After forward pass GRSq 0.345 RSq 0.389
Prune backward penalty 3 nprune null: selected 11 of 15 terms, and 6 of 6 preds
After pruning pass GRSq 0.358 RSq 0.389
GLM male devratio 0.33 dof 1025/1035 iters 5
> check.models.equal(a7eeupdate, a7e, msg="a7update a7e with alternative subset", newdata=etitanic[5,])
a7update a7e with alternative subset: models not identical

a7update a7e with alternative subset: glm submodel formula strings are identical: yarg ~ survived + `survived*h(age-15)` + `pclass3rd*survived` +     pclass3rd + `h(sibsp-1)*h(4-parch)` + `h(1-sibsp)*h(4-parch)` +     `pclass3rd*h(2-parch)` + `survived*h(age-26)` + `pclass2nd*survived` +     `survived*h(age-12)`
a7update a7e with alternative subset: but the actual glm submodel formulas differ (classes are "formula" and "formula")
a7update a7e with alternative subset: glm submodels not identical (but coefs, residuals, fitted.values are the same)
a7update a7e with alternative subset: Models are equivalent, within numerical tolerances

> 
> a7f <- earth(sex ~ ., data=etitanic, degree=2, glm=list(family=binomial(link="probit")), trace=0)
> a7fupdate <- update(a7, glm=list(family=binomial(link="probit")))
update.earth: using 1046 by 6 data argument from original call to earth
x[1046,6] with colnames pclass2nd pclass3rd survived age sibsp parch
y[1046,1] with colname male, and values 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,...
Skipped forward pass
Prune backward penalty 3 nprune null: selected 10 of 15 terms, and 6 of 6 preds
After pruning pass GRSq 0.352 RSq 0.38
GLM male devratio 0.32 dof 1036/1045 iters 5
> check.models.equal(a7fupdate, a7f, msg="a7update a7f with link=probit", newdata=etitanic[5,])
a7update a7f with link=probit: models not identical

a7update a7f with link=probit: glm submodel formula strings are identical: yarg ~ `survived*h(age-15)` + `pclass3rd*survived` + `h(25-age)*h(4-parch)` +     `h(sibsp-2)*h(4-parch)` + `h(2-sibsp)*h(4-parch)` + pclass3rd +     `pclass3rd*h(4-parch)` + `pclass2nd*survived` + `survived*h(age-11.5)`
a7update a7f with link=probit: but the actual glm submodel formulas differ (classes are "formula" and "formula")
a7update a7f with link=probit: glm submodels not identical (but coefs, residuals, fitted.values are the same)
a7update a7f with link=probit: Models are equivalent, within numerical tolerances

> 
> a7 <- earth(sex ~ ., data=etitanic, degree=2, glm=list(family="binomial"), keepxy=1)
> a7g <- earth(sex ~ ., data=etitanic, degree=2, glm=list(family=binomial(link="probit")), trace=0)
> a7gupdate <- update(a7, glm=list(family=binomial(link="probit")), trace=1)
update.earth: using 1046 by 6 data saved by keepxy in original call to earth
x[1046,6] with colnames pclass2nd pclass3rd survived age sibsp parch
y[1046,1] with colname male, and values 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,...
Skipped forward pass
Prune backward penalty 3 nprune null: selected 10 of 15 terms, and 6 of 6 preds
After pruning pass GRSq 0.352 RSq 0.38
GLM male devratio 0.32 dof 1036/1045 iters 5
> check.models.equal(a7gupdate, a7g, msg="a7update a7g with link=probit and keepxy", newdata=etitanic[5,])
a7update a7g with link=probit and keepxy: models not identical

a7update a7g with link=probit and keepxy: glm submodel formula strings are identical: yarg ~ `survived*h(age-15)` + `pclass3rd*survived` + `h(25-age)*h(4-parch)` +     `h(sibsp-2)*h(4-parch)` + `h(2-sibsp)*h(4-parch)` + pclass3rd +     `pclass3rd*h(4-parch)` + `pclass2nd*survived` + `survived*h(age-11.5)`
a7update a7g with link=probit and keepxy: but the actual glm submodel formulas differ (classes are "formula" and "formula")
a7update a7g with link=probit and keepxy: glm submodels not identical (but coefs, residuals, fitted.values are the same)
a7update a7g with link=probit and keepxy: Models are equivalent, within numerical tolerances

> 
> a8 <- earth(sex ~ ., data=etitanic, degree=2, glm=list(family="binomial"), keepxy=1)
> a8g <- earth(sex ~ ., data=etitanic[100:900,], degree=2, glm=list(family=binomial), trace=0)
> a8gupdate <- update(a8, data=etitanic[100:900,], trace=1)
x[801,6] with colnames pclass2nd pclass3rd survived age sibsp parch
y[801,1] with colname male, and values 0, 0, 0, 1, 1, 0, 0, 1, 1, 0,...
Forward pass term 1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20
Reached nk 21
After forward pass GRSq 0.345 RSq 0.409
Prune backward penalty 3 nprune null: selected 9 of 17 terms, and 6 of 6 preds
After pruning pass GRSq 0.369 RSq 0.4
GLM male devratio 0.34 dof 792/800 iters 5
> check.models.equal(a8gupdate, a8g, msg="a8update a8g with new data", newdata=etitanic[5,])
a8update a8g with new data: models not identical

a8update a8g with new data: glm submodel formula strings are identical: yarg ~ survived + `h(3-parch)` + `pclass3rd*survived` + pclass3rd +     `pclass3rd*h(13-age)` + pclass2nd + `h(15-age)` + `pclass3rd*h(2-sibsp)`
a8update a8g with new data: but the actual glm submodel formulas differ (classes are "formula" and "formula")
a8update a8g with new data: glm submodels not identical (but coefs, residuals, fitted.values are the same)
a8update a8g with new data: Models are equivalent, within numerical tolerances

> 
> # poisson models
> 
> counts <- c(18,17,15,20,10,20,25,13,12)
> counts2 <- c(181,171,151,201,101,201,251,131,121)
> outcome <- gl(3,1,9)
> treatment <- gl(3,3)
> d.AD <- data.frame(treatment, outcome, counts, counts2)
> 
> # one response poisson model
> cat("a8p: one response poisson model\n\n")
a8p: one response poisson model

> a8p <- earth(counts ~ outcome + treatment, glm=list(family=poisson()), trace=3, pmethod=PMETHOD)
x[9,4] with colnames outcome2 outcome3 treatment2 treatment3
y[9,1] with colname counts, and values 18, 17, 15, 20, 10, 20, 25, 1...
Forward pass: minspan 3 endspan 3   x[9,4] 288 Bytes   bx[9,21] 1.48 kB

         GRSq    RSq     DeltaRSq Pred     PredName         Cut  Terms   Par Deg
1      0.0000 0.0000                    (Intercept)
2     -0.2727 0.2841       0.2841    1     outcome2           0< 2             1 
4     -0.8939 0.5265       0.2424    2     outcome3           0< 3             1 
6     -6.5758 0.5265            0    -                                       reject (no DeltaRsq)

RSq changed by less than 0.001 at 5 terms, 3 terms used (DeltaRSq 0)
After forward pass GRSq -6.576 RSq 0.527
Forward pass complete: 5 terms, 3 terms used

Subset size        GRSq     RSq  DeltaGRSq nPreds
          1      0.0000  0.0000     0.0000      0  
          2     -0.2727  0.2841    -0.2727      1  
chosen    3     -0.8939  0.5265    -0.6212      2  

Prune none penalty 2 nprune null: selected 3 of 3 terms, and 2 of 4 preds
After pruning pass GRSq -0.894 RSq 0.527
GLM counts devratio 0.52 dof 6/8 iters 4
> show.earth.models(a8p, legend.pos="topleft")

Print a8p 

GLM (family poisson, link log):
 nulldev df       dev df   devratio     AIC iters converged
 10.5815  8   5.12914  6      0.515   52.76     4         1

Earth selected 3 of 3 terms, and 2 of 4 predictors (pmethod="none")
Termination condition: RSq changed by less than 0.001 at 3 terms
Importance: outcome2, outcome3, treatment2-unused, treatment3-unused
Number of terms at each degree of interaction: 1 2 (additive model)
Earth GCV 46.875    RSS 83.33333    GRSq -0.8939394    RSq 0.5265152

Summary a8p 

Call: earth(formula=counts~outcome+treatment, pmethod=PMETHOD, trace=3,
            glm=list(family=poisson()))

GLM coefficients
                counts
(Intercept)  3.0445224
outcome2    -0.4542553
outcome3    -0.2929871

GLM (family poisson, link log):
 nulldev df       dev df   devratio     AIC iters converged
 10.5815  8   5.12914  6      0.515   52.76     4         1

Earth selected 3 of 3 terms, and 2 of 4 predictors (pmethod="none")
Termination condition: RSq changed by less than 0.001 at 3 terms
Importance: outcome2, outcome3, treatment2-unused, treatment3-unused
Number of terms at each degree of interaction: 1 2 (additive model)
Earth GCV 46.875    RSS 83.33333    GRSq -0.8939394    RSq 0.5265152

Summary a8p digits=3, details=TRUE

Call: earth(formula=counts~outcome+treatment, pmethod=PMETHOD, trace=3,
            glm=list(family=poisson()))

Earth coefficients
            counts
(Intercept)  21.00
outcome2     -7.67
outcome3     -5.33

GLM coefficients
            counts
(Intercept)  3.045
outcome2    -0.454
outcome3    -0.293

GLM deviance residuals:
   Min      1Q  Median      3Q     Max  
-0.967  -0.671  -0.170   0.847   1.049  

GLM coefficients (family poisson, link log)
            Estimate Std. Error z value Pr(>|z|)
(Intercept)    3.045      0.126   24.17   <2e-16
outcome2      -0.454      0.202   -2.25    0.025
outcome3      -0.293      0.193   -1.52    0.128

GLM (family poisson, link log):
 nulldev df       dev df   devratio     AIC iters converged
    10.6  8      5.13  6       0.52    52.8     4         1

Earth selected 3 of 3 terms, and 2 of 4 predictors (pmethod="none")
Termination condition: RSq changed by less than 0.001 at 3 terms
Importance: outcome2, outcome3, treatment2-unused, treatment3-unused
Number of terms at each degree of interaction: 1 2 (additive model)
Earth GCV 46.9    RSS 83.3    GRSq -0.894    RSq 0.527

evimp a8p 

         nsubsets   gcv    rss
outcome2        2 -100.0  100.0
outcome3        1 -83.4   67.9

evimp a8p trim=FALSE

                  nsubsets   gcv    rss
outcome2                 2 -100.0  100.0
outcome3                 1 -83.4   67.9
treatment2-unused        0   0.0    0.0
treatment3-unused        0   0.0    0.0

glm params: epsilon 1e-08 maxit 25 trace FALSE family poisson link log 

plotmo a8p 
 plotmo grid:    outcome treatment
                       1         1
-------------------------------------------------------------------------------

> # build a standard GLM model for comparison
> cat("a9: one response poisson model, standard GLM model for comparison\n\n")
a9: one response poisson model, standard GLM model for comparison

> a9 <- glm(counts ~ outcome + treatment, family="poisson")
> cat("Direct GLM a9 summary:\n\n")
Direct GLM a9 summary:

> print(summary(a9))

Call:
glm(formula = counts ~ outcome + treatment, family = "poisson")

Deviance Residuals: 
       1         2         3         4         5         6         7         8  
-0.67125   0.96272  -0.16965  -0.21999  -0.95552   1.04939   0.84715  -0.09167  
       9  
-0.96656  

Coefficients:
              Estimate Std. Error z value Pr(>|z|)    
(Intercept)  3.045e+00  1.709e-01  17.815   <2e-16 ***
outcome2    -4.543e-01  2.022e-01  -2.247   0.0246 *  
outcome3    -2.930e-01  1.927e-01  -1.520   0.1285    
treatment2   1.338e-15  2.000e-01   0.000   1.0000    
treatment3   1.421e-15  2.000e-01   0.000   1.0000    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for poisson family taken to be 1)

    Null deviance: 10.5814  on 8  degrees of freedom
Residual deviance:  5.1291  on 4  degrees of freedom
AIC: 56.761

Number of Fisher Scoring iterations: 4

> plotmo(a9, grid.levels=list(outcome="2"), caption="a9 <- glm(counts ~ outcome + treatment, family=\"poisson\")")
 plotmo grid:    outcome treatment
                       2         1
> 
> # two response poisson model
> cat("a10: two response poisson model\n\n")
a10: two response poisson model

> a10 <- earth(cbind(counts, counts2) ~ outcome + treatment, glm=list(fam="po"), trace=1, pmethod=PMETHOD)
x[9,4] with colnames outcome2 outcome3 treatment2 treatment3
y[9,2] with colnames counts counts2
Forward pass term 1, 2, 4, 6
RSq changed by less than 0.001 at 5 terms, 3 terms used (DeltaRSq 0)
After forward pass GRSq -6.576 RSq 0.527
Prune none penalty 2 nprune null: selected 3 of 3 terms, and 2 of 4 preds
After pruning pass GRSq -0.894 RSq 0.527
GLM counts devratio 0.52 dof 6/8 iters 4
GLM counts2 devratio 0.52 dof 6/8 iters 4
> show.earth.models(a10, nresponse="counts")

Print a10 

GLM (family poisson, link log):
         nulldev df       dev df   devratio     AIC iters converged
counts   10.5815  8   5.12914  6      0.515   52.76     4         1
counts2 105.1660  8  50.96448  6      0.515  119.30     4         1

Earth selected 3 of 3 terms, and 2 of 4 predictors (pmethod="none")
Termination condition: RSq changed by less than 0.001 at 3 terms
Importance: outcome2, outcome3, treatment2-unused, treatment3-unused
Number of terms at each degree of interaction: 1 2 (additive model)

Earth
             GCV       RSS       GRSq       RSq
counts    46.875   83.3333 -0.8939394 0.5265152
counts2 4687.500 8333.3333 -0.8939394 0.5265152
All     4734.375 8416.6667 -0.8939394 0.5265152

Summary a10 

Call: earth(formula=cbind(counts,counts2)~outcome+treatment, pmethod=PMETHOD,
            trace=1, glm=list(fam="po"))

GLM coefficients
                counts    counts2
(Intercept)  3.0445224  5.3518581
outcome2    -0.4542553 -0.4515339
outcome3    -0.2929871 -0.2913750

GLM (family poisson, link log):
         nulldev df       dev df   devratio     AIC iters converged
counts   10.5815  8   5.12914  6      0.515   52.76     4         1
counts2 105.1660  8  50.96448  6      0.515  119.30     4         1

Earth selected 3 of 3 terms, and 2 of 4 predictors (pmethod="none")
Termination condition: RSq changed by less than 0.001 at 3 terms
Importance: outcome2, outcome3, treatment2-unused, treatment3-unused
Number of terms at each degree of interaction: 1 2 (additive model)

Earth
             GCV       RSS       GRSq       RSq
counts    46.875   83.3333 -0.8939394 0.5265152
counts2 4687.500 8333.3333 -0.8939394 0.5265152
All     4734.375 8416.6667 -0.8939394 0.5265152

Summary a10 decomp="none", digits=5, fixed.point=FALSE, details=TRUE

Call: earth(formula=cbind(counts,counts2)~outcome+treatment, pmethod=PMETHOD,
            trace=1, glm=list(fam="po"))

Earth coefficients
             counts counts2
(Intercept) 21.0000 211.000
outcome2    -7.6667 -76.667
outcome3    -5.3333 -53.333

GLM coefficients
              counts  counts2
(Intercept)  3.04452  5.35186
outcome2    -0.45426 -0.45153
outcome3    -0.29299 -0.29138

GLM counts deviance residuals:
     Min        1Q    Median        3Q       Max  
-0.96656  -0.67125  -0.16965   0.84715   1.04939  

GLM counts coefficients (family poisson, link log)
            Estimate Std. Error z value Pr(>|z|)
(Intercept)  3.04452    0.12599 24.1651  < 2e-16
outcome2    -0.45426    0.20217 -2.2469  0.02465
outcome3    -0.29299    0.19274 -1.5201  0.12849

GLM counts2 deviance residuals:
     Min        1Q    Median        3Q       Max  
-3.04594  -2.11738  -0.53474   2.67294   3.30873  

GLM counts2 coefficients (family poisson, link log)
             Estimate Std. Error  z value  Pr(>|z|)
(Intercept)  5.351858   0.039746 134.6500 < 2.2e-16
outcome2    -0.451534   0.063727  -7.0854 1.386e-12
outcome3    -0.291375   0.060778  -4.7941 1.634e-06

GLM (family poisson, link log):
        nulldev df       dev df   devratio     AIC iters converged
counts    10.58  8     5.129  6       0.52    52.8     4         1
counts2  105.17  8    50.964  6       0.52   119.0     4         1

Earth selected 3 of 3 terms, and 2 of 4 predictors (pmethod="none")
Termination condition: RSq changed by less than 0.001 at 3 terms
Importance: outcome2, outcome3, treatment2-unused, treatment3-unused
Number of terms at each degree of interaction: 1 2 (additive model)

Earth
            GCV     RSS     GRSq     RSq
counts    46.87   83.33 -0.89394 0.52651
counts2 4687.50 8333.33 -0.89394 0.52651
All     4734.38 8416.67 -0.89394 0.52651

evimp a10 

         nsubsets   gcv    rss
outcome2        2 -100.0  100.0
outcome3        1 -83.4   67.9

evimp a10 trim=FALSE

                  nsubsets   gcv    rss
outcome2                 2 -100.0  100.0
outcome3                 1 -83.4   67.9
treatment2-unused        0   0.0    0.0
treatment3-unused        0   0.0    0.0

glm params: epsilon 1e-08 maxit 25 trace FALSE family poisson link log 

plotmo a10 
 plotmo grid:    outcome treatment
                       1         1
-------------------------------------------------------------------------------

> 
> # compare family=gaussian to standard earth model
> cat("a11: compare family=gaussian to standard earth model\n\n")
a11: compare family=gaussian to standard earth model

> a11 <- earth(etitanic$sex ~ ., data=etitanic, degree=2, glm=list(family="gaussian"), trace=4)
Call: earth(formula=etitanic$sex~., data=etitanic, trace=4,
            glm=list(family="gaussian"), degree=2)

x[1046,6]:
     pclass2nd pclass3rd survived     age sibsp parch
1            0         0        1 29.0000     0     0
2            0         0        1  0.9167     1     2
3            0         0        0  2.0000     1     2
...          0         0        0 30.0000     1     2
1046         0         1        0 29.0000     0     0

y[1046,1]:
     male
1       0
2       1
3       0
...     1
1046    1

Forward pass: minspan 6 endspan 9   x[1046,6] 49 kB   bx[1046,21] 172 kB

         GRSq    RSq     DeltaRSq Pred     PredName         Cut  Terms   Par Deg
1      0.0000 0.0000                    (Intercept)
2      0.2860 0.2894       0.2894    3     survived           0< 2             1 
4      0.3055 0.3155      0.02604    6        parch           4  3   4         1 
6      0.3162 0.3325        0.017    4          age          15  5   6     2   2 
8      0.3227 0.3420     0.009563    2    pclass3rd           0< 7         2   2 
10     0.3270 0.3525      0.01049    4          age          25  8   9     5   2 
12     0.3288 0.3605     0.007986    5        sibsp           2  10  11    5   2 
14     0.3336 0.3682     0.007705    2    pclass3rd           0< 12            1 
16     0.3389 0.3763     0.008053    2    pclass3rd           0< 13        5   2 
18     0.3404 0.3808     0.004528    1    pclass2nd           0< 14        2   2 
20     0.3405 0.3839     0.003089    4          age        11.5  15        2   2 final (reached nk 21)

Reached nk 21
After forward pass GRSq 0.340 RSq 0.384
Forward pass complete: 21 terms, 15 terms used

Subset size        GRSq     RSq  DeltaGRSq nPreds  Terms (col nbr in bx)
          1      0.0000  0.0000     0.0000      0  1
          2      0.2860  0.2894     0.2860      1  1 2
          3      0.2872  0.2940     0.0011      2  1 2 3
          4      0.3055  0.3155     0.0184      2  1 2 3 4
          5      0.3052  0.3185    -0.0003      3  1 2 3 4 5
          6      0.3195  0.3357     0.0143      4  1 5 9 12 13 15
          7      0.3314  0.3504     0.0118      4  1 5 7 9 12 13 15
          8      0.3377  0.3597     0.0063      5  1 5 7 9 10 12 13 15
          9      0.3472  0.3720     0.0096      5  1 5 7 9 10 11 12 13 15
chosen   10      0.3524  0.3800     0.0052      6  1 5 7 9 10 11 12 13 14 15
         11      0.3511  0.3818    -0.0013      6  1 3 5 7 9 10 11 12 13 14 15
         12      0.3494  0.3832    -0.0017      6  1 2 3 5 7 9 10 11 12 13 14 15
         13      0.3465  0.3835    -0.0028      6  1 2 3 5 6 7 9 10 11 12 13 14 15
         14      0.3436  0.3838    -0.0029      6  1 2 3 4 5 6 7 9 10 11 12 13 14 15
         15      0.3405  0.3839    -0.0032      6  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Prune backward penalty 3 nprune null: selected 10 of 15 terms, and 6 of 6 preds
After pruning pass GRSq 0.352 RSq 0.38

glm y[1046,1]:
     male
1       0
2       1
3       0
...     1
1046    1

glm weights: NULL

GLM male devratio 0.38 dof 1036/1045 iters 2
> cat("\nsummary(a11, details=TRUE)\n\n", sep="")

summary(a11, details=TRUE)

> print(summary(a11, details=TRUE))
Call: earth(formula=etitanic$sex~., data=etitanic, trace=4,
            glm=list(family="gaussian"), degree=2)

Earth coefficients
                               male
(Intercept)              0.78683434
pclass3rd               -0.54704139
pclass2nd * survived    -0.16389622
pclass3rd * survived     0.21003798
pclass3rd * h(4-parch)   0.11827615
survived * h(age-15)     0.17223256
survived * h(age-11.5)  -0.17249670
h(25-age) * h(4-parch)  -0.00453940
h(2-sibsp) * h(4-parch)  0.02431712
h(sibsp-2) * h(4-parch)  0.06510531

GLM coefficients
                               male
(Intercept)              0.78683434
pclass3rd               -0.54704139
pclass2nd * survived    -0.16389622
pclass3rd * survived     0.21003798
pclass3rd * h(4-parch)   0.11827615
survived * h(age-15)     0.17223256
survived * h(age-11.5)  -0.17249670
h(25-age) * h(4-parch)  -0.00453940
h(2-sibsp) * h(4-parch)  0.02431712
h(sibsp-2) * h(4-parch)  0.06510531

GLM deviance residuals:
        Min           1Q       Median           3Q          Max  
-0.98137128  -0.24911370   0.06726295   0.18302689   0.91075446  

GLM coefficients (family gaussian, link identity)
                             Estimate    Std. Error   t value   Pr(>|t|)
(Intercept)              0.7868343433  0.0423871064  18.56306 < 2.22e-16
survived * h(age-15)     0.1722325636  0.0149860217  11.49288 < 2.22e-16
pclass3rd * survived     0.2100379776  0.0508526436   4.13033 3.9143e-05
h(25-age) * h(4-parch)  -0.0045393995  0.0008358286  -5.43102 6.9815e-08
h(sibsp-2) * h(4-parch)  0.0651053056  0.0141628706   4.59690 4.8168e-06
h(2-sibsp) * h(4-parch)  0.0243171175  0.0055901123   4.35002 1.4958e-05
pclass3rd               -0.5470413932  0.0946425398  -5.78008 9.8730e-09
pclass3rd * h(4-parch)   0.1182761529  0.0244084967   4.84570 1.4543e-06
pclass2nd * survived    -0.1638962213  0.0447652568  -3.66124 0.00026368
survived * h(age-11.5)  -0.1724966990  0.0137251005 -12.56797 < 2.22e-16

GLM dispersion parameter for gaussian family taken to be 0.1460669

GLM (family gaussian, link identity):
 nulldev   df       dev   df   devratio     AIC iters converged
 244.077 1045   151.325 1036       0.38   968.2     2         1

Earth selected 10 of 15 terms, and 6 of 6 predictors
Termination condition: Reached nk 21
Importance: survived, parch, age, pclass3rd, sibsp, pclass2nd
Number of terms at each degree of interaction: 1 1 8
Earth GCV 0.1513968    RSS 151.3254    GRSq 0.3524225    RSq 0.3800084
> stopifnot(identical(a11$coefficients, a11$glm.coefficients))
> cat("-------------------------------------------------------------------------------\n\n")
-------------------------------------------------------------------------------

> 
> cat("a12: compare family=gaussian to standard earth model with two responses\n\n")
a12: compare family=gaussian to standard earth model with two responses

> a12 <- earth(cbind(etitanic$sex, (as.integer(etitanic$age)^2)) ~ ., data=etitanic, degree=2, glm=list(family="gaussian"), trace=4)
Call: earth(formula=cbind(etitanic$sex,(as.integer(etitanic$age)^2))~.,
            data=etitanic, trace=4, glm=list(family="gaussian"), degree=2)

x[1046,5]:
     pclass2nd pclass3rd survived sibsp parch
1            0         0        1     0     0
2            0         0        1     1     2
3            0         0        0     1     2
...          0         0        0     1     2
1046         0         1        0     0     0

y[1046,2]:
     y1  y2
1     1 841
2     2   0
3     1   4
...   2 900
1046  2 841

Forward pass: minspan 6 endspan 9   x[1046,5] 40.9 kB   bx[1046,21] 172 kB

         GRSq    RSq     DeltaRSq Pred     PredName         Cut  Terms   Par Deg
1      0.0000 0.0000                    (Intercept)
2      0.1060 0.1103       0.1103    2    pclass3rd           0< 2             1 
4      0.1653 0.1733      0.06303    1    pclass2nd           0< 3             1 
6      0.2059 0.2210      0.04767    5        parch           2  4   5         1 
8      0.2210 0.2396      0.01859    3     survived           0< 6             1 
10     0.2223 0.2481     0.008525    5        parch           2  7   8     2   2 
12     0.2234 0.2565      0.00837    4        sibsp           1  9   10        1 
14     0.2219 0.2587     0.002244    5        parch           1  11        2   2 
16     0.2231 0.2635     0.004765    5        parch           1  12            1 
18     0.2226 0.2702     0.006718    5        parch           1  13  14    4   2 
20     0.2232 0.2743      0.00415    1    pclass2nd           0< 15        6   2 final (reached nk 21)

Reached nk 21
After forward pass GRSq 0.223 RSq 0.274
Forward pass complete: 21 terms, 15 terms used

Using EvalSubsetsUsingXtx (rather than leaps) because this is a multiple response model
     nTerms iTerm    DeltaRss     RSq
         15     2 2.8941e+007  0.2461 min
         15     3 3.4484e+007  0.2406
         15     4 3.0548e+007  0.2445
         15     5 1.9834e+006  0.2724 min
         15     6 2.0705e+007  0.2541
         15     7 2.4297e+007  0.2506
         15     8 6.3042e+006  0.2682
         15     9 6.3458e+006  0.2681
         15    10      8231.6  0.2743 min
         15    11 1.5243e+007  0.2594
         15    12 1.4677e+007  0.2600
         15    13 1.0817e+007  0.2638
         15    14 4.9902e+006  0.2695
         15    15 4.2448e+006  0.2702

         14     2 2.9403e+007  0.2456 min
         14     3  3.491e+007  0.2402
         14     4 3.0578e+007  0.2444
         14     5 1.9758e+006  0.2724 min
         14     6  2.074e+007  0.2541
         14     7 2.4514e+007  0.2504
         14     8 6.4997e+006  0.2680
         14     9  6.995e+006  0.2675
         14    11 1.5597e+007  0.2591
         14    12  1.467e+007  0.2600
         14    13 1.0901e+007  0.2637
         14    14 5.1186e+006  0.2693
         14    15 4.2486e+006  0.2702

         13     2 4.1871e+007  0.2315 min
         13     3 4.0788e+007  0.2325 min
         13     4 3.2141e+007  0.2410 min
         13     6 2.0184e+007  0.2527 min
         13     7 2.3466e+007  0.2495
         13     8 5.1563e+006  0.2674 min
         13     9 7.0251e+006  0.2655
         13    11 1.5565e+007  0.2572
         13    12 2.1626e+007  0.2513
         13    13 8.9657e+006  0.2636
         13    14  3.173e+006  0.2693 min
         13    15 3.5082e+006  0.2690

         12     2 4.1546e+007  0.2287 min
         12     3 7.7449e+007  0.1936
         12     4 3.1892e+007  0.2381 min
         12     6 2.3605e+007  0.2462 min
         12     7 2.3299e+007  0.2465 min
         12     8 4.9192e+006  0.2645 min
         12     9 7.5636e+006  0.2619
         12    11 1.5356e+007  0.2543
         12    12  2.139e+007  0.2484
         12    13 6.1065e+006  0.2633
         12    15 2.5439e+006  0.2668 min

         11     2 4.0833e+007  0.2269 min
         11     3 7.5335e+007  0.1932
         11     4 3.2208e+007  0.2353 min
         11     6 2.3752e+007  0.2436 min
         11     7 2.0994e+007  0.2463 min
         11     8 4.7818e+006  0.2621 min
         11     9 8.2607e+006  0.2587
         11    11 1.3425e+007  0.2537
         11    12 1.8871e+007  0.2484
         11    13 3.5784e+006  0.2633 min

         10     2  3.947e+007  0.2247 min
         10     3 7.2626e+007  0.1923
         10     4  2.897e+007  0.2350 min
         10     6 2.2396e+007  0.2414 min
         10     7 1.8734e+007  0.2450 min
         10     8 4.7438e+006  0.2587 min
         10     9 8.8185e+006  0.2547
         10    11 1.0366e+007  0.2532
         10    12  1.638e+007  0.2473

          9     2 1.8992e+008  0.0730 min
          9     3 7.3379e+007  0.1870 min
          9     4 2.8502e+007  0.2308 min
          9     6 2.5381e+007  0.2339 min
          9     7 1.4043e+007  0.2450 min
          9     9 1.3625e+007  0.2454 min
          9    11 5.6644e+006  0.2531 min
          9    12 1.5764e+007  0.2433

          8     2 1.8436e+008  0.0729 min
          8     3 7.3891e+007  0.1809 min
          8     4 2.2897e+007  0.2308 min
          8     6 2.6814e+007  0.2269
          8     7 8.7055e+006  0.2446 min
          8     9 9.3843e+006  0.2440
          8    12 1.0108e+007  0.2433

          7     2 1.9348e+008  0.0555 min
          7     3 7.5359e+007  0.1710 min
          7     4 1.7932e+007  0.2271 min
          7     6  2.644e+007  0.2188
          7     9 9.7584e+006  0.2351 min
          7    12 8.2948e+006  0.2365 min

          6     2 1.9155e+008  0.0493 min
          6     3  7.663e+007  0.1616 min
          6     4   1.17e+007  0.2251 min
          6     6 3.1425e+007  0.2058
          6     9 2.1466e+007  0.2155

          5     2 1.8693e+008  0.0424 min
          5     3 7.7548e+007  0.1493 min
          5     6  3.258e+007  0.1932 min
          5     9 2.2907e+007  0.2027 min

          4     2 2.0575e+008  0.0016 min
          4     3  7.681e+007  0.1276 min
          4     6 3.0059e+007  0.1733 min

          3     2 1.7662e+008  0.0007 min
          3     3  6.448e+007  0.1103 min

          2     2 1.1281e+008  0.0000 min

Subset size        GRSq     RSq  DeltaGRSq nPreds  Terms (col nbr in bx)
          1      0.0000  0.0000     0.0000      0  1
          2      0.1060  0.1103     0.1060      1  1 2
          3      0.1653  0.1733     0.0593      2  1 2 3
          4      0.1911  0.2027     0.0258      3  1 2 3 6
          5      0.2100  0.2251     0.0189      4  1 2 3 6 9
          6      0.2179  0.2365     0.0079      5  1 2 3 4 6 9
          7      0.2225  0.2446     0.0045      5  1 2 3 4 6 9 12
          8      0.2275  0.2531     0.0050      5  1 2 3 4 6 7 9 12
          9      0.2295  0.2587     0.0020      5  1 2 3 4 6 7 9 11 12
chosen   10      0.2305  0.2633     0.0011      5  1 2 3 4 6 7 8 9 11 12
         11      0.2304  0.2668    -0.0001      5  1 2 3 4 6 7 8 9 11 12 13
         12      0.2293  0.2693    -0.0012      5  1 2 3 4 6 7 8 9 11 12 13 15
         13      0.2288  0.2724    -0.0005      5  1 2 3 4 6 7 8 9 11 12 13 14 15
         14      0.2270  0.2743    -0.0018      5  1 2 3 4 5 6 7 8 9 11 12 13 14 15
         15      0.2232  0.2743    -0.0038      5  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Prune backward penalty 3 nprune null: selected 10 of 15 terms, and 5 of 5 preds
After pruning pass GRSq 0.231 RSq 0.263

glm y[1046,1]:
     y1
1     1
2     2
3     1
...   2
1046  2

glm weights: NULL

GLM y1 devratio 0.32 dof 1036/1045 iters 2
glm y[1046,1]:
      y2
1    841
2      0
3      4
...  900
1046 841

glm weights: NULL

GLM y2 devratio 0.26 dof 1036/1045 iters 2
> cat("\nsummary(a12, details=TRUE)\n\n", sep="")

summary(a12, details=TRUE)

> print(summary(a12, details=TRUE))
Call: earth(formula=cbind(etitanic$sex,(as.integer(etitanic$age)^2))~.,
            data=etitanic, trace=4, glm=list(family="gaussian"), degree=2)

Earth coefficients
                                y1         y2
(Intercept)             1.87825514  1994.3477
pclass2nd              -0.03052777  -739.9866
pclass3rd              -0.24945083 -1666.0231
survived               -0.52605843  -320.9401
h(sibsp-1)              0.01497329  -177.7240
h(parch-1)             -0.09968178  -594.6399
h(parch-2)              0.04012795  1973.9441
pclass3rd * h(parch-2) -0.02275679 -2152.3800
pclass3rd * h(2-parch)  0.13019337   299.5782
pclass3rd * h(parch-1)  0.03601703  1047.1577

GLM coefficients
                                y1         y2
(Intercept)             1.87825514  1994.3477
pclass2nd              -0.03052777  -739.9866
pclass3rd              -0.24945083 -1666.0231
survived               -0.52605843  -320.9401
h(sibsp-1)              0.01497329  -177.7240
h(parch-1)             -0.09968178  -594.6399
h(parch-2)              0.04012795  1973.9441
pclass3rd * h(parch-2) -0.02275679 -2152.3800
pclass3rd * h(2-parch)  0.13019337   299.5782
pclass3rd * h(parch-1)  0.03601703  1047.1577

GLM y1 deviance residuals:
       Min          1Q      Median          3Q         Max  
-0.9041644  -0.3216689   0.1108089   0.1522726   0.9609189  

GLM y1 coefficients (family gaussian, link identity)
                          Estimate  Std. Error   t value Pr(>|t|)
(Intercept)             1.87825514  0.02962998  63.39037  < 2e-16
pclass3rd              -0.24945083  0.10625049  -2.34776 0.019074
pclass2nd              -0.03052777  0.03479059  -0.87747 0.380434
h(parch-2)              0.04012795  0.14694175   0.27309 0.784840
survived               -0.52605843  0.02717222 -19.36016  < 2e-16
pclass3rd * h(parch-2) -0.02275679  0.19924557  -0.11421 0.909090
pclass3rd * h(2-parch)  0.13019337  0.05510971   2.36244 0.018339
h(sibsp-1)              0.01497329  0.02397899   0.62443 0.532480
pclass3rd * h(parch-1)  0.03601703  0.13031139   0.27639 0.782302
h(parch-1)             -0.09968178  0.05886754  -1.69332 0.090695

GLM y1 dispersion parameter for gaussian family taken to be 0.1605338

GLM y2 deviance residuals:
       Min          1Q      Median          3Q         Max  
-1705.3478   -514.7814   -198.4811    297.5189   4726.5924  

GLM y2 coefficients (family gaussian, link identity)
                          Estimate  Std. Error  t value   Pr(>|t|)
(Intercept)             1994.34775    63.07215 31.62010 < 2.22e-16
pclass3rd              -1666.02307   226.17115 -7.36621 3.5776e-13
pclass2nd               -739.98661    74.05734 -9.99208 < 2.22e-16
h(parch-2)              1973.94408   312.78900  6.31078 4.1081e-10
survived                -320.94014    57.84041 -5.54872 3.6538e-08
pclass3rd * h(parch-2) -2152.38000   424.12604 -5.07486 4.5943e-07
pclass3rd * h(2-parch)   299.57821   117.30982  2.55374 0.01079967
h(sibsp-1)              -177.72401    51.04312 -3.48184 0.00051875
pclass3rd * h(parch-1)  1047.15774   277.38862  3.77506 0.00016906
h(parch-1)              -594.63992   125.30896 -4.74539 2.3728e-06

GLM y2 dispersion parameter for gaussian family taken to be 727409.6

GLM (family gaussian, link identity):
       nulldev   df         dev   df   devratio     AIC iters converged
y1 2.44077e+02 1045 1.66313e+02 1036      0.319    1067     2         1
y2 1.02296e+09 1045 7.53596e+08 1036      0.263   17100     2         1

Earth selected 10 of 15 terms, and 5 of 5 predictors
Termination condition: Reached nk 21
Importance: pclass3rd, pclass2nd, survived, sibsp, parch
Number of terms at each degree of interaction: 1 6 3

Earth
          GCV       RSS      GRSq       RSq
y1       0.17       166 0.2882848 0.3186029
y2  753952.19 753596300 0.2305416 0.2633195
All 753952.36 753596466 0.2305416 0.2633195
> stopifnot(identical(a12$coefficients, a12$glm.coefficients))
> 
> # test to see how standard model.matrix does column numbering with formula
> 
> my.x1 <- as.numeric(ToothGrowth[,2]) # supp was VC or OJ
> my.x2 <- as.numeric(ToothGrowth[,3]) # dose
> my.input.mat <- cbind(my.x1, my.x2)
> my.response <- ToothGrowth[,1]
> a13 <- earth(my.response~my.input.mat, trace=1)
x[60,2] with colnames my.input.matmy.x1 my.input.matmy.x2
y[60,1] with colname my.response, and values 4.2, 11.5, 7.3, 5.8, 6.4, 10,...
Forward pass term 1, 2, 4, 6
RSq changed by less than 0.001 at 5 terms, 4 terms used (DeltaRSq 0)
After forward pass GRSq 0.682 RSq 0.762
Prune backward penalty 2 nprune null: selected 4 of 4 terms, and 2 of 2 preds
After pruning pass GRSq 0.705 RSq 0.762
> print(summary(a13, details=TRUE))
Call: earth(formula=my.response~my.input.mat, trace=1)

                       coefficients
(Intercept)                  25.285
my.input.matmy.x1            -3.700
h(1-my.input.matmy.x2)      -18.260
h(my.input.matmy.x2-1)        6.365

Selected 4 of 4 terms, and 2 of 2 predictors
Termination condition: RSq changed by less than 0.001 at 4 terms
Importance: my.input.matmy.x2, my.input.matmy.x1
Number of terms at each degree of interaction: 1 3 (additive model)
GCV 17.52421    RSS 820.425    GRSq 0.7054941    RSq 0.7623478
> 
> stop.if.not.identical <- function(msg, a, b)
+ {
+     if(!identical(a, b)) {
+        cat(msg, "not identical\n")
+        cat(deparse(substitute(a)), ":\n", sep="")
+        print(a)
+        cat(deparse(substitute(b)), ":\n", sep="")
+        print(b)
+        stop("test failed")
+     }
+     cat(msg, "identical\n")
+ }
> 
> # some matrix interface tests
> 
> # double response glm model with two binomial paired cols
> SF.both <- cbind(SF, SF2)
> df <- data.frame(sex, ldose)
> expect.err(try(earth(SF.both ~ ., data=df, glm=list(family="binomial"), trace=1)), "Binomial response (see above): all values should be between 0 and 1, or a binomial pair")
x[12,2] with colnames sexmale ldose
y[12,4] with colnames numdead numalive numdead2 numalive2

print(head(y)):
     numdead numalive numdead2 numalive2
[1,]       1       19        2        18
[2,]       4       16        3        17
[3,]       9       11       10        10
[4,]      13        7       13         7
[5,]      18        2       19         1
[6,]      20        0       20         0

Error : Binomial response (see above): all values should be between 0 and 1, or a binomial pair
Got error as expected from try(earth(SF.both ~ ., data = df, glm = list(family = "binomial"),     trace = 1))
> 
> # --- predict with factors ------------------------------------------------------
> 
> # there is a lot of redundancy in this routine, it doesn't really matter
> 
> test.predict.with.factors <- function(trace)
+ {
+     cat("\n--- predict with single level factors and a single response, trace=", trace,
+         " ---\n\n", sep="")
+ 
+     cat("first do a quick test of predict.earth help page example\n")
+     a <- earth(Volume ~ ., data = trees)
+     if (trace) print(head(predict(a, trace=trace)))
+     if (trace) print(predict(a, c(10,80), trace=trace))
+ 
+     # test set A: prepare the data
+ 
+     ldose  <- rep(0:5, 2) - 2
+     # ldose1 <- c(0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 0.3, 1.4, 2.5, 3.6, 4.7, 5.8)
+     ldose1 <- c(0.1, 1.2, 0.1, 1.2, 1.0, 0.1, 0.3, 1.4, 0.1, 1.2, 0.1, 0.9)
+     sex <- factor(rep(c("male", "female"), times=c(6,6)))
+     numdead <- c(1,4,9,13,18,20,0,2,6,10,12,16)
+ 
+     sexmale <- (sex == "male")
+     am <-  earth(cbind(sexmale, ldose, ldose1), numdead, trace=trace, pmethod=PMETHOD, nk=NK, degree=2)
+     af <-  earth(numdead ~ sex + ldose + ldose1, trace=trace, pmethod=PMETHOD, nk=NK, degree=2)
+     check.models.equal(am, af, "predict with single level factors and a single response")
+ 
+     cat("A-20m head(predict(am, trace=", trace, ")\n", sep="")
+     pm <- predict(am, trace=trace)
+     if (trace) print(head(pm))
+ 
+     cat("A-20f head(predict(af, trace=", trace, ")\n", sep="")
+     pf <- predict(af, trace=trace)
+     if (trace) print(head(pf))
+     stop.if.not.identical("A-20", pm, pf)
+ 
+     cat("A-21m predict(am, newdata=c(sex[1], -2, 0.1), trace=", trace, "))\n", sep="")
+     pm <- predict(am, newdata=c(sex[1]=="male", -2, 0.1), trace=trace)
+     pm.ref <- pm
+     if (trace) print(pm)
+ 
+     cat("A-21f predict(af, newdata=c(sex[1], -2, 0.1), trace=", trace, "))\n", sep="")
+     pf <- predict(af, newdata=c(sex[1]=="male", -2, 0.1), trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("A-21", pm.ref, pf)
+ 
+     cat("A-22m predict(am, newdata=c(1, -2, 0.1), trace=", trace, ")) use numeric instead of factor sex\n", sep="")
+     pm <- predict(am, newdata=c(1, -2, 0.1), trace=trace)
+     if (trace) print(pm)
+     stop.if.not.identical("A-22", pm.ref, pm)
+ 
+     cat("A-22f predict(af, newdata=c(1, -2, 0.1), trace=", trace, ")) use numeric instead of factor sex\n", sep="")
+     pf <- predict(af, newdata=c(1, -2, 0.1), trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("A-22", pm, pf)
+ 
+     cat("A-23m predict(am, newdata=c(sex[1], sex[1], -2, -2, 0.1, 0.1), trace=", trace, ")) multiple rows as a vec\n", sep="")
+     pm <- predict(am, newdata=c(sex[1], sex[1], -2, -2, 0.1, 0.1), trace=trace)
+     if (trace) print(pm)
+ 
+     cat("A-23f predict(af, newdata=c(sex[1], sex[1], -2, -2, 0.1, 0.1), trace=", trace, ")) multiple rows as a vec\n", sep="")
+     pf <- predict(af, newdata=c(sex[1], sex[1], -2, -2, 0.1, 0.1), trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("A-23", pm, pf)
+ 
+     cat("A-24m predict(am, newdata=c(sex[1], sex[1], -2, -1, 0.1, 0.1), trace=", trace, ")) more multiple rows as a vec\n", sep="")
+     pm <- predict(am, newdata=c(sex[1], sex[1], -2, -1, 0.1, 0.1), trace=trace)
+     if (trace) print(pm)
+     pm2.ref <- pm
+ 
+     cat("A-24f predict(af, newdata=c(sex[1], sex[1], -2, -1, 0.1, 0.1), trace=", trace, ")) more multiple rows as a vec\n", sep="")
+     pf <- predict(af, newdata=c(sex[1], sex[1], -2, -1, 0.1, 0.1), trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("A-24", pm, pf)
+ 
+     cat("A-25m predict(am, xpredict matrix trace=", trace, "\n", sep="")
+     new.data <- matrix(c(sex[1], sex[1], -2, -1, 0.1, 0.1), nrow=2)
+     pm <- predict(am, newdata=new.data, trace=trace)
+     if (trace) print(pm)
+     stop.if.not.identical("A-25", pm2.ref, pm)
+ 
+     cat("A-25f predict(af, xpredict matrix trace=", trace, "\n", sep="")
+     pf <- predict(af, newdata=new.data, trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("A-25", pm, pf)
+ 
+     cat("A-26m predict(am, new.data with col names) trace=", trace, "\n", sep="")
+     new.data <- matrix(c(sex[1], sex[1], -2, -1, 0.1, 0.1), nrow=2)
+     colnames(new.data) <- c("sex", "ldose", "ldose1")
+     pm <- predict(am, newdata=new.data, trace=trace)
+     if (trace) print(pm)
+     stop.if.not.identical("A-26m", pm2.ref, pm)
+ 
+     cat("A-26f predict(af, new.data with col names) trace=", trace, "\n", sep="")
+     pf <- predict(af, newdata=new.data, trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("A-26f", pm, pf)
+ 
+     cat("A-27m predict(am, new.data with out of order col names) trace=", trace, "\n", sep="")
+     new.data <- matrix(c(sex[1], sex[1], 0.1, 0.1, -2, -1), nrow=2)
+     colnames(new.data) <- c("sex", "ldose1", "ldose")
+     pm <- predict(am, newdata=new.data, trace=trace)
+     if (trace) print(pm)
+     stop.if.not.identical("A-27", pm2.ref, pm)
+ 
+     cat("A-27f predict(af, new.data with out of order col names) trace=", trace, "\n", sep="")
+     pf <- predict(af, newdata=new.data, trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("A-27", pm, pf)
+ 
+     cat("A-28m predict(am, xdata.frame without col names) trace=", trace, "\n", sep="")
+     if (trace) print(pm)
+     stop.if.not.identical("A-28", pm2.ref, pm)
+ 
+     cat("A-28f predict(af, xdata.frame without col names) trace=", trace, "\n", sep="")
+     xdata.frame <- data.frame(c(sex[1], sex[1]), c(-2, -1), c(0.1, 0.1))
+     pf <- predict(af, xdata.frame, trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("A-28", pm, pf)
+ 
+     cat("A-29m predict(am, xdata.frame with col names) trace=", trace, "\n", sep="")
+     xdata.frame.29 <- data.frame(sex[1], -2, 0.1)
+     colnames(xdata.frame.29) <- c("sex", "ldose", "ldose1")
+     pm <- predict(am, xdata.frame.29, trace=trace)
+     if (trace) print(pm)
+     stop.if.not.identical("A-29", pm.ref, pm)
+ 
+     cat("A-29f predict(af, xdata.frame with col names) trace=", trace, "\n", sep="")
+     pf <- predict(af, xdata.frame.29, trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("A-29", pm, pf)
+ 
+     cat("A2-29m predict(am, xdata.frame with col names) trace=", trace, "\n", sep="")
+     xdata.frame.29.2 <- data.frame(c(sex[1], sex[1]), c(-2, -1), c(0.1, 0.1))
+     colnames(xdata.frame.29.2) <- c("sex", "ldose", "ldose1")
+     pm <- predict(am, xdata.frame.29.2, trace=trace)
+     if (trace) print(pm)
+     stop.if.not.identical("A2-29", pm2.ref, pm)
+ 
+     cat("A2-29f predict(af, xdata.frame with col names) trace=", trace, "\n", sep="")
+     pf <- predict(af, xdata.frame.29.2, trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("A2-29", pm, pf)
+ 
+     cat("A-31m predict(am, xdata.frame, trace=", trace, ") data frame with factors and wrong col names\n", sep="")
+     xdata.frame <- data.frame(sex[1], -2, 0.1)
+     pm <- predict(am, xdata.frame, trace=trace)
+     stop.if.not.identical("A-31", pm.ref, pm)
+     if (trace) print(pm)
+ 
+     cat("A-31f predict(af, xdata.frame, trace=", trace, ") data frame with factors and wrong col names\n", sep="")
+     pf <- predict(af, xdata.frame, trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("A-31", pm, pf)
+ 
+     cat("A-31bm predict(am, xdata.frame, trace=", trace, ") data frame col names\n", sep="")
+     xdata.frame <- data.frame(sex=sex[1], ldose=-2, ldose1=0.1)
+     pm <- predict(am, xdata.frame, trace=trace)
+     if (trace) print(pm)
+     stop.if.not.identical("A-31", pm.ref, pm)
+ 
+     cat("A-31bf predict(af, xdata.frame, trace=", trace, ") data frame col names\n", sep="")
+     pf <- predict(af, xdata.frame, trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("A-31b", pm, pf)
+ 
+     cat("A-32m predict(am, xdata.frame, trace=", trace, ") # data frame with names\n", sep="")
+     xdata.frame <- data.frame(sex[1], -2, 0.1)
+     colnames(xdata.frame) <- c("sex", "ldose", "ldose1")
+     pm <- predict(am, xdata.frame, trace=trace)
+     if (trace) print(pm)
+     stop.if.not.identical("A-32", pm, pf)
+     stop.if.not.identical("A-32", pm.ref, pm)
+ 
+     cat("A-32f predict(af, xdata.frame, trace=", trace, ") # data frame with names\n", sep="")
+     pf <- predict(af, xdata.frame, trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("A-32", pm, pf)
+ 
+     cat("A-42am predict(am, newdata=c(1, -2, 0.1), trace=", trace, ")) use numeric instead of factor sex\n", sep="")
+     pm <- predict(am, newdata=c(1, -2, 0.1), trace=trace)
+     if (trace) print(pm)
+     stop.if.not.identical("A-42a", pm.ref, pm)
+ 
+     cat("A-42af predict(af, newdata=c(1, -2, 0.1), trace=", trace, ")) use numeric instead of factor sex\n", sep="")
+     pf <- predict(af, newdata=c(1, -2, 0.1), trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("A-42a", pm, pf)
+ 
+     cat("A-43am predict(af, newdata=c(sex[1], sex[1], -2, -2, 0.1, 0.1), trace=", trace, ")) multiple rows as a vec\n", sep="")
+     pm <- predict(af, newdata=c(sex[1], sex[1], -2, -2, 0.1, 0.1), trace=trace)
+     if (trace) print(pm)
+ 
+     cat("A-43af predict(am, newdata=c(sex[1], sex[1], -2, -2, 0.1, 0.1), trace=", trace, ")) multiple rows as a vec\n", sep="")
+     pf <- predict(am, newdata=c(sex[1], sex[1], -2, -2, 0.1, 0.1), trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("A-43a", pm, pf)
+ 
+     cat("A-44am predict(af, newdata=c(sex[1], sex[1], -2, -1, 0.1, 0.1), trace=", trace, ")) more multiple rows as a vec\n", sep="")
+     pm <- predict(af, newdata=c(sex[1], sex[1], -2, -1, 0.1, 0.1), trace=trace)
+     if (trace) print(pm)
+     stop.if.not.identical("A-44a", pm2.ref, pm)
+ 
+     cat("A-44fm predict(am, newdata=c(sex[1], sex[1], -2, -1, 0.1, 0.1), trace=", trace, ")) more multiple rows as a vec\n", sep="")
+     pf <- predict(am, newdata=c(sex[1], sex[1], -2, -1, 0.1, 0.1), trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("A-44f", pm, pf)
+ 
+     cat("A-53m predict(am, xdata.frame, trace=", trace, ") data frame with not enough columns, expect error message\n", sep="")
+     xdata.frame <- data.frame(sex[1], -2)
+     expect.err(try(predict(am, xdata.frame, trace=trace)), "expected 3")
+ 
+     cat("A-53f predict(af, xdata.frame, trace=", trace, ") data frame with not enough columns, expect error message\n", sep="")
+     xdata.frame <- data.frame(sex[1], -2)
+     expect.err(try(predict(af, xdata.frame, trace=trace)), "expected 3")
+ 
+     cat("A-54m predict(am, xdata.frame, trace=", trace, ") # data frame with cols in different order\n", sep="")
+     xdata.frame <- data.frame(-2, sex[1], 0.1)
+     colnames(xdata.frame) <- c("ldose", "sex", "ldose1")
+     pm <- predict(am, xdata.frame, trace=trace)
+     if (trace) print(pm)
+     stop.if.not.identical("A-54", pm.ref, pm)
+ 
+     cat("A-54f predict(af, xdata.frame, trace=", trace, ") # data frame with cols in different order\n", sep="")
+     pf <- predict(af, xdata.frame, trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("A-54", pm, pf)
+ 
+     cat("A-55m predict(am, xdata.frame, trace=", trace, ") data frame without col names\n", sep="")
+     xdata.frame <- data.frame(sex[c(1,7)], c(-2,-1), c(0.1, 0.1))
+     pm <- predict(am, xdata.frame, trace=trace)
+     pm3.ref <- pm
+     if (trace) print(pm)
+ 
+     cat("A-55f predict(af, xdata.frame, trace=", trace, ") data frame without col names\n", sep="")
+     pf <- predict(af, xdata.frame, trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("A-55", pm, pf)
+ 
+     cat("A-56m predict(am, xdata.frame, trace=", trace, ") # data frame with col names\n", sep="")
+     xdata.frame <- data.frame(sex[c(1,7)], c(-2,-1), c(0.1, 0.1))
+     colnames(xdata.frame) <- c("sex", "ldose", "ldose1")
+     pm <- predict(am, xdata.frame, trace=trace)
+     if (trace) print(pm)
+     stop.if.not.identical("A-56", pm3.ref, pm)
+ 
+     cat("A-56f predict(af, xdata.frame, trace=", trace, ") # data frame with col names\n", sep="")
+     pf <- predict(af, xdata.frame, trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("A-56", pm, pf)
+ 
+     cat("A-57m predict(am, xdata.frame, trace=", trace, ") data frame with not enough columns, expect error message\n", sep="")
+     xdata.frame <- data.frame(sex[c(1,7)], c(-2,-1))
+     expect.err(try(predict(am, xdata.frame, trace=trace)), "expected 3")
+ 
+     cat("A-57f predict(af, xdata.frame, trace=", trace, ") data frame with not enough columns, expect error message\n", sep="")
+     expect.err(try(predict(af, xdata.frame, trace=trace)), "expected 3")
+     stop.if.not.identical("A-57", pm, pf)
+ 
+     cat("A-58m predict(am, xdata.frame, trace=", trace, ") # data frame with cols in different order\n", sep="")
+     xdata.frame <- data.frame(c(-2,-1), sex[c(1,7)], c(0.1, 0.1))
+     colnames(xdata.frame) <- c("ldose", "sex", "ldose1")
+     pm <- predict(am, xdata.frame, trace=trace)
+     if (trace) print(pm)
+     stop.if.not.identical("A-58", pm3.ref, pm)
+ 
+     cat("A-58f predict(af, xdata.frame, trace=", trace, ") # data frame with cols in different order\n", sep="")
+     pf <- predict(af, xdata.frame, trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("A-58", pm, pf)
+ 
+     cat("A-59m predict(am, xdata.frame, trace=", trace, ") numeric where factor expected, expect forge on message\n", sep="")
+     xdata.frame.39 <- data.frame(c(sex[1], sex[7]), c(-2,-1), c(0.1, 0.1))
+     colnames(xdata.frame.39) <- c("sex", "ldose", "ldose1")
+     pm <- predict(am, xdata.frame.39, trace=trace)
+     if (trace) print(pm)
+     # stop.if.not.identical("A-59", pm3.ref, pm) # TODO fails but "forge on" message is correctly issued
+ 
+     cat("A-59f predict(af, xdata.frame, trace=", trace, ") numeric where factor expected, expect forge on message\n", sep="")
+     pf <- predict(af, xdata.frame.39, trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("A-59", pm, pf)
+ 
+     cat("A-50m data frame without column names, trace=", trace, "\n", sep="")
+     xdata.frame <- data.frame(sex[1], -2, 0.1)
+     colnames(xdata.frame) <- NULL
+     pm <- predict(am, xdata.frame, trace=trace)
+     if (trace) print(pm)
+     stop.if.not.identical("A-34", pm.ref, pm)
+ 
+     cat("A-60f data frame without column names, trace=", trace, "\n", sep="")
+     xdata.frame <- data.frame(sex[1], -2, 0.1)
+     colnames(xdata.frame) <- NULL
+     pf <- predict(am, xdata.frame, trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("A-60", pm, pf)
+ 
+     cat("A-61f data frame without extra columns, trace=", trace, "\n", sep="")
+     xdata.frame <- data.frame(sex=sex[1], extra1=99, ldose=-2, extra2=99, ldose1=0.1, extra3=sex[7])
+     pf <- predict(af, xdata.frame, trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("A-61", pm, pf)
+ 
+     #-----------------------------------
+ 
+     my.x1 <- as.numeric(ToothGrowth[,2]) # supp was VC or OJ
+     my.x2 <- as.numeric(ToothGrowth[,3]) # dose
+     my.input.mat <- cbind(my.x1, my.x2)
+     my.response <- ToothGrowth[,1]
+ 
+     cat("A-68 input matrix to formula interface trace=", trace, ", expect error \"could not interpret\"\n", sep="")
+     a41 <- earth(my.response~my.input.mat, trace=trace)
+     expect.err(try(predict(a41, c(2.1, 0.6), trace=trace)), "could not interpret the data")
+ 
+     cat("A-69 above test but with properly named dataframe trace=", trace, "\n", sep="")
+     df <- data.frame(growth=my.response, supp=my.x1, dose=my.x2)
+     a42 <- earth(formula=growth~., data=df, trace=0)
+     p <- predict(a42, c(2.1, 0.6), trace=0) # now gives the correct result
+     if (trace) print(head(p))
+ 
+     cat("Tests with not all predictors used in the model so can pass fewer columns\n")
+     # No factor tests done, they probably won't work in this setup.
+ 
+     # first for earth.default
+     dummy <- rep(0, 12)
+     am <-  earth(cbind(ldose, dummy, ldose1), numdead, trace=trace, pmethod=PMETHOD, nk=NK, degree=2)
+     # prepare reference prediction, using all columns
+     newdata <- matrix(c(-2, 0, 0.1), ncol=3, nrow=1)
+     colnames(newdata) <- c("ldose", "dummy", "ldose1")
+     pm.ref <- predict(am, newdata=newdata, trace=trace)
+     if (trace) print(pm.ref)
+ 
+     cat("A-72m predict(am, newdata=newdata[two columns], trace=trace)\n")
+     newdata <- matrix(c(-2, 0.1), ncol=2, nrow=1)
+     colnames(newdata) <- c("ldose", "ldose1")
+     pm <- predict(am, newdata=newdata, trace=trace)
+     if (trace) print(pm)
+     stop.if.not.identical("A-72m", pm, pm.ref)
+ 
+     # prepare reference prediction, using all columns
+     newdata <- data.frame(cbind(ldose, dummy, ldose1))
+     print(newdata)
+     pm.ref <- predict(am, newdata=newdata, trace=trace)
+     if (trace) print(pm.ref)
+ 
+     cat("A-73m predict(am, newdata=newdata[two columns], trace=trace)\n")
+     newdata <- newdata[, c(1,3)]
+     pm <- predict(am, newdata=newdata, trace=trace)
+     if (trace) print(pm)
+     stop.if.not.identical("A-73m", pm, pm.ref)
+ 
+     # now for earth.formula
+     dummy <- rep(0, 12)
+     af <-  earth(numdead ~ ldose + dummy + ldose1, trace=trace, pmethod=PMETHOD, nk=NK, degree=2)
+     # prepare reference prediction, using all columns
+     newdata <- matrix(c(-2, 0, 0.1), ncol=3, nrow=1)
+     colnames(newdata) <- c("ldose", "dummy", "ldose1")
+     newdata <- as.data.frame(newdata)
+     pf.ref <- predict(af, newdata=newdata, trace=trace)
+     if (trace) print(pf.ref)
+ 
+     cat("A-72f predict(af, newdata=newdata[two columns], trace=trace)\n")
+     newdata <- matrix(c(-2, 0.1), ncol=2, nrow=1)
+     colnames(newdata) <- c("ldose", "ldose1")
+     newdata <- as.data.frame(newdata)
+     pf <- predict(af, newdata=newdata, trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("A-72f", pf, pf.ref)
+ 
+     # prepare reference prediction, using all columns
+     newdata <- data.frame(cbind(ldose, dummy, ldose1))
+     print(newdata)
+     pf.ref <- predict(af, newdata=newdata, trace=trace)
+     if (trace) print(pf.ref)
+ 
+     cat("A-73f predict(af, newdata=newdata[two columns], trace=trace)\n")
+     newdata <- newdata[, c(1,3)]
+     pf <- predict(af, newdata=newdata, trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("A-73f", pf, pf.ref)
+ 
+     cat("\n--- B predict with multiple level factors and a multiple real response, trace=", trace,
+         " ---\n\n", sep="")
+ 
+     # note that we can no now longer get away with using numerics for
+     # factors because factors have more than two levels
+ 
+     # test set B: prepare the data
+ 
+     ldose  <- rep(0:5, 2) - 2
+     ldose1 <- c(0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 0.3, 1.4, 2.5, 3.6, 4.7, 5.8)
+     sex3 <- factor(rep(c("male", "female", "andro"), times=c(6,4,2)))
+     fac3 <- factor(c("lev2", "lev2", "lev1", "lev1", "lev3", "lev3",
+                      "lev2", "lev2", "lev1", "lev1", "lev3", "lev3"))
+     numdead <- c(1,4,9,13,18,20,0,2,6,10,12,16)
+     numdead2 <- c(2,3,10,13,19,20,0,3,7,11,13,17)
+     numdeadboth <- cbind(numdead, numdead2)
+     isex <- as.double(sex3) # sex3 as an index
+     df <- data.frame(sex3, ldose, ldose1, fac3)
+     am <-  earth(df, numdeadboth, trace=trace, pmethod=PMETHOD, nk=NK, degree=2)
+     af <-  earth(numdeadboth ~ ., data=df, trace=trace, pmethod=PMETHOD, nk=NK, degree=2)
+     check.models.equal(am, af, "B predict with multiple level factors and a multiple real response")
+     cat("20m head(predict(am, trace=", trace, ")\n", sep="")
+     pm <- predict(am, trace=trace)
+     if (trace) print(head(pm))
+ 
+     cat("B-21f head(predict(af, trace=", trace, ")\n", sep="")
+     pf <- predict(af, trace=trace)
+     if (trace) print(head(pf))
+     stop.if.not.identical("B-20", pm, pf)
+ 
+     cat("B-31m predict(am, xdata.frame, trace=", trace, ") data frame with factors and wrong col names\n", sep="")
+     xdata.frame <- data.frame(sex3[1], -2, 0.1, fac3[1])
+     pm <- predict(am, xdata.frame, trace=trace)
+     pm.ref <- pm
+     stop.if.not.identical("B-31", pm.ref, pm)
+     if (trace) print(pm)
+ 
+     cat("B-31f predict(af, xdata.frame, trace=", trace, ") data frame with factors and wrong col names\n", sep="")
+     pf <- predict(af, xdata.frame, trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("B-31", pm, pf)
+ 
+     cat("B-31bm predict(am, xdata.frame, trace=", trace, ") data frame col names\n", sep="")
+     xdata.frame <- data.frame(sex3=sex3[1], ldose=-2, ldose1=0.1, fac3=fac3[1])
+     pm <- predict(am, xdata.frame, trace=trace)
+     if (trace) print(pm)
+     stop.if.not.identical("B-31", pm.ref, pm)
+ 
+     cat("B-31bf predict(af, xdata.frame, trace=", trace, ") data frame col names\n", sep="")
+     pf <- predict(af, xdata.frame, trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("B-31b", pm, pf)
+ 
+     cat("B-32m predict(am, xdata.frame, trace=", trace, ") # data frame with names\n", sep="")
+     xdata.frame <- data.frame(sex3[1], -2, 0.1, fac3[1])
+     colnames(xdata.frame) <- c("sex3", "ldose", "ldose1", "fac3")
+     pm <- predict(am, xdata.frame, trace=trace)
+     if (trace) print(pm)
+     stop.if.not.identical("B-32", pm, pf)
+     stop.if.not.identical("B-32", pm.ref, pm)
+ 
+     cat("B-32f predict(af, xdata.frame, trace=", trace, ") # data frame with names\n", sep="")
+     pf <- predict(af, xdata.frame, trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("B-32", pm, pf)
+ 
+     cat("B-53m predict(am, xdata.frame, trace=", trace, ") data frame with not enough columns, expect error message\n", sep="")
+     xdata.frame <- data.frame(sex3[1], -2)
+     expect.err(try(predict(am, xdata.frame, trace=trace)), "get.earth.x from model.matrix.earth from predict.earth: x has 2 columns but expected 4")
+ 
+     cat("B-53f predict(af, xdata.frame, trace=", trace, ") data frame with not enough columns, expect error message\n", sep="")
+     expect.err(try(predict(af, xdata.frame, trace=trace)), "get.earth.x from model.matrix.earth from predict.earth: x has 2 columns but expected 4")
+ 
+     cat("B-54m predict(am, xdata.frame, trace=", trace, ") # data frame with cols in different order\n", sep="")
+     xdata.frame <- data.frame(-2, sex3[1], 0.1, fac3[1])
+     colnames(xdata.frame) <- c("ldose", "sex3", "ldose1", "fac3")
+     pm <- predict(am, xdata.frame, trace=trace)
+     if (trace) print(pm)
+     stop.if.not.identical("B-54", pm.ref, pm)
+ 
+     cat("B-54f predict(af, xdata.frame, trace=", trace, ") # data frame with cols in different order\n", sep="")
+     pf <- predict(af, xdata.frame, trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("B-54", pm, pf)
+ 
+     cat("B-55m predict(am, xdata.frame, trace=", trace, ") data frame without col names\n", sep="")
+     xdata.frame <- data.frame(sex3[c(1,7)], c(-2,-1), c(0.1, 0.1), fac3[c(1,9)])
+     pm <- predict(am, xdata.frame, trace=trace)
+     pm3.ref <- pm
+     if (trace) print(pm)
+     cat("B-55m again, but with same x data for both reponses\n")
+     xdata.frame <- data.frame(sex3[c(1,1)], c(-2,-2), c(0.1, 0.1), fac3[c(1,1)])
+     pm <- predict(am, xdata.frame, trace=trace)
+     print(pm)
+ 
+     cat("B-55f predict(af, xdata.frame, trace=", trace, ") data frame without col names\n", sep="")
+     pf <- predict(af, xdata.frame, trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("B-55", pm, pf)
+ 
+     cat("B2-55bm predict(am, xdata.frame, trace=", trace, ") data frame col names\n", sep="")
+     xdata.frame <- data.frame(sex3=sex3[c(1,7)], ldose=c(-2,-1), ldose1=c(0.1,0.1), fac3=fac3[c(1,9)])
+     pm <- predict(am, xdata.frame, trace=trace)
+     if (trace) print(pm)
+     stop.if.not.identical("B2-55", pm3.ref, pm)
+ 
+     cat("B2-55bf predict(af, xdata.frame, trace=", trace, ") data frame col names\n", sep="")
+     pf <- predict(af, xdata.frame, trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("B2-55b", pm, pf)
+ 
+     cat("B-56m predict(am, xdata.frame, trace=", trace, ") # data frame with col names\n", sep="")
+     xdata.frame <- data.frame(sex3[c(1,7)], c(-2,-1), c(0.1, 0.1), fac3[c(1,9)])
+     colnames(xdata.frame) <- c("sex3", "ldose", "ldose1", "fac3")
+     pm <- predict(am, xdata.frame, trace=trace)
+     if (trace) print(pm)
+     stop.if.not.identical("B-56", pm3.ref, pm)
+ 
+     cat("B-56f predict(af, xdata.frame, trace=", trace, ") # data frame with col names\n", sep="")
+     pf <- predict(af, xdata.frame, trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("B-56", pm, pf)
+ 
+     cat("B-57m predict(am, xdata.frame, trace=", trace, ") data frame with not enough columns, expect error message\n", sep="")
+     xdata.frame <- data.frame(sex3[c(1,7)], c(-2,-1))
+     expect.err(try(predict(am, xdata.frame, trace=trace)), "get.earth.x from model.matrix.earth from predict.earth: x has 2 columns but expected 4")
+ 
+     cat("B-57f predict(af, xdata.frame, trace=", trace, ") data frame with not enough columns, expect error message\n", sep="")
+     expect.err(try(predict(af, xdata.frame, trace=trace)), "get.earth.x from model.matrix.earth from predict.earth: x has 2 columns but expected 4")
+     stop.if.not.identical("B-57", pm, pf)
+ 
+     cat("B-58m predict(am, xdata.frame, trace=", trace, ") # data frame with cols in different order\n", sep="")
+     xdata.frame <- data.frame(c(-2,-1), sex3[c(1,7)], c(0.1, 0.1),  fac3[c(1,9)])
+     colnames(xdata.frame) <- c("ldose", "sex3", "ldose1", "fac3")
+     pm <- predict(am, xdata.frame, trace=trace)
+     if (trace) print(pm)
+     stop.if.not.identical("B-58", pm3.ref, pm)
+ 
+     cat("B-58f predict(af, xdata.frame, trace=", trace, ") # data frame with cols in different order\n", sep="")
+     pf <- predict(af, xdata.frame, trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("B-58", pm, pf)
+ 
+     cat("B-50m data frame without column names, trace=", trace, "\n", sep="")
+     xdata.frame <- data.frame(sex3[1], -2, 0.1, fac3[1])
+     colnames(xdata.frame) <- NULL
+     pm <- predict(am, xdata.frame, trace=trace)
+     if (trace) print(pm)
+     stop.if.not.identical("B-34", pm.ref, pm)
+ 
+     cat("B-60f data frame without column names, trace=", trace, "\n", sep="")
+     xdata.frame <- data.frame(sex3[1], -2, 0.1, fac3[1])
+     colnames(xdata.frame) <- NULL
+     pf <- predict(am, xdata.frame, trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("B-60", pm, pf)
+ 
+     cat("B-60f data frame without extra columns, trace=", trace, "\n", sep="")
+     xdata.frame <- data.frame(sex3=sex3[1], extra1=99, ldose=-2, extra2=99,
+                                ldose1=0.1, fac3=fac3[1], extra3=sex3[7])
+     pf <- predict(af, xdata.frame, trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("B-60f", pm, pf)
+ 
+     cat("\n--- C predict with multiple level factors and a 3 level factor response, trace=", trace,
+         " ---\n\n", sep="")
+ 
+     # test set C: prepare the data
+ 
+     ldose  <- rep(0:5, 2) - 2
+     ldose1 <- c(0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 0.3, 1.4, 2.5, 3.6, 4.7, 5.8)
+     sex3 <- factor(rep(c("male", "female", "andro"), times=c(6,4,2)))
+     fac3 <- factor(c("lev2", "lev2", "lev1", "lev1", "lev3", "lev3",
+                      "lev2", "lev2", "lev1", "lev1", "lev3", "lev3"))
+     facdead <- factor(c("dead2", "dead2", "dead3", "dead1", "dead3", "dead3",
+                         "dead1", "dead2", "dead1", "dead1", "dead3", "dead3"))
+ 
+     isex <- as.double(sex3) # sex3 as an index
+     df <- data.frame(sex3=sex3, ldose=ldose, ldose1=ldose1, fac3=fac3)
+     am <-  earth(df, facdead, trace=trace, pmethod=PMETHOD, nk=NK, degree=2)
+     df.with.response <- data.frame(sex3=sex3, ldose=ldose, ldose1=ldose1, facdead=facdead, fac3=fac3)
+     af <-  earth(facdead ~ ., data=df.with.response, trace=trace, pmethod=PMETHOD, nk=NK, degree=2)
+     check.models.equal(am, af, "C predict with multiple level factors and a multiple real response")
+     cat("20m head(predict(am, trace=", trace, ")\n", sep="")
+     pm <- predict(am, trace=trace)
+     if (trace) print(head(pm))
+ 
+     cat("C-21f head(predict(af, trace=", trace, ")\n", sep="")
+     pf <- predict(af, trace=trace)
+     if (trace) print(head(pf))
+     stop.if.not.identical("C-20", pm, pf)
+ 
+     cat("C-31m predict(am, xdata.frame, trace=", trace, ") data frame with factors and wrong col names\n", sep="")
+     xdata.frame <- data.frame(sex3[1], -2, 0.1, fac3[1])
+     pm <- predict(am, xdata.frame, trace=trace)
+     pm.ref <- pm
+     stop.if.not.identical("C-31", pm.ref, pm)
+     if (trace) print(pm)
+ 
+     cat("C-31f predict(af, xdata.frame, trace=", trace, ") data frame with factors and wrong col names\n", sep="")
+     pf <- predict(af, xdata.frame, trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("C-31", pm, pf)
+ 
+     cat("C-31bm predict(am, xdata.frame, trace=", trace, ") data frame col names\n", sep="")
+     xdata.frame <- data.frame(sex3=sex3[1], ldose=-2, ldose1=0.1, fac3=fac3[1])
+     pm <- predict(am, xdata.frame, trace=trace)
+     if (trace) print(pm)
+     stop.if.not.identical("C-31", pm.ref, pm)
+ 
+     cat("C-31bf predict(af, xdata.frame, trace=", trace, ") data frame col names\n", sep="")
+     pf <- predict(af, xdata.frame, trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("C-31b", pm, pf)
+ 
+     cat("C-32m predict(am, xdata.frame, trace=", trace, ") # data frame with names\n", sep="")
+     xdata.frame <- data.frame(sex3[1], -2, 0.1, fac3[1])
+     colnames(xdata.frame) <- c("sex3", "ldose", "ldose1", "fac3")
+     pm <- predict(am, xdata.frame, trace=trace)
+     if (trace) print(pm)
+     stop.if.not.identical("C-32", pm, pf)
+     stop.if.not.identical("C-32", pm.ref, pm)
+ 
+     cat("C-32f predict(af, xdata.frame, trace=", trace, ") # data frame with names\n", sep="")
+     pf <- predict(af, xdata.frame, trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("C-32", pm, pf)
+ 
+     cat("C-53m predict(am, xdata.frame, trace=", trace, ") data frame with not enough columns, expect error message\n", sep="")
+     xdata.frame <- data.frame(sex3[1], -2)
+     expect.err(try(predict(am, xdata.frame, trace=trace)), "get.earth.x from model.matrix.earth from predict.earth: x has 2 columns but expected 4")
+ 
+     cat("C-53f predict(af, xdata.frame, trace=", trace, ") data frame with not enough columns, expect error message\n", sep="")
+     expect.err(try(predict(af, xdata.frame, trace=trace)), "get.earth.x from model.matrix.earth from predict.earth: x has 2 columns but expected 4")
+ 
+     cat("C-54m predict(am, xdata.frame, trace=", trace, ") # data frame with cols in different order\n", sep="")
+     xdata.frame <- data.frame(-2, sex3[1], 0.1, fac3[1])
+     colnames(xdata.frame) <- c("ldose", "sex3", "ldose1", "fac3")
+     pm <- predict(am, xdata.frame, trace=trace)
+     if (trace) print(pm)
+     stop.if.not.identical("C-54", pm.ref, pm)
+ 
+     cat("C-54f predict(af, xdata.frame, trace=", trace, ") # data frame with cols in different order\n", sep="")
+     pf <- predict(af, xdata.frame, trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("C-54", pm, pf)
+ 
+     cat("C-55m predict(am, xdata.frame, trace=", trace, ") data frame without col names\n", sep="")
+     xdata.frame <- data.frame(sex3[c(1,7)], c(-2,-1), c(0.1, 0.1), fac3[c(1,9)])
+     pm <- predict(am, xdata.frame, trace=trace)
+     pm3.ref <- pm
+     if (trace) print(pm)
+ 
+     cat("C-55f predict(af, xdata.frame, trace=", trace, ") data frame without col names\n", sep="")
+     pf <- predict(af, xdata.frame, trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("C-55", pm, pf)
+ 
+     cat("C2-55bm predict(am, xdata.frame, trace=", trace, ") data frame col names\n", sep="")
+     xdata.frame <- data.frame(sex3=sex3[c(1,7)], ldose=c(-2,-1), ldose1=c(0.1,0.1), fac3=fac3[c(1,9)])
+     pm <- predict(am, xdata.frame, trace=trace)
+     if (trace) print(pm)
+     stop.if.not.identical("C2-55", pm3.ref, pm)
+ 
+     cat("C2-55bf predict(af, xdata.frame, trace=", trace, ") data frame col names\n", sep="")
+     pf <- predict(af, xdata.frame, trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("C2-55b", pm, pf)
+ 
+     cat("C-56m predict(am, xdata.frame, trace=", trace, ") # data frame with col names\n", sep="")
+     xdata.frame <- data.frame(sex3[c(1,7)], c(-2,-1), c(0.1, 0.1), fac3[c(1,9)])
+     colnames(xdata.frame) <- c("sex3", "ldose", "ldose1", "fac3")
+     pm <- predict(am, xdata.frame, trace=trace)
+     if (trace) print(pm)
+     stop.if.not.identical("C-56", pm3.ref, pm)
+ 
+     cat("C-56f predict(af, xdata.frame, trace=", trace, ") # data frame with col names\n", sep="")
+     pf <- predict(af, xdata.frame, trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("C-56", pm, pf)
+ 
+     cat("C-57m predict(am, xdata.frame, trace=", trace, ") data frame with not enough columns, expect error message\n", sep="")
+     xdata.frame <- data.frame(sex3[c(1,7)], c(-2,-1))
+     expect.err(try(predict(am, xdata.frame, trace=trace)), "get.earth.x from model.matrix.earth from predict.earth: x has 2 columns but expected 4")
+ 
+     cat("C-57f predict(af, xdata.frame, trace=", trace, ") data frame with not enough columns, expect error message\n", sep="")
+     expect.err(try(predict(af, xdata.frame, trace=trace)), "has 2 columns")
+     stop.if.not.identical("C-57", pm, pf)
+ 
+     cat("C-58m predict(am, xdata.frame, trace=", trace, ") # data frame with cols in different order\n", sep="")
+     xdata.frame <- data.frame(c(-2,-1), sex3[c(1,7)], c(0.1, 0.1),  fac3[c(1,9)])
+     colnames(xdata.frame) <- c("ldose", "sex3", "ldose1", "fac3")
+     pm <- predict(am, xdata.frame, trace=trace)
+     if (trace) print(pm)
+     stop.if.not.identical("C-58", pm3.ref, pm)
+ 
+     cat("C-58f predict(af, xdata.frame, trace=", trace, ") # data frame with cols in different order\n", sep="")
+     pf <- predict(af, xdata.frame, trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("C-58", pm, pf)
+ 
+     cat("C-50m data frame without column names, trace=", trace, "\n", sep="")
+     xdata.frame <- data.frame(sex3[1], -2, 0.1, fac3[1])
+     colnames(xdata.frame) <- NULL
+     pm <- predict(am, xdata.frame, trace=trace)
+     if (trace) print(pm)
+     stop.if.not.identical("C-34", pm.ref, pm)
+ 
+     cat("C-60f data frame without column names, trace=", trace, "\n", sep="")
+     xdata.frame <- data.frame(sex3[1], -2, 0.1, fac3[1])
+     colnames(xdata.frame) <- NULL
+     pf <- predict(am, xdata.frame, trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("C-60", pm, pf)
+ 
+     cat("C-61f data frame without extra columns, trace=", trace, "\n", sep="")
+     xdata.frame <- data.frame(sex3=sex3[1], extra1=99, ldose=-2, extra2=99,
+                                ldose1=0.1, fac3=fac3[1], extra3=sex3[7])
+     pf <- predict(af, xdata.frame, trace=trace)
+     if (trace) print(pf)
+     stop.if.not.identical("C-61", pm, pf)
+ }
> test.predict.with.factors(trace=1)

--- predict with single level factors and a single response, trace=1 ---

first do a quick test of predict.earth help page example
predict.earth: returning earth fitted.values 
        Volume
[1,]  8.883097
[2,]  9.909039
[3,] 10.593000
[4,] 16.406671
[5,] 20.578818
[6,] 22.083528
get.earth.x from model.matrix.earth from predict.earth: x has no column names, adding column names: Girth Height
get.earth.x from model.matrix.earth from predict.earth: x[1,2]:
  Girth Height
1    10     80
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[1,2]:
  Girth Height
1    10     80
predict.earth with newdata: bx[1,4]:
  (Intercept) h(Girth-14.2) h(14.2-Girth) h(Height-75)
1           1             0           4.2            5
predict.earth: returning earth predictions 
       Volume
[1,] 17.60359
x[12,3] with colnames sexmale ldose ldose1
y[12,1] with colname numdead, and values 1, 4, 9, 13, 18, 20, 0, 2, 6,...
Forward pass term 1, 2, 4
Reached nk 6
After forward pass GRSq 0.935 RSq 0.981
Prune none penalty 3 nprune null: selected 3 of 3 terms, and 2 of 3 preds
After pruning pass GRSq 0.935 RSq 0.981
x[12,3] with colnames sexmale ldose ldose1
y[12,1] with colname numdead, and values 1, 4, 9, 13, 18, 20, 0, 2, 6,...
Forward pass term 1, 2, 4
Reached nk 6
After forward pass GRSq 0.935 RSq 0.981
Prune none penalty 3 nprune null: selected 3 of 3 terms, and 2 of 3 preds
After pruning pass GRSq 0.935 RSq 0.981
predict with single level factors and a single response: models not identical

Formulas differ: Error in formula.default(mod1) : invalid formula
and:             numdead ~ sex + ldose + ldose1

predict with single level factors and a single response: Models are equivalent, within numerical tolerances

A-20m head(predict(am, trace=1)
predict.earth: returning earth fitted.values 
       numdead
[1,]  1.726190
[2,]  5.369048
[3,]  9.011905
[4,] 12.654762
[5,] 16.297619
[6,] 19.940476
A-20f head(predict(af, trace=1)
predict.earth: returning earth fitted.values 
       numdead
[1,]  1.726190
[2,]  5.369048
[3,]  9.011905
[4,] 12.654762
[5,] 16.297619
[6,] 19.940476
A-20 identical
A-21m predict(am, newdata=c(sex[1], -2, 0.1), trace=1))
get.earth.x from model.matrix.earth from predict.earth: x has no column names, adding column names: sexmale ldose ldose1
get.earth.x from model.matrix.earth from predict.earth: x[1,3]:
  sexmale ldose ldose1
1       1    -2    0.1
predict.earth with newdata: bx[1,3]:
  (Intercept) ldose sexmale
1           1    -2       1
predict.earth: returning earth predictions 
     numdead
[1,] 1.72619
A-21f predict(af, newdata=c(sex[1], -2, 0.1), trace=1))
get.earth.x from model.matrix.earth from predict.earth: x has no column names, adding column names: sex ldose ldose1
get.earth.x from model.matrix.earth from predict.earth: x[1,3]:
  sex ldose ldose1
1   1    -2    0.1
Warning in model.frame.default(terms.without.response, data = data, na.action = na.pass,  :
  variable 'sex' is not a factor
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[1,3]:
  sex ldose ldose1
1   1    -2    0.1
Error : variable 'sex' was fitted with type "factor" but type "numeric" was supplied
Continuing anyway, first few rows of modelframe are
  sex ldose ldose1
1   1    -2    0.1
predict.earth with newdata: bx[1,3]:
  (Intercept) ldose sexmale
1           1    -2       1
predict.earth: returning earth predictions 
     numdead
[1,] 1.72619
A-21 identical
A-22m predict(am, newdata=c(1, -2, 0.1), trace=1)) use numeric instead of factor sex
get.earth.x from model.matrix.earth from predict.earth: x has no column names, adding column names: sexmale ldose ldose1
get.earth.x from model.matrix.earth from predict.earth: x[1,3]:
  sexmale ldose ldose1
1       1    -2    0.1
predict.earth with newdata: bx[1,3]:
  (Intercept) ldose sexmale
1           1    -2       1
predict.earth: returning earth predictions 
     numdead
[1,] 1.72619
A-22 identical
A-22f predict(af, newdata=c(1, -2, 0.1), trace=1)) use numeric instead of factor sex
get.earth.x from model.matrix.earth from predict.earth: x has no column names, adding column names: sex ldose ldose1
get.earth.x from model.matrix.earth from predict.earth: x[1,3]:
  sex ldose ldose1
1   1    -2    0.1
Warning in model.frame.default(terms.without.response, data = data, na.action = na.pass,  :
  variable 'sex' is not a factor
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[1,3]:
  sex ldose ldose1
1   1    -2    0.1
Error : variable 'sex' was fitted with type "factor" but type "numeric" was supplied
Continuing anyway, first few rows of modelframe are
  sex ldose ldose1
1   1    -2    0.1
predict.earth with newdata: bx[1,3]:
  (Intercept) ldose sexmale
1           1    -2       1
predict.earth: returning earth predictions 
     numdead
[1,] 1.72619
A-22 identical
A-23m predict(am, newdata=c(sex[1], sex[1], -2, -2, 0.1, 0.1), trace=1)) multiple rows as a vec
get.earth.x from model.matrix.earth from predict.earth: x has no column names, adding column names: sexmale ldose ldose1
get.earth.x from model.matrix.earth from predict.earth: x[2,3]:
  sexmale ldose ldose1
1       2    -2    0.1
2       2    -2    0.1
predict.earth with newdata: bx[2,3]:
  (Intercept) ldose sexmale
1           1    -2       2
2           1    -2       2
predict.earth: returning earth predictions 
      numdead
[1,] 4.892857
[2,] 4.892857
A-23f predict(af, newdata=c(sex[1], sex[1], -2, -2, 0.1, 0.1), trace=1)) multiple rows as a vec
get.earth.x from model.matrix.earth from predict.earth: x has no column names, adding column names: sex ldose ldose1
get.earth.x from model.matrix.earth from predict.earth: x[2,3]:
  sex ldose ldose1
1   2    -2    0.1
2   2    -2    0.1
Warning in model.frame.default(terms.without.response, data = data, na.action = na.pass,  :
  variable 'sex' is not a factor
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[2,3]:
  sex ldose ldose1
1   2    -2    0.1
2   2    -2    0.1
Error : variable 'sex' was fitted with type "factor" but type "numeric" was supplied
Continuing anyway, first few rows of modelframe are
  sex ldose ldose1
1   2    -2    0.1
2   2    -2    0.1
predict.earth with newdata: bx[2,3]:
  (Intercept) ldose sexmale
1           1    -2       2
2           1    -2       2
predict.earth: returning earth predictions 
      numdead
[1,] 4.892857
[2,] 4.892857
A-23 identical
A-24m predict(am, newdata=c(sex[1], sex[1], -2, -1, 0.1, 0.1), trace=1)) more multiple rows as a vec
get.earth.x from model.matrix.earth from predict.earth: x has no column names, adding column names: sexmale ldose ldose1
get.earth.x from model.matrix.earth from predict.earth: x[2,3]:
  sexmale ldose ldose1
1       2    -2    0.1
2       2    -1    0.1
predict.earth with newdata: bx[2,3]:
  (Intercept) ldose sexmale
1           1    -2       2
2           1    -1       2
predict.earth: returning earth predictions 
      numdead
[1,] 4.892857
[2,] 8.535714
A-24f predict(af, newdata=c(sex[1], sex[1], -2, -1, 0.1, 0.1), trace=1)) more multiple rows as a vec
get.earth.x from model.matrix.earth from predict.earth: x has no column names, adding column names: sex ldose ldose1
get.earth.x from model.matrix.earth from predict.earth: x[2,3]:
  sex ldose ldose1
1   2    -2    0.1
2   2    -1    0.1
Warning in model.frame.default(terms.without.response, data = data, na.action = na.pass,  :
  variable 'sex' is not a factor
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[2,3]:
  sex ldose ldose1
1   2    -2    0.1
2   2    -1    0.1
Error : variable 'sex' was fitted with type "factor" but type "numeric" was supplied
Continuing anyway, first few rows of modelframe are
  sex ldose ldose1
1   2    -2    0.1
2   2    -1    0.1
predict.earth with newdata: bx[2,3]:
  (Intercept) ldose sexmale
1           1    -2       2
2           1    -1       2
predict.earth: returning earth predictions 
      numdead
[1,] 4.892857
[2,] 8.535714
A-24 identical
A-25m predict(am, xpredict matrix trace=1
get.earth.x from model.matrix.earth from predict.earth: x has no column names, adding column names: sexmale ldose ldose1
get.earth.x from model.matrix.earth from predict.earth: x[2,3]:
  sexmale ldose ldose1
1       2    -2    0.1
2       2    -1    0.1
predict.earth with newdata: bx[2,3]:
  (Intercept) ldose sexmale
1           1    -2       2
2           1    -1       2
predict.earth: returning earth predictions 
      numdead
[1,] 4.892857
[2,] 8.535714
A-25 identical
A-25f predict(af, xpredict matrix trace=1
get.earth.x from model.matrix.earth from predict.earth: x has no column names, adding column names: sex ldose ldose1
get.earth.x from model.matrix.earth from predict.earth: x[2,3]:
  sex ldose ldose1
1   2    -2    0.1
2   2    -1    0.1
Warning in model.frame.default(terms.without.response, data = data, na.action = na.pass,  :
  variable 'sex' is not a factor
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[2,3]:
  sex ldose ldose1
1   2    -2    0.1
2   2    -1    0.1
Error : variable 'sex' was fitted with type "factor" but type "numeric" was supplied
Continuing anyway, first few rows of modelframe are
  sex ldose ldose1
1   2    -2    0.1
2   2    -1    0.1
predict.earth with newdata: bx[2,3]:
  (Intercept) ldose sexmale
1           1    -2       2
2           1    -1       2
predict.earth: returning earth predictions 
      numdead
[1,] 4.892857
[2,] 8.535714
A-25 identical
A-26m predict(am, new.data with col names) trace=1
get.earth.x from model.matrix.earth from predict.earth: x[2,3]:
  sex ldose ldose1
1   2    -2    0.1
2   2    -1    0.1
predict.earth with newdata: bx[2,3]:
  (Intercept) ldose sexmale
1           1    -2       2
2           1    -1       2
predict.earth: returning earth predictions 
      numdead
[1,] 4.892857
[2,] 8.535714
A-26m identical
A-26f predict(af, new.data with col names) trace=1
get.earth.x from model.matrix.earth from predict.earth: x[2,3]:
  sex ldose ldose1
1   2    -2    0.1
2   2    -1    0.1
Warning in model.frame.default(terms.without.response, data = data, na.action = na.pass,  :
  variable 'sex' is not a factor
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[2,3]:
  sex ldose ldose1
1   2    -2    0.1
2   2    -1    0.1
Error : variable 'sex' was fitted with type "factor" but type "numeric" was supplied
Continuing anyway, first few rows of modelframe are
  sex ldose ldose1
1   2    -2    0.1
2   2    -1    0.1
predict.earth with newdata: bx[2,3]:
  (Intercept) ldose sexmale
1           1    -2       2
2           1    -1       2
predict.earth: returning earth predictions 
      numdead
[1,] 4.892857
[2,] 8.535714
A-26f identical
A-27m predict(am, new.data with out of order col names) trace=1
get.earth.x from model.matrix.earth from predict.earth: x columns are in the wrong order, correcting the column order
    Old columns: sex ldose1 ldose
    New columns: sexmale ldose ldose1
get.earth.x from model.matrix.earth from predict.earth: x[2,3]:
  sex ldose ldose1
1   2    -2    0.1
2   2    -1    0.1
predict.earth with newdata: bx[2,3]:
  (Intercept) ldose sexmale
1           1    -2       2
2           1    -1       2
predict.earth: returning earth predictions 
      numdead
[1,] 4.892857
[2,] 8.535714
A-27 identical
A-27f predict(af, new.data with out of order col names) trace=1
get.earth.x from model.matrix.earth from predict.earth: x columns are in the wrong order, correcting the column order
    Old columns: sex ldose1 ldose
    New columns: sex ldose ldose1
get.earth.x from model.matrix.earth from predict.earth: x[2,3]:
  sex ldose ldose1
1   2    -2    0.1
2   2    -1    0.1
Warning in model.frame.default(terms.without.response, data = data, na.action = na.pass,  :
  variable 'sex' is not a factor
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[2,3]:
  sex ldose ldose1
1   2    -2    0.1
2   2    -1    0.1
Error : variable 'sex' was fitted with type "factor" but type "numeric" was supplied
Continuing anyway, first few rows of modelframe are
  sex ldose ldose1
1   2    -2    0.1
2   2    -1    0.1
predict.earth with newdata: bx[2,3]:
  (Intercept) ldose sexmale
1           1    -2       2
2           1    -1       2
predict.earth: returning earth predictions 
      numdead
[1,] 4.892857
[2,] 8.535714
A-27 identical
A-28m predict(am, xdata.frame without col names) trace=1
      numdead
[1,] 4.892857
[2,] 8.535714
A-28 identical
A-28f predict(af, xdata.frame without col names) trace=1
get.earth.x from model.matrix.earth from predict.earth: unexpected x column names, renaming columns
    Old names: c.sex.1...sex.1.. c..2...1. c.0.1..0.1.
    New names: sex ldose ldose1
get.earth.x from model.matrix.earth from predict.earth: x[2,3]:
  sex ldose ldose1
1   2    -2    0.1
2   2    -1    0.1
Warning in model.frame.default(terms.without.response, data = data, na.action = na.pass,  :
  variable 'sex' is not a factor
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[2,3]:
  sex ldose ldose1
1   2    -2    0.1
2   2    -1    0.1
Error : variable 'sex' was fitted with type "factor" but type "numeric" was supplied
Continuing anyway, first few rows of modelframe are
  sex ldose ldose1
1   2    -2    0.1
2   2    -1    0.1
predict.earth with newdata: bx[2,3]:
  (Intercept) ldose sexmale
1           1    -2       2
2           1    -1       2
predict.earth: returning earth predictions 
      numdead
[1,] 4.892857
[2,] 8.535714
A-28 identical
A-29m predict(am, xdata.frame with col names) trace=1
get.earth.x from model.matrix.earth from predict.earth: x[1,3]:
   sex ldose ldose1
1 male    -2    0.1
  sex is a factor with levels: female male
predict.earth with newdata: bx[1,3]:
  (Intercept) ldose sexmale
1           1    -2       1
predict.earth: returning earth predictions 
     numdead
[1,] 1.72619
A-29 identical
A-29f predict(af, xdata.frame with col names) trace=1
get.earth.x from model.matrix.earth from predict.earth: x[1,3]:
   sex ldose ldose1
1 male    -2    0.1
  sex is a factor with levels: female male
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[1,3]:
   sex ldose ldose1
1 male    -2    0.1
  sex is a factor with levels: female male
predict.earth with newdata: bx[1,3]:
  (Intercept) ldose sexmale
1           1    -2       1
predict.earth: returning earth predictions 
     numdead
[1,] 1.72619
A-29 identical
A2-29m predict(am, xdata.frame with col names) trace=1
get.earth.x from model.matrix.earth from predict.earth: x[2,3]:
  sex ldose ldose1
1   2    -2    0.1
2   2    -1    0.1
predict.earth with newdata: bx[2,3]:
  (Intercept) ldose sexmale
1           1    -2       2
2           1    -1       2
predict.earth: returning earth predictions 
      numdead
[1,] 4.892857
[2,] 8.535714
A2-29 identical
A2-29f predict(af, xdata.frame with col names) trace=1
get.earth.x from model.matrix.earth from predict.earth: x[2,3]:
  sex ldose ldose1
1   2    -2    0.1
2   2    -1    0.1
Warning in model.frame.default(terms.without.response, data = data, na.action = na.pass,  :
  variable 'sex' is not a factor
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[2,3]:
  sex ldose ldose1
1   2    -2    0.1
2   2    -1    0.1
Error : variable 'sex' was fitted with type "factor" but type "numeric" was supplied
Continuing anyway, first few rows of modelframe are
  sex ldose ldose1
1   2    -2    0.1
2   2    -1    0.1
predict.earth with newdata: bx[2,3]:
  (Intercept) ldose sexmale
1           1    -2       2
2           1    -1       2
predict.earth: returning earth predictions 
      numdead
[1,] 4.892857
[2,] 8.535714
A2-29 identical
A-31m predict(am, xdata.frame, trace=1) data frame with factors and wrong col names
get.earth.x from model.matrix.earth from predict.earth: unexpected x column names, renaming columns
    Old names: sex.1. X.2 X0.1
    New names: sexmale ldose ldose1
get.earth.x from model.matrix.earth from predict.earth: x[1,3]:
  sexmale ldose ldose1
1    male    -2    0.1
  sexmale is a factor with levels: female male
predict.earth with newdata: bx[1,3]:
  (Intercept) ldose sexmale
1           1    -2       1
predict.earth: returning earth predictions 
A-31 identical
     numdead
[1,] 1.72619
A-31f predict(af, xdata.frame, trace=1) data frame with factors and wrong col names
get.earth.x from model.matrix.earth from predict.earth: unexpected x column names, renaming columns
    Old names: sex.1. X.2 X0.1
    New names: sex ldose ldose1
get.earth.x from model.matrix.earth from predict.earth: x[1,3]:
   sex ldose ldose1
1 male    -2    0.1
  sex is a factor with levels: female male
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[1,3]:
   sex ldose ldose1
1 male    -2    0.1
  sex is a factor with levels: female male
predict.earth with newdata: bx[1,3]:
  (Intercept) ldose sexmale
1           1    -2       1
predict.earth: returning earth predictions 
     numdead
[1,] 1.72619
A-31 identical
A-31bm predict(am, xdata.frame, trace=1) data frame col names
get.earth.x from model.matrix.earth from predict.earth: x[1,3]:
   sex ldose ldose1
1 male    -2    0.1
  sex is a factor with levels: female male
predict.earth with newdata: bx[1,3]:
  (Intercept) ldose sexmale
1           1    -2       1
predict.earth: returning earth predictions 
     numdead
[1,] 1.72619
A-31 identical
A-31bf predict(af, xdata.frame, trace=1) data frame col names
get.earth.x from model.matrix.earth from predict.earth: x[1,3]:
   sex ldose ldose1
1 male    -2    0.1
  sex is a factor with levels: female male
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[1,3]:
   sex ldose ldose1
1 male    -2    0.1
  sex is a factor with levels: female male
predict.earth with newdata: bx[1,3]:
  (Intercept) ldose sexmale
1           1    -2       1
predict.earth: returning earth predictions 
     numdead
[1,] 1.72619
A-31b identical
A-32m predict(am, xdata.frame, trace=1) # data frame with names
get.earth.x from model.matrix.earth from predict.earth: x[1,3]:
   sex ldose ldose1
1 male    -2    0.1
  sex is a factor with levels: female male
predict.earth with newdata: bx[1,3]:
  (Intercept) ldose sexmale
1           1    -2       1
predict.earth: returning earth predictions 
     numdead
[1,] 1.72619
A-32 identical
A-32 identical
A-32f predict(af, xdata.frame, trace=1) # data frame with names
get.earth.x from model.matrix.earth from predict.earth: x[1,3]:
   sex ldose ldose1
1 male    -2    0.1
  sex is a factor with levels: female male
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[1,3]:
   sex ldose ldose1
1 male    -2    0.1
  sex is a factor with levels: female male
predict.earth with newdata: bx[1,3]:
  (Intercept) ldose sexmale
1           1    -2       1
predict.earth: returning earth predictions 
     numdead
[1,] 1.72619
A-32 identical
A-42am predict(am, newdata=c(1, -2, 0.1), trace=1)) use numeric instead of factor sex
get.earth.x from model.matrix.earth from predict.earth: x has no column names, adding column names: sexmale ldose ldose1
get.earth.x from model.matrix.earth from predict.earth: x[1,3]:
  sexmale ldose ldose1
1       1    -2    0.1
predict.earth with newdata: bx[1,3]:
  (Intercept) ldose sexmale
1           1    -2       1
predict.earth: returning earth predictions 
     numdead
[1,] 1.72619
A-42a identical
A-42af predict(af, newdata=c(1, -2, 0.1), trace=1)) use numeric instead of factor sex
get.earth.x from model.matrix.earth from predict.earth: x has no column names, adding column names: sex ldose ldose1
get.earth.x from model.matrix.earth from predict.earth: x[1,3]:
  sex ldose ldose1
1   1    -2    0.1
Warning in model.frame.default(terms.without.response, data = data, na.action = na.pass,  :
  variable 'sex' is not a factor
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[1,3]:
  sex ldose ldose1
1   1    -2    0.1
Error : variable 'sex' was fitted with type "factor" but type "numeric" was supplied
Continuing anyway, first few rows of modelframe are
  sex ldose ldose1
1   1    -2    0.1
predict.earth with newdata: bx[1,3]:
  (Intercept) ldose sexmale
1           1    -2       1
predict.earth: returning earth predictions 
     numdead
[1,] 1.72619
A-42a identical
A-43am predict(af, newdata=c(sex[1], sex[1], -2, -2, 0.1, 0.1), trace=1)) multiple rows as a vec
get.earth.x from model.matrix.earth from predict.earth: x has no column names, adding column names: sex ldose ldose1
get.earth.x from model.matrix.earth from predict.earth: x[2,3]:
  sex ldose ldose1
1   2    -2    0.1
2   2    -2    0.1
Warning in model.frame.default(terms.without.response, data = data, na.action = na.pass,  :
  variable 'sex' is not a factor
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[2,3]:
  sex ldose ldose1
1   2    -2    0.1
2   2    -2    0.1
Error : variable 'sex' was fitted with type "factor" but type "numeric" was supplied
Continuing anyway, first few rows of modelframe are
  sex ldose ldose1
1   2    -2    0.1
2   2    -2    0.1
predict.earth with newdata: bx[2,3]:
  (Intercept) ldose sexmale
1           1    -2       2
2           1    -2       2
predict.earth: returning earth predictions 
      numdead
[1,] 4.892857
[2,] 4.892857
A-43af predict(am, newdata=c(sex[1], sex[1], -2, -2, 0.1, 0.1), trace=1)) multiple rows as a vec
get.earth.x from model.matrix.earth from predict.earth: x has no column names, adding column names: sexmale ldose ldose1
get.earth.x from model.matrix.earth from predict.earth: x[2,3]:
  sexmale ldose ldose1
1       2    -2    0.1
2       2    -2    0.1
predict.earth with newdata: bx[2,3]:
  (Intercept) ldose sexmale
1           1    -2       2
2           1    -2       2
predict.earth: returning earth predictions 
      numdead
[1,] 4.892857
[2,] 4.892857
A-43a identical
A-44am predict(af, newdata=c(sex[1], sex[1], -2, -1, 0.1, 0.1), trace=1)) more multiple rows as a vec
get.earth.x from model.matrix.earth from predict.earth: x has no column names, adding column names: sex ldose ldose1
get.earth.x from model.matrix.earth from predict.earth: x[2,3]:
  sex ldose ldose1
1   2    -2    0.1
2   2    -1    0.1
Warning in model.frame.default(terms.without.response, data = data, na.action = na.pass,  :
  variable 'sex' is not a factor
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[2,3]:
  sex ldose ldose1
1   2    -2    0.1
2   2    -1    0.1
Error : variable 'sex' was fitted with type "factor" but type "numeric" was supplied
Continuing anyway, first few rows of modelframe are
  sex ldose ldose1
1   2    -2    0.1
2   2    -1    0.1
predict.earth with newdata: bx[2,3]:
  (Intercept) ldose sexmale
1           1    -2       2
2           1    -1       2
predict.earth: returning earth predictions 
      numdead
[1,] 4.892857
[2,] 8.535714
A-44a identical
A-44fm predict(am, newdata=c(sex[1], sex[1], -2, -1, 0.1, 0.1), trace=1)) more multiple rows as a vec
get.earth.x from model.matrix.earth from predict.earth: x has no column names, adding column names: sexmale ldose ldose1
get.earth.x from model.matrix.earth from predict.earth: x[2,3]:
  sexmale ldose ldose1
1       2    -2    0.1
2       2    -1    0.1
predict.earth with newdata: bx[2,3]:
  (Intercept) ldose sexmale
1           1    -2       2
2           1    -1       2
predict.earth: returning earth predictions 
      numdead
[1,] 4.892857
[2,] 8.535714
A-44f identical
A-53m predict(am, xdata.frame, trace=1) data frame with not enough columns, expect error message
Error : get.earth.x from model.matrix.earth from predict.earth: x has 2 columns but expected 3
       column names: sex.1. X.2
       expected column names: sexmale ldose ldose1
Got error as expected from try(predict(am, xdata.frame, trace = trace))
A-53f predict(af, xdata.frame, trace=1) data frame with not enough columns, expect error message
Error : get.earth.x from model.matrix.earth from predict.earth: x has 2 columns but expected 3
       column names: sex.1. X.2
       expected column names: sex ldose ldose1
Got error as expected from try(predict(af, xdata.frame, trace = trace))
A-54m predict(am, xdata.frame, trace=1) # data frame with cols in different order
get.earth.x from model.matrix.earth from predict.earth: x columns are in the wrong order, correcting the column order
    Old columns: ldose sex ldose1
    New columns: sexmale ldose ldose1
get.earth.x from model.matrix.earth from predict.earth: x[1,3]:
   sex ldose ldose1
1 male    -2    0.1
  sex is a factor with levels: female male
predict.earth with newdata: bx[1,3]:
  (Intercept) ldose sexmale
1           1    -2       1
predict.earth: returning earth predictions 
     numdead
[1,] 1.72619
A-54 identical
A-54f predict(af, xdata.frame, trace=1) # data frame with cols in different order
get.earth.x from model.matrix.earth from predict.earth: x columns are in the wrong order, correcting the column order
    Old columns: ldose sex ldose1
    New columns: sex ldose ldose1
get.earth.x from model.matrix.earth from predict.earth: x[1,3]:
   sex ldose ldose1
1 male    -2    0.1
  sex is a factor with levels: female male
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[1,3]:
   sex ldose ldose1
1 male    -2    0.1
  sex is a factor with levels: female male
predict.earth with newdata: bx[1,3]:
  (Intercept) ldose sexmale
1           1    -2       1
predict.earth: returning earth predictions 
     numdead
[1,] 1.72619
A-54 identical
A-55m predict(am, xdata.frame, trace=1) data frame without col names
get.earth.x from model.matrix.earth from predict.earth: unexpected x column names, renaming columns
    Old names: sex.c.1..7.. c..2...1. c.0.1..0.1.
    New names: sexmale ldose ldose1
get.earth.x from model.matrix.earth from predict.earth: x[2,3]:
  sexmale ldose ldose1
1    male    -2    0.1
2  female    -1    0.1
  sexmale is a factor with levels: female male
predict.earth with newdata: bx[2,3]:
  (Intercept) ldose sexmale
1           1    -2       1
2           1    -1       0
predict.earth: returning earth predictions 
      numdead
[1,] 1.726190
[2,] 2.202381
A-55f predict(af, xdata.frame, trace=1) data frame without col names
get.earth.x from model.matrix.earth from predict.earth: unexpected x column names, renaming columns
    Old names: sex.c.1..7.. c..2...1. c.0.1..0.1.
    New names: sex ldose ldose1
get.earth.x from model.matrix.earth from predict.earth: x[2,3]:
     sex ldose ldose1
1   male    -2    0.1
2 female    -1    0.1
  sex is a factor with levels: female male
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[2,3]:
     sex ldose ldose1
1   male    -2    0.1
2 female    -1    0.1
  sex is a factor with levels: female male
predict.earth with newdata: bx[2,3]:
  (Intercept) ldose sexmale
1           1    -2       1
2           1    -1       0
predict.earth: returning earth predictions 
      numdead
[1,] 1.726190
[2,] 2.202381
A-55 identical
A-56m predict(am, xdata.frame, trace=1) # data frame with col names
get.earth.x from model.matrix.earth from predict.earth: x[2,3]:
     sex ldose ldose1
1   male    -2    0.1
2 female    -1    0.1
  sex is a factor with levels: female male
predict.earth with newdata: bx[2,3]:
  (Intercept) ldose sexmale
1           1    -2       1
2           1    -1       0
predict.earth: returning earth predictions 
      numdead
[1,] 1.726190
[2,] 2.202381
A-56 identical
A-56f predict(af, xdata.frame, trace=1) # data frame with col names
get.earth.x from model.matrix.earth from predict.earth: x[2,3]:
     sex ldose ldose1
1   male    -2    0.1
2 female    -1    0.1
  sex is a factor with levels: female male
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[2,3]:
     sex ldose ldose1
1   male    -2    0.1
2 female    -1    0.1
  sex is a factor with levels: female male
predict.earth with newdata: bx[2,3]:
  (Intercept) ldose sexmale
1           1    -2       1
2           1    -1       0
predict.earth: returning earth predictions 
      numdead
[1,] 1.726190
[2,] 2.202381
A-56 identical
A-57m predict(am, xdata.frame, trace=1) data frame with not enough columns, expect error message
Error : get.earth.x from model.matrix.earth from predict.earth: x has 2 columns but expected 3
       column names: sex.c.1..7.. c..2...1.
       expected column names: sexmale ldose ldose1
Got error as expected from try(predict(am, xdata.frame, trace = trace))
A-57f predict(af, xdata.frame, trace=1) data frame with not enough columns, expect error message
Error : get.earth.x from model.matrix.earth from predict.earth: x has 2 columns but expected 3
       column names: sex.c.1..7.. c..2...1.
       expected column names: sex ldose ldose1
Got error as expected from try(predict(af, xdata.frame, trace = trace))
A-57 identical
A-58m predict(am, xdata.frame, trace=1) # data frame with cols in different order
get.earth.x from model.matrix.earth from predict.earth: x columns are in the wrong order, correcting the column order
    Old columns: ldose sex ldose1
    New columns: sexmale ldose ldose1
get.earth.x from model.matrix.earth from predict.earth: x[2,3]:
     sex ldose ldose1
1   male    -2    0.1
2 female    -1    0.1
  sex is a factor with levels: female male
predict.earth with newdata: bx[2,3]:
  (Intercept) ldose sexmale
1           1    -2       1
2           1    -1       0
predict.earth: returning earth predictions 
      numdead
[1,] 1.726190
[2,] 2.202381
A-58 identical
A-58f predict(af, xdata.frame, trace=1) # data frame with cols in different order
get.earth.x from model.matrix.earth from predict.earth: x columns are in the wrong order, correcting the column order
    Old columns: ldose sex ldose1
    New columns: sex ldose ldose1
get.earth.x from model.matrix.earth from predict.earth: x[2,3]:
     sex ldose ldose1
1   male    -2    0.1
2 female    -1    0.1
  sex is a factor with levels: female male
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[2,3]:
     sex ldose ldose1
1   male    -2    0.1
2 female    -1    0.1
  sex is a factor with levels: female male
predict.earth with newdata: bx[2,3]:
  (Intercept) ldose sexmale
1           1    -2       1
2           1    -1       0
predict.earth: returning earth predictions 
      numdead
[1,] 1.726190
[2,] 2.202381
A-58 identical
A-59m predict(am, xdata.frame, trace=1) numeric where factor expected, expect forge on message
get.earth.x from model.matrix.earth from predict.earth: x[2,3]:
  sex ldose ldose1
1   2    -2    0.1
2   1    -1    0.1
predict.earth with newdata: bx[2,3]:
  (Intercept) ldose sexmale
1           1    -2       2
2           1    -1       1
predict.earth: returning earth predictions 
      numdead
[1,] 4.892857
[2,] 5.369048
A-59f predict(af, xdata.frame, trace=1) numeric where factor expected, expect forge on message
get.earth.x from model.matrix.earth from predict.earth: x[2,3]:
  sex ldose ldose1
1   2    -2    0.1
2   1    -1    0.1
Warning in model.frame.default(terms.without.response, data = data, na.action = na.pass,  :
  variable 'sex' is not a factor
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[2,3]:
  sex ldose ldose1
1   2    -2    0.1
2   1    -1    0.1
Error : variable 'sex' was fitted with type "factor" but type "numeric" was supplied
Continuing anyway, first few rows of modelframe are
  sex ldose ldose1
1   2    -2    0.1
2   1    -1    0.1
predict.earth with newdata: bx[2,3]:
  (Intercept) ldose sexmale
1           1    -2       2
2           1    -1       1
predict.earth: returning earth predictions 
      numdead
[1,] 4.892857
[2,] 5.369048
A-59 identical
A-50m data frame without column names, trace=1
get.earth.x from model.matrix.earth from predict.earth: x has no column names, adding column names: sexmale ldose ldose1
get.earth.x from model.matrix.earth from predict.earth: x[1,3]:
  sexmale ldose ldose1
1    male    -2    0.1
  sexmale is a factor with levels: female male
predict.earth with newdata: bx[1,3]:
  (Intercept) ldose sexmale
1           1    -2       1
predict.earth: returning earth predictions 
     numdead
[1,] 1.72619
A-34 identical
A-60f data frame without column names, trace=1
get.earth.x from model.matrix.earth from predict.earth: x has no column names, adding column names: sexmale ldose ldose1
get.earth.x from model.matrix.earth from predict.earth: x[1,3]:
  sexmale ldose ldose1
1    male    -2    0.1
  sexmale is a factor with levels: female male
predict.earth with newdata: bx[1,3]:
  (Intercept) ldose sexmale
1           1    -2       1
predict.earth: returning earth predictions 
     numdead
[1,] 1.72619
A-60 identical
A-61f data frame without extra columns, trace=1
get.earth.x from model.matrix.earth from predict.earth: x[1,6]:
   sex extra1 ldose extra2 ldose1 extra3
1 male     99    -2     99    0.1 female
  factors: sex extra3
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[1,3]:
   sex ldose ldose1
1 male    -2    0.1
  sex is a factor with levels: female male
predict.earth with newdata: bx[1,3]:
  (Intercept) ldose sexmale
1           1    -2       1
predict.earth: returning earth predictions 
     numdead
[1,] 1.72619
A-61 identical
A-68 input matrix to formula interface trace=1, expect error "could not interpret"
x[60,2] with colnames my.input.matmy.x1 my.input.matmy.x2
y[60,1] with colname my.response, and values 4.2, 11.5, 7.3, 5.8, 6.4, 10,...
Forward pass term 1, 2, 4, 6
RSq changed by less than 0.001 at 5 terms, 4 terms used (DeltaRSq 0)
After forward pass GRSq 0.682 RSq 0.762
Prune backward penalty 2 nprune null: selected 4 of 4 terms, and 2 of 2 preds
After pruning pass GRSq 0.705 RSq 0.762
get.earth.x from model.matrix.earth from predict.earth: x has no column names, adding column names: my.x1 my.x2
get.earth.x from model.matrix.earth from predict.earth: x[1,2]:
  my.x1 my.x2
1   2.1   0.6
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[60,1]:
    my.input.mat.my.x1 my.input.mat.my.x2
1                  2.0                0.5
2                  2.0                0.5
3                  2.0                0.5
...                2.0                0.5
60                 1.0                2.0
Error : model.frame.default could not interpret the data passed to get.earth.x from model.matrix.earth from predict.earth
        (actual.nrows=60 expected.nrows=1 fitted.nrows=60)
Got error as expected from try(predict(a41, c(2.1, 0.6), trace = trace))
A-69 above test but with properly named dataframe trace=1
     growth
[1,] 10.211
Tests with not all predictors used in the model so can pass fewer columns
x[12,3] with colnames ldose dummy ldose1
y[12,1] with colname numdead, and values 1, 4, 9, 13, 18, 20, 0, 2, 6,...
Forward pass term 1, 2, 4
Reached nk 6
After forward pass GRSq 0.745 RSq 0.924
Prune none penalty 3 nprune null: selected 3 of 3 terms, and 2 of 3 preds
After pruning pass GRSq 0.745 RSq 0.924
get.earth.x from model.matrix.earth from predict.earth: x[1,3]:
  ldose dummy ldose1
1    -2     0    0.1
predict.earth with newdata: bx[1,3]:
  (Intercept) ldose ldose*ldose1
1           1    -2         -0.2
predict.earth: returning earth predictions 
       numdead
[1,] 0.4686592
A-72m predict(am, newdata=newdata[two columns], trace=trace)
get.earth.x from model.matrix.earth from predict.earth: x has missing columns, creating a new x with all cols
get.earth.x from model.matrix.earth from predict.earth: x[1,3]:
  ldose dummy ldose1
1    -2    NA    0.1
predict.earth with newdata: bx[1,3]:
  (Intercept) ldose ldose*ldose1
1           1    -2         -0.2
predict.earth: returning earth predictions 
       numdead
[1,] 0.4686592
A-72m identical
   ldose dummy ldose1
1     -2     0    0.1
2     -1     0    1.2
3      0     0    0.1
4      1     0    1.2
5      2     0    1.0
6      3     0    0.1
7     -2     0    0.3
8     -1     0    1.4
9      0     0    0.1
10     1     0    1.2
11     2     0    0.1
12     3     0    0.9
get.earth.x from model.matrix.earth from predict.earth: x[12,3]:
    ldose dummy ldose1
1      -2     0    0.1
2      -1     0    1.2
3       0     0    0.1
...     1     0    1.2
12      3     0    0.9
predict.earth with newdata: bx[12,3]:
    (Intercept) ldose ldose*ldose1
1             1    -2         -0.2
2             1    -1         -1.2
3             1     0          0.0
...           1     1          1.2
12            1     3          2.7
predict.earth: returning earth predictions 
         numdead
 [1,]  0.4686592
 [2,]  3.4356368
 [3,]  7.3864088
 [4,] 11.3371809
 [5,] 15.1090812
 [6,] 17.7630332
 [7,]  0.2897875
 [8,]  3.3462009
 [9,]  7.3864088
[10,] 11.3371809
[11,] 14.3041584
[12,] 18.8362636
A-73m predict(am, newdata=newdata[two columns], trace=trace)
get.earth.x from model.matrix.earth from predict.earth: x has missing columns, creating a new x with all cols
get.earth.x from model.matrix.earth from predict.earth: x[12,3]:
    ldose dummy ldose1
1      -2    NA    0.1
2      -1    NA    1.2
3       0    NA    0.1
...     1    NA    1.2
12      3    NA    0.9
predict.earth with newdata: bx[12,3]:
    (Intercept) ldose ldose*ldose1
1             1    -2         -0.2
2             1    -1         -1.2
3             1     0          0.0
...           1     1          1.2
12            1     3          2.7
predict.earth: returning earth predictions 
         numdead
 [1,]  0.4686592
 [2,]  3.4356368
 [3,]  7.3864088
 [4,] 11.3371809
 [5,] 15.1090812
 [6,] 17.7630332
 [7,]  0.2897875
 [8,]  3.3462009
 [9,]  7.3864088
[10,] 11.3371809
[11,] 14.3041584
[12,] 18.8362636
A-73m identical
x[12,3] with colnames ldose dummy ldose1
y[12,1] with colname numdead, and values 1, 4, 9, 13, 18, 20, 0, 2, 6,...
Forward pass term 1, 2, 4
Reached nk 6
After forward pass GRSq 0.745 RSq 0.924
Prune none penalty 3 nprune null: selected 3 of 3 terms, and 2 of 3 preds
After pruning pass GRSq 0.745 RSq 0.924
get.earth.x from model.matrix.earth from predict.earth: x[1,3]:
  ldose dummy ldose1
1    -2     0    0.1
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[1,3]:
  ldose dummy ldose1
1    -2     0    0.1
predict.earth with newdata: bx[1,3]:
  (Intercept) ldose ldose*ldose1
1           1    -2         -0.2
predict.earth: returning earth predictions 
       numdead
[1,] 0.4686592
A-72f predict(af, newdata=newdata[two columns], trace=trace)
get.earth.x from model.matrix.earth from predict.earth: x has missing columns, creating a new x with all cols
get.earth.x from model.matrix.earth from predict.earth: x[1,3]:
  ldose dummy ldose1
1    -2    NA    0.1
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[1,3]:
  ldose dummy ldose1
1    -2    NA    0.1
predict.earth with newdata: bx[1,3]:
  (Intercept) ldose ldose*ldose1
1           1    -2         -0.2
predict.earth: returning earth predictions 
       numdead
[1,] 0.4686592
A-72f identical
   ldose dummy ldose1
1     -2     0    0.1
2     -1     0    1.2
3      0     0    0.1
4      1     0    1.2
5      2     0    1.0
6      3     0    0.1
7     -2     0    0.3
8     -1     0    1.4
9      0     0    0.1
10     1     0    1.2
11     2     0    0.1
12     3     0    0.9
get.earth.x from model.matrix.earth from predict.earth: x[12,3]:
    ldose dummy ldose1
1      -2     0    0.1
2      -1     0    1.2
3       0     0    0.1
...     1     0    1.2
12      3     0    0.9
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[12,3]:
    ldose dummy ldose1
1      -2     0    0.1
2      -1     0    1.2
3       0     0    0.1
...     1     0    1.2
12      3     0    0.9
predict.earth with newdata: bx[12,3]:
    (Intercept) ldose ldose*ldose1
1             1    -2         -0.2
2             1    -1         -1.2
3             1     0          0.0
...           1     1          1.2
12            1     3          2.7
predict.earth: returning earth predictions 
         numdead
 [1,]  0.4686592
 [2,]  3.4356368
 [3,]  7.3864088
 [4,] 11.3371809
 [5,] 15.1090812
 [6,] 17.7630332
 [7,]  0.2897875
 [8,]  3.3462009
 [9,]  7.3864088
[10,] 11.3371809
[11,] 14.3041584
[12,] 18.8362636
A-73f predict(af, newdata=newdata[two columns], trace=trace)
get.earth.x from model.matrix.earth from predict.earth: x has missing columns, creating a new x with all cols
get.earth.x from model.matrix.earth from predict.earth: x[12,3]:
    ldose dummy ldose1
1      -2    NA    0.1
2      -1    NA    1.2
3       0    NA    0.1
...     1    NA    1.2
12      3    NA    0.9
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[12,3]:
    ldose dummy ldose1
1      -2    NA    0.1
2      -1    NA    1.2
3       0    NA    0.1
...     1    NA    1.2
12      3    NA    0.9
predict.earth with newdata: bx[12,3]:
    (Intercept) ldose ldose*ldose1
1             1    -2         -0.2
2             1    -1         -1.2
3             1     0          0.0
...           1     1          1.2
12            1     3          2.7
predict.earth: returning earth predictions 
         numdead
 [1,]  0.4686592
 [2,]  3.4356368
 [3,]  7.3864088
 [4,] 11.3371809
 [5,] 15.1090812
 [6,] 17.7630332
 [7,]  0.2897875
 [8,]  3.3462009
 [9,]  7.3864088
[10,] 11.3371809
[11,] 14.3041584
[12,] 18.8362636
A-73f identical

--- B predict with multiple level factors and a multiple real response, trace=1 ---

x[12,6] with colnames sex3female sex3male ldose ldose1 fac3lev2 fac3lev3
y[12,2] with colnames numdead numdead2
Forward pass term 1, 2, 4
Reached nk 6
After forward pass GRSq 0.763 RSq 0.976
Prune none penalty 3 nprune null: selected 4 of 4 terms, and 2 of 6 preds
After pruning pass GRSq 0.763 RSq 0.976
x[12,6] with colnames sex3female sex3male ldose ldose1 fac3lev2 fac3lev3
y[12,2] with colnames numdead numdead2
Forward pass term 1, 2, 4
Reached nk 6
After forward pass GRSq 0.763 RSq 0.976
Prune none penalty 3 nprune null: selected 4 of 4 terms, and 2 of 6 preds
After pruning pass GRSq 0.763 RSq 0.976
B predict with multiple level factors and a multiple real response: models not identical

Formulas differ: Error in formula.default(mod1) : invalid formula
and:             numdeadboth ~ sex3 + ldose + ldose1 + fac3

B predict with multiple level factors and a multiple real response: Models are equivalent, within numerical tolerances

20m head(predict(am, trace=1)
predict.earth: returning earth fitted.values 
       numdead  numdead2
[1,]  1.577732  1.587702
[2,]  5.369367  5.595869
[3,]  9.161001  9.604036
[4,] 12.751499 13.214895
[5,] 16.297300 16.737465
[6,] 19.843100 20.260034
B-21f head(predict(af, trace=1)
predict.earth: returning earth fitted.values 
       numdead  numdead2
[1,]  1.577732  1.587702
[2,]  5.369367  5.595869
[3,]  9.161001  9.604036
[4,] 12.751499 13.214895
[5,] 16.297300 16.737465
[6,] 19.843100 20.260034
B-20 identical
B-31m predict(am, xdata.frame, trace=1) data frame with factors and wrong col names
get.earth.x from model.matrix.earth from predict.earth: unexpected x column names, renaming columns
    Old names: sex3.1. X.2 X0.1 fac3.1.
    New names: sex3 ldose ldose1 fac3
get.earth.x from model.matrix.earth from predict.earth: x[1,4]:
  sex3 ldose ldose1 fac3
1 male    -2    0.1 lev2
  factors: sex3 fac3
predict.earth with newdata: bx[1,4]:
  (Intercept) ldose h(ldose1-2.5) h(2.5-ldose1)
1           1    -2             0           2.4
predict.earth: returning earth predictions 
B-31 identical
      numdead numdead2
[1,] 1.577732 1.587702
B-31f predict(af, xdata.frame, trace=1) data frame with factors and wrong col names
get.earth.x from model.matrix.earth from predict.earth: unexpected x column names, renaming columns
    Old names: sex3.1. X.2 X0.1 fac3.1.
    New names: sex3 ldose ldose1 fac3
get.earth.x from model.matrix.earth from predict.earth: x[1,4]:
  sex3 ldose ldose1 fac3
1 male    -2    0.1 lev2
  factors: sex3 fac3
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[1,4]:
  sex3 ldose ldose1 fac3
1 male    -2    0.1 lev2
  factors: sex3 fac3
predict.earth with newdata: bx[1,4]:
  (Intercept) ldose h(ldose1-2.5) h(2.5-ldose1)
1           1    -2             0           2.4
predict.earth: returning earth predictions 
      numdead numdead2
[1,] 1.577732 1.587702
B-31 identical
B-31bm predict(am, xdata.frame, trace=1) data frame col names
get.earth.x from model.matrix.earth from predict.earth: x[1,4]:
  sex3 ldose ldose1 fac3
1 male    -2    0.1 lev2
  factors: sex3 fac3
predict.earth with newdata: bx[1,4]:
  (Intercept) ldose h(ldose1-2.5) h(2.5-ldose1)
1           1    -2             0           2.4
predict.earth: returning earth predictions 
      numdead numdead2
[1,] 1.577732 1.587702
B-31 identical
B-31bf predict(af, xdata.frame, trace=1) data frame col names
get.earth.x from model.matrix.earth from predict.earth: x[1,4]:
  sex3 ldose ldose1 fac3
1 male    -2    0.1 lev2
  factors: sex3 fac3
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[1,4]:
  sex3 ldose ldose1 fac3
1 male    -2    0.1 lev2
  factors: sex3 fac3
predict.earth with newdata: bx[1,4]:
  (Intercept) ldose h(ldose1-2.5) h(2.5-ldose1)
1           1    -2             0           2.4
predict.earth: returning earth predictions 
      numdead numdead2
[1,] 1.577732 1.587702
B-31b identical
B-32m predict(am, xdata.frame, trace=1) # data frame with names
get.earth.x from model.matrix.earth from predict.earth: x[1,4]:
  sex3 ldose ldose1 fac3
1 male    -2    0.1 lev2
  factors: sex3 fac3
predict.earth with newdata: bx[1,4]:
  (Intercept) ldose h(ldose1-2.5) h(2.5-ldose1)
1           1    -2             0           2.4
predict.earth: returning earth predictions 
      numdead numdead2
[1,] 1.577732 1.587702
B-32 identical
B-32 identical
B-32f predict(af, xdata.frame, trace=1) # data frame with names
get.earth.x from model.matrix.earth from predict.earth: x[1,4]:
  sex3 ldose ldose1 fac3
1 male    -2    0.1 lev2
  factors: sex3 fac3
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[1,4]:
  sex3 ldose ldose1 fac3
1 male    -2    0.1 lev2
  factors: sex3 fac3
predict.earth with newdata: bx[1,4]:
  (Intercept) ldose h(ldose1-2.5) h(2.5-ldose1)
1           1    -2             0           2.4
predict.earth: returning earth predictions 
      numdead numdead2
[1,] 1.577732 1.587702
B-32 identical
B-53m predict(am, xdata.frame, trace=1) data frame with not enough columns, expect error message
Error : get.earth.x from model.matrix.earth from predict.earth: x has 2 columns but expected 4
       column names: sex3.1. X.2
       expected column names: sex3 ldose ldose1 fac3
Got error as expected from try(predict(am, xdata.frame, trace = trace))
B-53f predict(af, xdata.frame, trace=1) data frame with not enough columns, expect error message
Error : get.earth.x from model.matrix.earth from predict.earth: x has 2 columns but expected 4
       column names: sex3.1. X.2
       expected column names: sex3 ldose ldose1 fac3
Got error as expected from try(predict(af, xdata.frame, trace = trace))
B-54m predict(am, xdata.frame, trace=1) # data frame with cols in different order
get.earth.x from model.matrix.earth from predict.earth: x columns are in the wrong order, correcting the column order
    Old columns: ldose sex3 ldose1 fac3
    New columns: sex3 ldose ldose1 fac3
get.earth.x from model.matrix.earth from predict.earth: x[1,4]:
  sex3 ldose ldose1 fac3
1 male    -2    0.1 lev2
  factors: sex3 fac3
predict.earth with newdata: bx[1,4]:
  (Intercept) ldose h(ldose1-2.5) h(2.5-ldose1)
1           1    -2             0           2.4
predict.earth: returning earth predictions 
      numdead numdead2
[1,] 1.577732 1.587702
B-54 identical
B-54f predict(af, xdata.frame, trace=1) # data frame with cols in different order
get.earth.x from model.matrix.earth from predict.earth: x columns are in the wrong order, correcting the column order
    Old columns: ldose sex3 ldose1 fac3
    New columns: sex3 ldose ldose1 fac3
get.earth.x from model.matrix.earth from predict.earth: x[1,4]:
  sex3 ldose ldose1 fac3
1 male    -2    0.1 lev2
  factors: sex3 fac3
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[1,4]:
  sex3 ldose ldose1 fac3
1 male    -2    0.1 lev2
  factors: sex3 fac3
predict.earth with newdata: bx[1,4]:
  (Intercept) ldose h(ldose1-2.5) h(2.5-ldose1)
1           1    -2             0           2.4
predict.earth: returning earth predictions 
      numdead numdead2
[1,] 1.577732 1.587702
B-54 identical
B-55m predict(am, xdata.frame, trace=1) data frame without col names
get.earth.x from model.matrix.earth from predict.earth: unexpected x column names, renaming columns
    Old names: sex3.c.1..7.. c..2...1. c.0.1..0.1. fac3.c.1..9..
    New names: sex3 ldose ldose1 fac3
get.earth.x from model.matrix.earth from predict.earth: x[2,4]:
    sex3 ldose ldose1 fac3
1   male    -2    0.1 lev2
2 female    -1    0.1 lev1
  factors: sex3 fac3
predict.earth with newdata: bx[2,4]:
  (Intercept) ldose h(ldose1-2.5) h(2.5-ldose1)
1           1    -2             0           2.4
2           1    -1             0           2.4
predict.earth: returning earth predictions 
       numdead  numdead2
[1,]  1.577732  1.587702
[2,] 22.663117 20.019737
B-55m again, but with same x data for both reponses
get.earth.x from model.matrix.earth from predict.earth: unexpected x column names, renaming columns
    Old names: sex3.c.1..1.. c..2...2. c.0.1..0.1. fac3.c.1..1..
    New names: sex3 ldose ldose1 fac3
get.earth.x from model.matrix.earth from predict.earth: x[2,4]:
  sex3 ldose ldose1 fac3
1 male    -2    0.1 lev2
2 male    -2    0.1 lev2
  factors: sex3 fac3
predict.earth with newdata: bx[2,4]:
  (Intercept) ldose h(ldose1-2.5) h(2.5-ldose1)
1           1    -2             0           2.4
2           1    -2             0           2.4
predict.earth: returning earth predictions 
      numdead numdead2
[1,] 1.577732 1.587702
[2,] 1.577732 1.587702
B-55f predict(af, xdata.frame, trace=1) data frame without col names
get.earth.x from model.matrix.earth from predict.earth: unexpected x column names, renaming columns
    Old names: sex3.c.1..1.. c..2...2. c.0.1..0.1. fac3.c.1..1..
    New names: sex3 ldose ldose1 fac3
get.earth.x from model.matrix.earth from predict.earth: x[2,4]:
  sex3 ldose ldose1 fac3
1 male    -2    0.1 lev2
2 male    -2    0.1 lev2
  factors: sex3 fac3
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[2,4]:
  sex3 ldose ldose1 fac3
1 male    -2    0.1 lev2
2 male    -2    0.1 lev2
  factors: sex3 fac3
predict.earth with newdata: bx[2,4]:
  (Intercept) ldose h(ldose1-2.5) h(2.5-ldose1)
1           1    -2             0           2.4
2           1    -2             0           2.4
predict.earth: returning earth predictions 
      numdead numdead2
[1,] 1.577732 1.587702
[2,] 1.577732 1.587702
B-55 identical
B2-55bm predict(am, xdata.frame, trace=1) data frame col names
get.earth.x from model.matrix.earth from predict.earth: x[2,4]:
    sex3 ldose ldose1 fac3
1   male    -2    0.1 lev2
2 female    -1    0.1 lev1
  factors: sex3 fac3
predict.earth with newdata: bx[2,4]:
  (Intercept) ldose h(ldose1-2.5) h(2.5-ldose1)
1           1    -2             0           2.4
2           1    -1             0           2.4
predict.earth: returning earth predictions 
       numdead  numdead2
[1,]  1.577732  1.587702
[2,] 22.663117 20.019737
B2-55 identical
B2-55bf predict(af, xdata.frame, trace=1) data frame col names
get.earth.x from model.matrix.earth from predict.earth: x[2,4]:
    sex3 ldose ldose1 fac3
1   male    -2    0.1 lev2
2 female    -1    0.1 lev1
  factors: sex3 fac3
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[2,4]:
    sex3 ldose ldose1 fac3
1   male    -2    0.1 lev2
2 female    -1    0.1 lev1
  factors: sex3 fac3
predict.earth with newdata: bx[2,4]:
  (Intercept) ldose h(ldose1-2.5) h(2.5-ldose1)
1           1    -2             0           2.4
2           1    -1             0           2.4
predict.earth: returning earth predictions 
       numdead  numdead2
[1,]  1.577732  1.587702
[2,] 22.663117 20.019737
B2-55b identical
B-56m predict(am, xdata.frame, trace=1) # data frame with col names
get.earth.x from model.matrix.earth from predict.earth: x[2,4]:
    sex3 ldose ldose1 fac3
1   male    -2    0.1 lev2
2 female    -1    0.1 lev1
  factors: sex3 fac3
predict.earth with newdata: bx[2,4]:
  (Intercept) ldose h(ldose1-2.5) h(2.5-ldose1)
1           1    -2             0           2.4
2           1    -1             0           2.4
predict.earth: returning earth predictions 
       numdead  numdead2
[1,]  1.577732  1.587702
[2,] 22.663117 20.019737
B-56 identical
B-56f predict(af, xdata.frame, trace=1) # data frame with col names
get.earth.x from model.matrix.earth from predict.earth: x[2,4]:
    sex3 ldose ldose1 fac3
1   male    -2    0.1 lev2
2 female    -1    0.1 lev1
  factors: sex3 fac3
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[2,4]:
    sex3 ldose ldose1 fac3
1   male    -2    0.1 lev2
2 female    -1    0.1 lev1
  factors: sex3 fac3
predict.earth with newdata: bx[2,4]:
  (Intercept) ldose h(ldose1-2.5) h(2.5-ldose1)
1           1    -2             0           2.4
2           1    -1             0           2.4
predict.earth: returning earth predictions 
       numdead  numdead2
[1,]  1.577732  1.587702
[2,] 22.663117 20.019737
B-56 identical
B-57m predict(am, xdata.frame, trace=1) data frame with not enough columns, expect error message
Error : get.earth.x from model.matrix.earth from predict.earth: x has 2 columns but expected 4
       column names: sex3.c.1..7.. c..2...1.
       expected column names: sex3 ldose ldose1 fac3
Got error as expected from try(predict(am, xdata.frame, trace = trace))
B-57f predict(af, xdata.frame, trace=1) data frame with not enough columns, expect error message
Error : get.earth.x from model.matrix.earth from predict.earth: x has 2 columns but expected 4
       column names: sex3.c.1..7.. c..2...1.
       expected column names: sex3 ldose ldose1 fac3
Got error as expected from try(predict(af, xdata.frame, trace = trace))
B-57 identical
B-58m predict(am, xdata.frame, trace=1) # data frame with cols in different order
get.earth.x from model.matrix.earth from predict.earth: x columns are in the wrong order, correcting the column order
    Old columns: ldose sex3 ldose1 fac3
    New columns: sex3 ldose ldose1 fac3
get.earth.x from model.matrix.earth from predict.earth: x[2,4]:
    sex3 ldose ldose1 fac3
1   male    -2    0.1 lev2
2 female    -1    0.1 lev1
  factors: sex3 fac3
predict.earth with newdata: bx[2,4]:
  (Intercept) ldose h(ldose1-2.5) h(2.5-ldose1)
1           1    -2             0           2.4
2           1    -1             0           2.4
predict.earth: returning earth predictions 
       numdead  numdead2
[1,]  1.577732  1.587702
[2,] 22.663117 20.019737
B-58 identical
B-58f predict(af, xdata.frame, trace=1) # data frame with cols in different order
get.earth.x from model.matrix.earth from predict.earth: x columns are in the wrong order, correcting the column order
    Old columns: ldose sex3 ldose1 fac3
    New columns: sex3 ldose ldose1 fac3
get.earth.x from model.matrix.earth from predict.earth: x[2,4]:
    sex3 ldose ldose1 fac3
1   male    -2    0.1 lev2
2 female    -1    0.1 lev1
  factors: sex3 fac3
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[2,4]:
    sex3 ldose ldose1 fac3
1   male    -2    0.1 lev2
2 female    -1    0.1 lev1
  factors: sex3 fac3
predict.earth with newdata: bx[2,4]:
  (Intercept) ldose h(ldose1-2.5) h(2.5-ldose1)
1           1    -2             0           2.4
2           1    -1             0           2.4
predict.earth: returning earth predictions 
       numdead  numdead2
[1,]  1.577732  1.587702
[2,] 22.663117 20.019737
B-58 identical
B-50m data frame without column names, trace=1
get.earth.x from model.matrix.earth from predict.earth: x has no column names, adding column names: sex3 ldose ldose1 fac3
get.earth.x from model.matrix.earth from predict.earth: x[1,4]:
  sex3 ldose ldose1 fac3
1 male    -2    0.1 lev2
  factors: sex3 fac3
predict.earth with newdata: bx[1,4]:
  (Intercept) ldose h(ldose1-2.5) h(2.5-ldose1)
1           1    -2             0           2.4
predict.earth: returning earth predictions 
      numdead numdead2
[1,] 1.577732 1.587702
B-34 identical
B-60f data frame without column names, trace=1
get.earth.x from model.matrix.earth from predict.earth: x has no column names, adding column names: sex3 ldose ldose1 fac3
get.earth.x from model.matrix.earth from predict.earth: x[1,4]:
  sex3 ldose ldose1 fac3
1 male    -2    0.1 lev2
  factors: sex3 fac3
predict.earth with newdata: bx[1,4]:
  (Intercept) ldose h(ldose1-2.5) h(2.5-ldose1)
1           1    -2             0           2.4
predict.earth: returning earth predictions 
      numdead numdead2
[1,] 1.577732 1.587702
B-60 identical
B-60f data frame without extra columns, trace=1
get.earth.x from model.matrix.earth from predict.earth: x[1,7]:
  sex3 extra1 ldose extra2 ldose1 fac3 extra3
1 male     99    -2     99    0.1 lev2 female
  factors: sex3 fac3 extra3
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[1,4]:
  sex3 ldose ldose1 fac3
1 male    -2    0.1 lev2
  factors: sex3 fac3
predict.earth with newdata: bx[1,4]:
  (Intercept) ldose h(ldose1-2.5) h(2.5-ldose1)
1           1    -2             0           2.4
predict.earth: returning earth predictions 
      numdead numdead2
[1,] 1.577732 1.587702
B-60f identical

--- C predict with multiple level factors and a 3 level factor response, trace=1 ---

x[12,6] with colnames sex3female sex3male ldose ldose1 fac3lev2 fac3lev3
y[12,3] with colnames dead1 dead2 dead3
Forward pass term 1, 2, 4
Reached nk 6
After forward pass GRSq -2.977 RSq 0.597
Prune none penalty 3 nprune null: selected 4 of 4 terms, and 2 of 6 preds
After pruning pass GRSq -2.98 RSq 0.597
x[12,6] with colnames sex3female sex3male ldose ldose1 fac3lev2 fac3lev3
y[12,3] with colnames dead1 dead2 dead3
Forward pass term 1, 2, 4
Reached nk 6
After forward pass GRSq -2.977 RSq 0.597
Prune none penalty 3 nprune null: selected 4 of 4 terms, and 2 of 6 preds
After pruning pass GRSq -2.98 RSq 0.597
C predict with multiple level factors and a multiple real response: models not identical

Formulas differ: Error in formula.default(mod1) : invalid formula
and:             facdead ~ sex3 + ldose + ldose1 + fac3

C predict with multiple level factors and a multiple real response: Models are equivalent, within numerical tolerances

20m head(predict(am, trace=1)
predict.earth: returning earth fitted.values 
           dead1       dead2       dead3
[1,]  0.48796881  0.55646922 -0.04443804
[2,] -0.17857394  1.04640569  0.13216825
[3,]  0.61065675  0.20356630  0.18577695
[4,]  0.63869210 -0.05928628  0.42059419
[5,]  0.30641076 -0.01824193  0.71183118
[6,] -0.02587059  0.02280242  1.00306817
C-21f head(predict(af, trace=1)
predict.earth: returning earth fitted.values 
           dead1       dead2       dead3
[1,]  0.48796881  0.55646922 -0.04443804
[2,] -0.17857394  1.04640569  0.13216825
[3,]  0.61065675  0.20356630  0.18577695
[4,]  0.63869210 -0.05928628  0.42059419
[5,]  0.30641076 -0.01824193  0.71183118
[6,] -0.02587059  0.02280242  1.00306817
C-20 identical
C-31m predict(am, xdata.frame, trace=1) data frame with factors and wrong col names
get.earth.x from model.matrix.earth from predict.earth: unexpected x column names, renaming columns
    Old names: sex3.1. X.2 X0.1 fac3.1.
    New names: sex3 ldose ldose1 fac3
get.earth.x from model.matrix.earth from predict.earth: x[1,4]:
  sex3 ldose ldose1 fac3
1 male    -2    0.1 lev2
  factors: sex3 fac3
predict.earth with newdata: bx[1,4]:
  (Intercept) h(ldose1-2.5) h(2.5-ldose1) ldose*h(2.5-ldose1)
1           1             0           2.4                -4.8
predict.earth: returning earth predictions 
C-31 identical
         dead1     dead2       dead3
[1,] 0.4879688 0.5564692 -0.04443804
C-31f predict(af, xdata.frame, trace=1) data frame with factors and wrong col names
get.earth.x from model.matrix.earth from predict.earth: unexpected x column names, renaming columns
    Old names: sex3.1. X.2 X0.1 fac3.1.
    New names: sex3 ldose ldose1 fac3
get.earth.x from model.matrix.earth from predict.earth: x[1,4]:
  sex3 ldose ldose1 fac3
1 male    -2    0.1 lev2
  factors: sex3 fac3
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[1,4]:
  sex3 ldose ldose1 fac3
1 male    -2    0.1 lev2
  factors: sex3 fac3
predict.earth with newdata: bx[1,4]:
  (Intercept) h(ldose1-2.5) h(2.5-ldose1) ldose*h(2.5-ldose1)
1           1             0           2.4                -4.8
predict.earth: returning earth predictions 
         dead1     dead2       dead3
[1,] 0.4879688 0.5564692 -0.04443804
C-31 identical
C-31bm predict(am, xdata.frame, trace=1) data frame col names
get.earth.x from model.matrix.earth from predict.earth: x[1,4]:
  sex3 ldose ldose1 fac3
1 male    -2    0.1 lev2
  factors: sex3 fac3
predict.earth with newdata: bx[1,4]:
  (Intercept) h(ldose1-2.5) h(2.5-ldose1) ldose*h(2.5-ldose1)
1           1             0           2.4                -4.8
predict.earth: returning earth predictions 
         dead1     dead2       dead3
[1,] 0.4879688 0.5564692 -0.04443804
C-31 identical
C-31bf predict(af, xdata.frame, trace=1) data frame col names
get.earth.x from model.matrix.earth from predict.earth: x[1,4]:
  sex3 ldose ldose1 fac3
1 male    -2    0.1 lev2
  factors: sex3 fac3
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[1,4]:
  sex3 ldose ldose1 fac3
1 male    -2    0.1 lev2
  factors: sex3 fac3
predict.earth with newdata: bx[1,4]:
  (Intercept) h(ldose1-2.5) h(2.5-ldose1) ldose*h(2.5-ldose1)
1           1             0           2.4                -4.8
predict.earth: returning earth predictions 
         dead1     dead2       dead3
[1,] 0.4879688 0.5564692 -0.04443804
C-31b identical
C-32m predict(am, xdata.frame, trace=1) # data frame with names
get.earth.x from model.matrix.earth from predict.earth: x[1,4]:
  sex3 ldose ldose1 fac3
1 male    -2    0.1 lev2
  factors: sex3 fac3
predict.earth with newdata: bx[1,4]:
  (Intercept) h(ldose1-2.5) h(2.5-ldose1) ldose*h(2.5-ldose1)
1           1             0           2.4                -4.8
predict.earth: returning earth predictions 
         dead1     dead2       dead3
[1,] 0.4879688 0.5564692 -0.04443804
C-32 identical
C-32 identical
C-32f predict(af, xdata.frame, trace=1) # data frame with names
get.earth.x from model.matrix.earth from predict.earth: x[1,4]:
  sex3 ldose ldose1 fac3
1 male    -2    0.1 lev2
  factors: sex3 fac3
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[1,4]:
  sex3 ldose ldose1 fac3
1 male    -2    0.1 lev2
  factors: sex3 fac3
predict.earth with newdata: bx[1,4]:
  (Intercept) h(ldose1-2.5) h(2.5-ldose1) ldose*h(2.5-ldose1)
1           1             0           2.4                -4.8
predict.earth: returning earth predictions 
         dead1     dead2       dead3
[1,] 0.4879688 0.5564692 -0.04443804
C-32 identical
C-53m predict(am, xdata.frame, trace=1) data frame with not enough columns, expect error message
Error : get.earth.x from model.matrix.earth from predict.earth: x has 2 columns but expected 4
       column names: sex3.1. X.2
       expected column names: sex3 ldose ldose1 fac3
Got error as expected from try(predict(am, xdata.frame, trace = trace))
C-53f predict(af, xdata.frame, trace=1) data frame with not enough columns, expect error message
Error : get.earth.x from model.matrix.earth from predict.earth: x has 2 columns but expected 4
       column names: sex3.1. X.2
       expected column names: sex3 ldose ldose1 fac3
Got error as expected from try(predict(af, xdata.frame, trace = trace))
C-54m predict(am, xdata.frame, trace=1) # data frame with cols in different order
get.earth.x from model.matrix.earth from predict.earth: x columns are in the wrong order, correcting the column order
    Old columns: ldose sex3 ldose1 fac3
    New columns: sex3 ldose ldose1 fac3
get.earth.x from model.matrix.earth from predict.earth: x[1,4]:
  sex3 ldose ldose1 fac3
1 male    -2    0.1 lev2
  factors: sex3 fac3
predict.earth with newdata: bx[1,4]:
  (Intercept) h(ldose1-2.5) h(2.5-ldose1) ldose*h(2.5-ldose1)
1           1             0           2.4                -4.8
predict.earth: returning earth predictions 
         dead1     dead2       dead3
[1,] 0.4879688 0.5564692 -0.04443804
C-54 identical
C-54f predict(af, xdata.frame, trace=1) # data frame with cols in different order
get.earth.x from model.matrix.earth from predict.earth: x columns are in the wrong order, correcting the column order
    Old columns: ldose sex3 ldose1 fac3
    New columns: sex3 ldose ldose1 fac3
get.earth.x from model.matrix.earth from predict.earth: x[1,4]:
  sex3 ldose ldose1 fac3
1 male    -2    0.1 lev2
  factors: sex3 fac3
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[1,4]:
  sex3 ldose ldose1 fac3
1 male    -2    0.1 lev2
  factors: sex3 fac3
predict.earth with newdata: bx[1,4]:
  (Intercept) h(ldose1-2.5) h(2.5-ldose1) ldose*h(2.5-ldose1)
1           1             0           2.4                -4.8
predict.earth: returning earth predictions 
         dead1     dead2       dead3
[1,] 0.4879688 0.5564692 -0.04443804
C-54 identical
C-55m predict(am, xdata.frame, trace=1) data frame without col names
get.earth.x from model.matrix.earth from predict.earth: unexpected x column names, renaming columns
    Old names: sex3.c.1..7.. c..2...1. c.0.1..0.1. fac3.c.1..9..
    New names: sex3 ldose ldose1 fac3
get.earth.x from model.matrix.earth from predict.earth: x[2,4]:
    sex3 ldose ldose1 fac3
1   male    -2    0.1 lev2
2 female    -1    0.1 lev1
  factors: sex3 fac3
predict.earth with newdata: bx[2,4]:
  (Intercept) h(ldose1-2.5) h(2.5-ldose1) ldose*h(2.5-ldose1)
1           1             0           2.4                -4.8
2           1             0           2.4                -2.4
predict.earth: returning earth predictions 
          dead1     dead2       dead3
[1,]  0.4879688 0.5564692 -0.04443804
[2,] -1.1001477 2.0104065  0.08974114
C-55f predict(af, xdata.frame, trace=1) data frame without col names
get.earth.x from model.matrix.earth from predict.earth: unexpected x column names, renaming columns
    Old names: sex3.c.1..7.. c..2...1. c.0.1..0.1. fac3.c.1..9..
    New names: sex3 ldose ldose1 fac3
get.earth.x from model.matrix.earth from predict.earth: x[2,4]:
    sex3 ldose ldose1 fac3
1   male    -2    0.1 lev2
2 female    -1    0.1 lev1
  factors: sex3 fac3
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[2,4]:
    sex3 ldose ldose1 fac3
1   male    -2    0.1 lev2
2 female    -1    0.1 lev1
  factors: sex3 fac3
predict.earth with newdata: bx[2,4]:
  (Intercept) h(ldose1-2.5) h(2.5-ldose1) ldose*h(2.5-ldose1)
1           1             0           2.4                -4.8
2           1             0           2.4                -2.4
predict.earth: returning earth predictions 
          dead1     dead2       dead3
[1,]  0.4879688 0.5564692 -0.04443804
[2,] -1.1001477 2.0104065  0.08974114
C-55 identical
C2-55bm predict(am, xdata.frame, trace=1) data frame col names
get.earth.x from model.matrix.earth from predict.earth: x[2,4]:
    sex3 ldose ldose1 fac3
1   male    -2    0.1 lev2
2 female    -1    0.1 lev1
  factors: sex3 fac3
predict.earth with newdata: bx[2,4]:
  (Intercept) h(ldose1-2.5) h(2.5-ldose1) ldose*h(2.5-ldose1)
1           1             0           2.4                -4.8
2           1             0           2.4                -2.4
predict.earth: returning earth predictions 
          dead1     dead2       dead3
[1,]  0.4879688 0.5564692 -0.04443804
[2,] -1.1001477 2.0104065  0.08974114
C2-55 identical
C2-55bf predict(af, xdata.frame, trace=1) data frame col names
get.earth.x from model.matrix.earth from predict.earth: x[2,4]:
    sex3 ldose ldose1 fac3
1   male    -2    0.1 lev2
2 female    -1    0.1 lev1
  factors: sex3 fac3
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[2,4]:
    sex3 ldose ldose1 fac3
1   male    -2    0.1 lev2
2 female    -1    0.1 lev1
  factors: sex3 fac3
predict.earth with newdata: bx[2,4]:
  (Intercept) h(ldose1-2.5) h(2.5-ldose1) ldose*h(2.5-ldose1)
1           1             0           2.4                -4.8
2           1             0           2.4                -2.4
predict.earth: returning earth predictions 
          dead1     dead2       dead3
[1,]  0.4879688 0.5564692 -0.04443804
[2,] -1.1001477 2.0104065  0.08974114
C2-55b identical
C-56m predict(am, xdata.frame, trace=1) # data frame with col names
get.earth.x from model.matrix.earth from predict.earth: x[2,4]:
    sex3 ldose ldose1 fac3
1   male    -2    0.1 lev2
2 female    -1    0.1 lev1
  factors: sex3 fac3
predict.earth with newdata: bx[2,4]:
  (Intercept) h(ldose1-2.5) h(2.5-ldose1) ldose*h(2.5-ldose1)
1           1             0           2.4                -4.8
2           1             0           2.4                -2.4
predict.earth: returning earth predictions 
          dead1     dead2       dead3
[1,]  0.4879688 0.5564692 -0.04443804
[2,] -1.1001477 2.0104065  0.08974114
C-56 identical
C-56f predict(af, xdata.frame, trace=1) # data frame with col names
get.earth.x from model.matrix.earth from predict.earth: x[2,4]:
    sex3 ldose ldose1 fac3
1   male    -2    0.1 lev2
2 female    -1    0.1 lev1
  factors: sex3 fac3
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[2,4]:
    sex3 ldose ldose1 fac3
1   male    -2    0.1 lev2
2 female    -1    0.1 lev1
  factors: sex3 fac3
predict.earth with newdata: bx[2,4]:
  (Intercept) h(ldose1-2.5) h(2.5-ldose1) ldose*h(2.5-ldose1)
1           1             0           2.4                -4.8
2           1             0           2.4                -2.4
predict.earth: returning earth predictions 
          dead1     dead2       dead3
[1,]  0.4879688 0.5564692 -0.04443804
[2,] -1.1001477 2.0104065  0.08974114
C-56 identical
C-57m predict(am, xdata.frame, trace=1) data frame with not enough columns, expect error message
Error : get.earth.x from model.matrix.earth from predict.earth: x has 2 columns but expected 4
       column names: sex3.c.1..7.. c..2...1.
       expected column names: sex3 ldose ldose1 fac3
Got error as expected from try(predict(am, xdata.frame, trace = trace))
C-57f predict(af, xdata.frame, trace=1) data frame with not enough columns, expect error message
Error : get.earth.x from model.matrix.earth from predict.earth: x has 2 columns but expected 4
       column names: sex3.c.1..7.. c..2...1.
       expected column names: sex3 ldose ldose1 fac3
Got error as expected from try(predict(af, xdata.frame, trace = trace))
C-57 identical
C-58m predict(am, xdata.frame, trace=1) # data frame with cols in different order
get.earth.x from model.matrix.earth from predict.earth: x columns are in the wrong order, correcting the column order
    Old columns: ldose sex3 ldose1 fac3
    New columns: sex3 ldose ldose1 fac3
get.earth.x from model.matrix.earth from predict.earth: x[2,4]:
    sex3 ldose ldose1 fac3
1   male    -2    0.1 lev2
2 female    -1    0.1 lev1
  factors: sex3 fac3
predict.earth with newdata: bx[2,4]:
  (Intercept) h(ldose1-2.5) h(2.5-ldose1) ldose*h(2.5-ldose1)
1           1             0           2.4                -4.8
2           1             0           2.4                -2.4
predict.earth: returning earth predictions 
          dead1     dead2       dead3
[1,]  0.4879688 0.5564692 -0.04443804
[2,] -1.1001477 2.0104065  0.08974114
C-58 identical
C-58f predict(af, xdata.frame, trace=1) # data frame with cols in different order
get.earth.x from model.matrix.earth from predict.earth: x columns are in the wrong order, correcting the column order
    Old columns: ldose sex3 ldose1 fac3
    New columns: sex3 ldose ldose1 fac3
get.earth.x from model.matrix.earth from predict.earth: x[2,4]:
    sex3 ldose ldose1 fac3
1   male    -2    0.1 lev2
2 female    -1    0.1 lev1
  factors: sex3 fac3
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[2,4]:
    sex3 ldose ldose1 fac3
1   male    -2    0.1 lev2
2 female    -1    0.1 lev1
  factors: sex3 fac3
predict.earth with newdata: bx[2,4]:
  (Intercept) h(ldose1-2.5) h(2.5-ldose1) ldose*h(2.5-ldose1)
1           1             0           2.4                -4.8
2           1             0           2.4                -2.4
predict.earth: returning earth predictions 
          dead1     dead2       dead3
[1,]  0.4879688 0.5564692 -0.04443804
[2,] -1.1001477 2.0104065  0.08974114
C-58 identical
C-50m data frame without column names, trace=1
get.earth.x from model.matrix.earth from predict.earth: x has no column names, adding column names: sex3 ldose ldose1 fac3
get.earth.x from model.matrix.earth from predict.earth: x[1,4]:
  sex3 ldose ldose1 fac3
1 male    -2    0.1 lev2
  factors: sex3 fac3
predict.earth with newdata: bx[1,4]:
  (Intercept) h(ldose1-2.5) h(2.5-ldose1) ldose*h(2.5-ldose1)
1           1             0           2.4                -4.8
predict.earth: returning earth predictions 
         dead1     dead2       dead3
[1,] 0.4879688 0.5564692 -0.04443804
C-34 identical
C-60f data frame without column names, trace=1
get.earth.x from model.matrix.earth from predict.earth: x has no column names, adding column names: sex3 ldose ldose1 fac3
get.earth.x from model.matrix.earth from predict.earth: x[1,4]:
  sex3 ldose ldose1 fac3
1 male    -2    0.1 lev2
  factors: sex3 fac3
predict.earth with newdata: bx[1,4]:
  (Intercept) h(ldose1-2.5) h(2.5-ldose1) ldose*h(2.5-ldose1)
1           1             0           2.4                -4.8
predict.earth: returning earth predictions 
         dead1     dead2       dead3
[1,] 0.4879688 0.5564692 -0.04443804
C-60 identical
C-61f data frame without extra columns, trace=1
get.earth.x from model.matrix.earth from predict.earth: x[1,7]:
  sex3 extra1 ldose extra2 ldose1 fac3 extra3
1 male     99    -2     99    0.1 lev2 female
  factors: sex3 fac3 extra3
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[1,4]:
  sex3 ldose ldose1 fac3
1 male    -2    0.1 lev2
  factors: sex3 fac3
predict.earth with newdata: bx[1,4]:
  (Intercept) h(ldose1-2.5) h(2.5-ldose1) ldose*h(2.5-ldose1)
1           1             0           2.4                -4.8
predict.earth: returning earth predictions 
         dead1     dead2       dead3
[1,] 0.4879688 0.5564692 -0.04443804
C-61 identical
> test.predict.with.factors(trace=0)

--- predict with single level factors and a single response, trace=0 ---

first do a quick test of predict.earth help page example
predict with single level factors and a single response: models not identical

Formulas differ: Error in formula.default(mod1) : invalid formula
and:             numdead ~ sex + ldose + ldose1

predict with single level factors and a single response: Models are equivalent, within numerical tolerances

A-20m head(predict(am, trace=0)
A-20f head(predict(af, trace=0)
A-20 identical
A-21m predict(am, newdata=c(sex[1], -2, 0.1), trace=0))
A-21f predict(af, newdata=c(sex[1], -2, 0.1), trace=0))
Warning in model.frame.default(terms.without.response, data = data, na.action = na.pass,  :
  variable 'sex' is not a factor
Error : variable 'sex' was fitted with type "factor" but type "numeric" was supplied
Continuing anyway, first few rows of modelframe are
  sex ldose ldose1
1   1    -2    0.1
A-21 identical
A-22m predict(am, newdata=c(1, -2, 0.1), trace=0)) use numeric instead of factor sex
A-22 identical
A-22f predict(af, newdata=c(1, -2, 0.1), trace=0)) use numeric instead of factor sex
Warning in model.frame.default(terms.without.response, data = data, na.action = na.pass,  :
  variable 'sex' is not a factor
Error : variable 'sex' was fitted with type "factor" but type "numeric" was supplied
Continuing anyway, first few rows of modelframe are
  sex ldose ldose1
1   1    -2    0.1
A-22 identical
A-23m predict(am, newdata=c(sex[1], sex[1], -2, -2, 0.1, 0.1), trace=0)) multiple rows as a vec
A-23f predict(af, newdata=c(sex[1], sex[1], -2, -2, 0.1, 0.1), trace=0)) multiple rows as a vec
Warning in model.frame.default(terms.without.response, data = data, na.action = na.pass,  :
  variable 'sex' is not a factor
Error : variable 'sex' was fitted with type "factor" but type "numeric" was supplied
Continuing anyway, first few rows of modelframe are
  sex ldose ldose1
1   2    -2    0.1
2   2    -2    0.1
A-23 identical
A-24m predict(am, newdata=c(sex[1], sex[1], -2, -1, 0.1, 0.1), trace=0)) more multiple rows as a vec
A-24f predict(af, newdata=c(sex[1], sex[1], -2, -1, 0.1, 0.1), trace=0)) more multiple rows as a vec
Warning in model.frame.default(terms.without.response, data = data, na.action = na.pass,  :
  variable 'sex' is not a factor
Error : variable 'sex' was fitted with type "factor" but type "numeric" was supplied
Continuing anyway, first few rows of modelframe are
  sex ldose ldose1
1   2    -2    0.1
2   2    -1    0.1
A-24 identical
A-25m predict(am, xpredict matrix trace=0
A-25 identical
A-25f predict(af, xpredict matrix trace=0
Warning in model.frame.default(terms.without.response, data = data, na.action = na.pass,  :
  variable 'sex' is not a factor
Error : variable 'sex' was fitted with type "factor" but type "numeric" was supplied
Continuing anyway, first few rows of modelframe are
  sex ldose ldose1
1   2    -2    0.1
2   2    -1    0.1
A-25 identical
A-26m predict(am, new.data with col names) trace=0
A-26m identical
A-26f predict(af, new.data with col names) trace=0
Warning in model.frame.default(terms.without.response, data = data, na.action = na.pass,  :
  variable 'sex' is not a factor
Error : variable 'sex' was fitted with type "factor" but type "numeric" was supplied
Continuing anyway, first few rows of modelframe are
  sex ldose ldose1
1   2    -2    0.1
2   2    -1    0.1
A-26f identical
A-27m predict(am, new.data with out of order col names) trace=0
A-27 identical
A-27f predict(af, new.data with out of order col names) trace=0
Warning in model.frame.default(terms.without.response, data = data, na.action = na.pass,  :
  variable 'sex' is not a factor
Error : variable 'sex' was fitted with type "factor" but type "numeric" was supplied
Continuing anyway, first few rows of modelframe are
  sex ldose ldose1
1   2    -2    0.1
2   2    -1    0.1
A-27 identical
A-28m predict(am, xdata.frame without col names) trace=0
A-28 identical
A-28f predict(af, xdata.frame without col names) trace=0
Warning in model.frame.default(terms.without.response, data = data, na.action = na.pass,  :
  variable 'sex' is not a factor
Error : variable 'sex' was fitted with type "factor" but type "numeric" was supplied
Continuing anyway, first few rows of modelframe are
  sex ldose ldose1
1   2    -2    0.1
2   2    -1    0.1
A-28 identical
A-29m predict(am, xdata.frame with col names) trace=0
A-29 identical
A-29f predict(af, xdata.frame with col names) trace=0
A-29 identical
A2-29m predict(am, xdata.frame with col names) trace=0
A2-29 identical
A2-29f predict(af, xdata.frame with col names) trace=0
Warning in model.frame.default(terms.without.response, data = data, na.action = na.pass,  :
  variable 'sex' is not a factor
Error : variable 'sex' was fitted with type "factor" but type "numeric" was supplied
Continuing anyway, first few rows of modelframe are
  sex ldose ldose1
1   2    -2    0.1
2   2    -1    0.1
A2-29 identical
A-31m predict(am, xdata.frame, trace=0) data frame with factors and wrong col names
A-31 identical
A-31f predict(af, xdata.frame, trace=0) data frame with factors and wrong col names
A-31 identical
A-31bm predict(am, xdata.frame, trace=0) data frame col names
A-31 identical
A-31bf predict(af, xdata.frame, trace=0) data frame col names
A-31b identical
A-32m predict(am, xdata.frame, trace=0) # data frame with names
A-32 identical
A-32 identical
A-32f predict(af, xdata.frame, trace=0) # data frame with names
A-32 identical
A-42am predict(am, newdata=c(1, -2, 0.1), trace=0)) use numeric instead of factor sex
A-42a identical
A-42af predict(af, newdata=c(1, -2, 0.1), trace=0)) use numeric instead of factor sex
Warning in model.frame.default(terms.without.response, data = data, na.action = na.pass,  :
  variable 'sex' is not a factor
Error : variable 'sex' was fitted with type "factor" but type "numeric" was supplied
Continuing anyway, first few rows of modelframe are
  sex ldose ldose1
1   1    -2    0.1
A-42a identical
A-43am predict(af, newdata=c(sex[1], sex[1], -2, -2, 0.1, 0.1), trace=0)) multiple rows as a vec
Warning in model.frame.default(terms.without.response, data = data, na.action = na.pass,  :
  variable 'sex' is not a factor
Error : variable 'sex' was fitted with type "factor" but type "numeric" was supplied
Continuing anyway, first few rows of modelframe are
  sex ldose ldose1
1   2    -2    0.1
2   2    -2    0.1
A-43af predict(am, newdata=c(sex[1], sex[1], -2, -2, 0.1, 0.1), trace=0)) multiple rows as a vec
A-43a identical
A-44am predict(af, newdata=c(sex[1], sex[1], -2, -1, 0.1, 0.1), trace=0)) more multiple rows as a vec
Warning in model.frame.default(terms.without.response, data = data, na.action = na.pass,  :
  variable 'sex' is not a factor
Error : variable 'sex' was fitted with type "factor" but type "numeric" was supplied
Continuing anyway, first few rows of modelframe are
  sex ldose ldose1
1   2    -2    0.1
2   2    -1    0.1
A-44a identical
A-44fm predict(am, newdata=c(sex[1], sex[1], -2, -1, 0.1, 0.1), trace=0)) more multiple rows as a vec
A-44f identical
A-53m predict(am, xdata.frame, trace=0) data frame with not enough columns, expect error message
Error : get.earth.x from model.matrix.earth from predict.earth: x has 2 columns but expected 3
       column names: sex.1. X.2
       expected column names: sexmale ldose ldose1
Got error as expected from try(predict(am, xdata.frame, trace = trace))
A-53f predict(af, xdata.frame, trace=0) data frame with not enough columns, expect error message
Error : get.earth.x from model.matrix.earth from predict.earth: x has 2 columns but expected 3
       column names: sex.1. X.2
       expected column names: sex ldose ldose1
Got error as expected from try(predict(af, xdata.frame, trace = trace))
A-54m predict(am, xdata.frame, trace=0) # data frame with cols in different order
A-54 identical
A-54f predict(af, xdata.frame, trace=0) # data frame with cols in different order
A-54 identical
A-55m predict(am, xdata.frame, trace=0) data frame without col names
A-55f predict(af, xdata.frame, trace=0) data frame without col names
A-55 identical
A-56m predict(am, xdata.frame, trace=0) # data frame with col names
A-56 identical
A-56f predict(af, xdata.frame, trace=0) # data frame with col names
A-56 identical
A-57m predict(am, xdata.frame, trace=0) data frame with not enough columns, expect error message
Error : get.earth.x from model.matrix.earth from predict.earth: x has 2 columns but expected 3
       column names: sex.c.1..7.. c..2...1.
       expected column names: sexmale ldose ldose1
Got error as expected from try(predict(am, xdata.frame, trace = trace))
A-57f predict(af, xdata.frame, trace=0) data frame with not enough columns, expect error message
Error : get.earth.x from model.matrix.earth from predict.earth: x has 2 columns but expected 3
       column names: sex.c.1..7.. c..2...1.
       expected column names: sex ldose ldose1
Got error as expected from try(predict(af, xdata.frame, trace = trace))
A-57 identical
A-58m predict(am, xdata.frame, trace=0) # data frame with cols in different order
A-58 identical
A-58f predict(af, xdata.frame, trace=0) # data frame with cols in different order
A-58 identical
A-59m predict(am, xdata.frame, trace=0) numeric where factor expected, expect forge on message
A-59f predict(af, xdata.frame, trace=0) numeric where factor expected, expect forge on message
Warning in model.frame.default(terms.without.response, data = data, na.action = na.pass,  :
  variable 'sex' is not a factor
Error : variable 'sex' was fitted with type "factor" but type "numeric" was supplied
Continuing anyway, first few rows of modelframe are
  sex ldose ldose1
1   2    -2    0.1
2   1    -1    0.1
A-59 identical
A-50m data frame without column names, trace=0
A-34 identical
A-60f data frame without column names, trace=0
A-60 identical
A-61f data frame without extra columns, trace=0
A-61 identical
A-68 input matrix to formula interface trace=0, expect error "could not interpret"
Error : model.frame.default could not interpret the data passed to get.earth.x from model.matrix.earth from predict.earth
        (actual.nrows=60 expected.nrows=1 fitted.nrows=60)
Got error as expected from try(predict(a41, c(2.1, 0.6), trace = trace))
A-69 above test but with properly named dataframe trace=0
Tests with not all predictors used in the model so can pass fewer columns
A-72m predict(am, newdata=newdata[two columns], trace=trace)
A-72m identical
   ldose dummy ldose1
1     -2     0    0.1
2     -1     0    1.2
3      0     0    0.1
4      1     0    1.2
5      2     0    1.0
6      3     0    0.1
7     -2     0    0.3
8     -1     0    1.4
9      0     0    0.1
10     1     0    1.2
11     2     0    0.1
12     3     0    0.9
A-73m predict(am, newdata=newdata[two columns], trace=trace)
A-73m identical
A-72f predict(af, newdata=newdata[two columns], trace=trace)
A-72f identical
   ldose dummy ldose1
1     -2     0    0.1
2     -1     0    1.2
3      0     0    0.1
4      1     0    1.2
5      2     0    1.0
6      3     0    0.1
7     -2     0    0.3
8     -1     0    1.4
9      0     0    0.1
10     1     0    1.2
11     2     0    0.1
12     3     0    0.9
A-73f predict(af, newdata=newdata[two columns], trace=trace)
A-73f identical

--- B predict with multiple level factors and a multiple real response, trace=0 ---

B predict with multiple level factors and a multiple real response: models not identical

Formulas differ: Error in formula.default(mod1) : invalid formula
and:             numdeadboth ~ sex3 + ldose + ldose1 + fac3

B predict with multiple level factors and a multiple real response: Models are equivalent, within numerical tolerances

20m head(predict(am, trace=0)
B-21f head(predict(af, trace=0)
B-20 identical
B-31m predict(am, xdata.frame, trace=0) data frame with factors and wrong col names
B-31 identical
B-31f predict(af, xdata.frame, trace=0) data frame with factors and wrong col names
B-31 identical
B-31bm predict(am, xdata.frame, trace=0) data frame col names
B-31 identical
B-31bf predict(af, xdata.frame, trace=0) data frame col names
B-31b identical
B-32m predict(am, xdata.frame, trace=0) # data frame with names
B-32 identical
B-32 identical
B-32f predict(af, xdata.frame, trace=0) # data frame with names
B-32 identical
B-53m predict(am, xdata.frame, trace=0) data frame with not enough columns, expect error message
Error : get.earth.x from model.matrix.earth from predict.earth: x has 2 columns but expected 4
       column names: sex3.1. X.2
       expected column names: sex3 ldose ldose1 fac3
Got error as expected from try(predict(am, xdata.frame, trace = trace))
B-53f predict(af, xdata.frame, trace=0) data frame with not enough columns, expect error message
Error : get.earth.x from model.matrix.earth from predict.earth: x has 2 columns but expected 4
       column names: sex3.1. X.2
       expected column names: sex3 ldose ldose1 fac3
Got error as expected from try(predict(af, xdata.frame, trace = trace))
B-54m predict(am, xdata.frame, trace=0) # data frame with cols in different order
B-54 identical
B-54f predict(af, xdata.frame, trace=0) # data frame with cols in different order
B-54 identical
B-55m predict(am, xdata.frame, trace=0) data frame without col names
B-55m again, but with same x data for both reponses
      numdead numdead2
[1,] 1.577732 1.587702
[2,] 1.577732 1.587702
B-55f predict(af, xdata.frame, trace=0) data frame without col names
B-55 identical
B2-55bm predict(am, xdata.frame, trace=0) data frame col names
B2-55 identical
B2-55bf predict(af, xdata.frame, trace=0) data frame col names
B2-55b identical
B-56m predict(am, xdata.frame, trace=0) # data frame with col names
B-56 identical
B-56f predict(af, xdata.frame, trace=0) # data frame with col names
B-56 identical
B-57m predict(am, xdata.frame, trace=0) data frame with not enough columns, expect error message
Error : get.earth.x from model.matrix.earth from predict.earth: x has 2 columns but expected 4
       column names: sex3.c.1..7.. c..2...1.
       expected column names: sex3 ldose ldose1 fac3
Got error as expected from try(predict(am, xdata.frame, trace = trace))
B-57f predict(af, xdata.frame, trace=0) data frame with not enough columns, expect error message
Error : get.earth.x from model.matrix.earth from predict.earth: x has 2 columns but expected 4
       column names: sex3.c.1..7.. c..2...1.
       expected column names: sex3 ldose ldose1 fac3
Got error as expected from try(predict(af, xdata.frame, trace = trace))
B-57 identical
B-58m predict(am, xdata.frame, trace=0) # data frame with cols in different order
B-58 identical
B-58f predict(af, xdata.frame, trace=0) # data frame with cols in different order
B-58 identical
B-50m data frame without column names, trace=0
B-34 identical
B-60f data frame without column names, trace=0
B-60 identical
B-60f data frame without extra columns, trace=0
B-60f identical

--- C predict with multiple level factors and a 3 level factor response, trace=0 ---

C predict with multiple level factors and a multiple real response: models not identical

Formulas differ: Error in formula.default(mod1) : invalid formula
and:             facdead ~ sex3 + ldose + ldose1 + fac3

C predict with multiple level factors and a multiple real response: Models are equivalent, within numerical tolerances

20m head(predict(am, trace=0)
C-21f head(predict(af, trace=0)
C-20 identical
C-31m predict(am, xdata.frame, trace=0) data frame with factors and wrong col names
C-31 identical
C-31f predict(af, xdata.frame, trace=0) data frame with factors and wrong col names
C-31 identical
C-31bm predict(am, xdata.frame, trace=0) data frame col names
C-31 identical
C-31bf predict(af, xdata.frame, trace=0) data frame col names
C-31b identical
C-32m predict(am, xdata.frame, trace=0) # data frame with names
C-32 identical
C-32 identical
C-32f predict(af, xdata.frame, trace=0) # data frame with names
C-32 identical
C-53m predict(am, xdata.frame, trace=0) data frame with not enough columns, expect error message
Error : get.earth.x from model.matrix.earth from predict.earth: x has 2 columns but expected 4
       column names: sex3.1. X.2
       expected column names: sex3 ldose ldose1 fac3
Got error as expected from try(predict(am, xdata.frame, trace = trace))
C-53f predict(af, xdata.frame, trace=0) data frame with not enough columns, expect error message
Error : get.earth.x from model.matrix.earth from predict.earth: x has 2 columns but expected 4
       column names: sex3.1. X.2
       expected column names: sex3 ldose ldose1 fac3
Got error as expected from try(predict(af, xdata.frame, trace = trace))
C-54m predict(am, xdata.frame, trace=0) # data frame with cols in different order
C-54 identical
C-54f predict(af, xdata.frame, trace=0) # data frame with cols in different order
C-54 identical
C-55m predict(am, xdata.frame, trace=0) data frame without col names
C-55f predict(af, xdata.frame, trace=0) data frame without col names
C-55 identical
C2-55bm predict(am, xdata.frame, trace=0) data frame col names
C2-55 identical
C2-55bf predict(af, xdata.frame, trace=0) data frame col names
C2-55b identical
C-56m predict(am, xdata.frame, trace=0) # data frame with col names
C-56 identical
C-56f predict(af, xdata.frame, trace=0) # data frame with col names
C-56 identical
C-57m predict(am, xdata.frame, trace=0) data frame with not enough columns, expect error message
Error : get.earth.x from model.matrix.earth from predict.earth: x has 2 columns but expected 4
       column names: sex3.c.1..7.. c..2...1.
       expected column names: sex3 ldose ldose1 fac3
Got error as expected from try(predict(am, xdata.frame, trace = trace))
C-57f predict(af, xdata.frame, trace=0) data frame with not enough columns, expect error message
Error : get.earth.x from model.matrix.earth from predict.earth: x has 2 columns but expected 4
       column names: sex3.c.1..7.. c..2...1.
       expected column names: sex3 ldose ldose1 fac3
Got error as expected from try(predict(af, xdata.frame, trace = trace))
C-57 identical
C-58m predict(am, xdata.frame, trace=0) # data frame with cols in different order
C-58 identical
C-58f predict(af, xdata.frame, trace=0) # data frame with cols in different order
C-58 identical
C-50m data frame without column names, trace=0
C-34 identical
C-60f data frame without column names, trace=0
C-60 identical
C-61f data frame without extra columns, trace=0
C-61 identical
> 
> cat("---test glm.predict---\n")
---test glm.predict---
> 
> ldose  <- rep(0:5, 2) - 2
> sex <- factor(rep(c("male", "female"), times=c(6,6)))
> numdead <- c(1,4,9,13,18,20,0,2,6,10,12,16)
> SF <- cbind(numdead, numalive=20 - numdead)
> 
> cat("c1a: single response glm model with a binomial pair of y columns, fitted values, keepxy=0\n")
c1a: single response glm model with a binomial pair of y columns, fitted values, keepxy=0
> c1a  <- earth(SF ~ sex + ldose, glm=list(family="binomial"), linpreds=TRUE, trace=1, pmethod=PMETHOD, nk=NK, degree=1, keepxy=0)
x[12,2] with colnames sexmale ldose
y[12,2] with colnames numdead numalive
earth and glm: unweighted
Response columns numdead and numalive are a binomial pair (240 obs in total)
yfrac[12,1] with colname numdead, and values 0.05, 0.2, 0.45, 0.65, 0.9, 1...
Forward pass term 1, 2, 4
Reached nk 6
After forward pass GRSq 0.952 RSq 0.981
Prune none penalty 2 nprune null: selected 3 of 3 terms, and 2 of 2 preds
After pruning pass GRSq 0.952 RSq 0.981
GLM numdead devratio 0.95 dof 9/11 iters 4
> c1ag <- glm(SF ~ sex + ldose, family="binomial") # use this as a reference
> 
> c1a.predict <- predict(c1a, trace=1)
predict.earth: returning glm fitted.values
> c1ag.predict <- predict(c1ag, trace=1)
> check.almost.equal(c1a.predict, c1ag.predict, max=1e-10, msg="c1a fitted values, type=default link, keepxy=0", verbose=TRUE)
c1a fitted values, type=default link, keepxy=0 OK
> c1a.predict <- predict(c1a, type="link", trace=1)
predict.earth: returning glm fitted.values
> c1ag.predict <- predict(c1ag, type="li", trace=1)
> check.almost.equal(c1a.predict, c1ag.predict, max=1e-10, msg="c1a fitted values, type=link, keepxy=0", verbose=TRUE)
c1a fitted values, type=link, keepxy=0 OK
> c1a.predict <- predict(c1a, type="response", trace=1)
predict.earth: returning glm fitted.values
> c1ag.predict <- predict(c1ag, type="resp", trace=1)
> check.almost.equal(c1a.predict, c1ag.predict, max=1e-10, msg="c1a fitted values, type=response, keepxy=0", verbose=TRUE)
c1a fitted values, type=response, keepxy=0 OK
> c1a.predict <- predict(c1a, type="e", trace=1)
predict.earth: returning earth (not glm) fitted.values 
> dead.frac <- numdead / (numdead + (20 - numdead))
> c1ae <- earth(dead.frac ~ sex + ldose, trace=1, linpreds=TRUE, pmethod=PMETHOD, nk=NK, degree=1, keepxy=0)
x[12,2] with colnames sexmale ldose
y[12,1] with colname dead.frac, and values 0.05, 0.2, 0.45, 0.65, 0.9, 1...
Forward pass term 1, 2, 4
Reached nk 6
After forward pass GRSq 0.952 RSq 0.981
Prune none penalty 2 nprune null: selected 3 of 3 terms, and 2 of 2 preds
After pruning pass GRSq 0.952 RSq 0.981
> c1ae.predict <- predict(c1ae, trace=1)
predict.earth: returning earth fitted.values 
> check.almost.equal(c1a.predict, c1ae.predict, max=1e-10, msg="c1a fitted values, type=earth, keepxy=0", verbose=TRUE)
c1a fitted values, type=earth, keepxy=0 OK
> 
> cat("c1b: single response glm model with a binomial pair of y columns\n")
c1b: single response glm model with a binomial pair of y columns
> c1b <-  earth(SF ~ sex + ldose, glm=list(family="binomial"), linpreds=TRUE, trace=1, pmethod=PMETHOD, nk=NK, degree=1, keepxy=1)
x[12,2] with colnames sexmale ldose
y[12,2] with colnames numdead numalive
earth and glm: unweighted
Response columns numdead and numalive are a binomial pair (240 obs in total)
yfrac[12,1] with colname numdead, and values 0.05, 0.2, 0.45, 0.65, 0.9, 1...
Forward pass term 1, 2, 4
Reached nk 6
After forward pass GRSq 0.952 RSq 0.981
Prune none penalty 2 nprune null: selected 3 of 3 terms, and 2 of 2 preds
After pruning pass GRSq 0.952 RSq 0.981
GLM numdead devratio 0.95 dof 9/11 iters 4
Warning: No 'data' argument to earth so 'keepxy' is limited

> c1be <-  earth(numdead ~ sex + ldose, linpreds=TRUE, trace=1, pmethod=PMETHOD, nk=NK, degree=1, keepxy=1)
x[12,2] with colnames sexmale ldose
y[12,1] with colname numdead, and values 1, 4, 9, 13, 18, 20, 0, 2, 6,...
Forward pass term 1, 2, 4
Reached nk 6
After forward pass GRSq 0.952 RSq 0.981
Prune none penalty 2 nprune null: selected 3 of 3 terms, and 2 of 2 preds
After pruning pass GRSq 0.952 RSq 0.981
Warning: No 'data' argument to earth so 'keepxy' is limited

> c1bg <- glm(SF ~ sex + ldose, family="binomial") # use this as a reference
> 
> newdata <- data.frame(sex=sex[1], ldose=2)
> c1b.predict <- predict(c1b, newdata, trace=1)
get.earth.x from model.matrix.earth from predict.earth: x[1,2]:
   sex ldose
1 male     2
  sex is a factor with levels: female male
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[1,2]:
   sex ldose
1 male     2
  sex is a factor with levels: female male
predict.earth with newdata: bx[1,3]:
  (Intercept) ldose sexmale
1           1     2       1
predict.earth: returning glm link predictions
> stopifnot(dim(c1b.predict) == c(1,1))
> check.almost.equal(c1b.predict, predict(c1bg, newdata), max=1e-10, msg="c1b", verbose=TRUE)
c1b OK
> 
> c1b.link.predict <- predict(c1b, newdata, type="link", trace=1) # should be same as above because default is link
get.earth.x from model.matrix.earth from predict.earth: x[1,2]:
   sex ldose
1 male     2
  sex is a factor with levels: female male
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[1,2]:
   sex ldose
1 male     2
  sex is a factor with levels: female male
predict.earth with newdata: bx[1,3]:
  (Intercept) ldose sexmale
1           1     2       1
predict.earth: returning glm link predictions
> check.almost.equal(c1b.link.predict, c1b.predict, max=1e-10, msg="c1b link", verbose=TRUE)
c1b link OK
> 
> c1b.predict <- predict(c1b, newdata, type="r")
> stopifnot(dim(c1b.predict) == c(1,1))
> check.almost.equal(c1b.predict, predict(c1bg, newdata, type="response"), max=1e-10, msg="c1b type=response", verbose=TRUE)
c1b type=response OK
> 
> c1b.predict <- predict(c1b, newdata, type="earth")
> stopifnot(dim(c1b.predict) == c(1,1))
> print(c1b.predict)
      numdead
[1,] 0.814881
> 
> newdata <- data.frame(sex=sex[c(1,3,7,9)], ldose=ldose[c(1,3,7,9)])
> c1b.predict <- predict(c1b, newdata, trace=1)
get.earth.x from model.matrix.earth from predict.earth: x[4,2]:
     sex ldose
1   male    -2
2   male     0
3 female    -2
4 female     0
  sex is a factor with levels: female male
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[4,2]:
     sex ldose
1   male    -2
2   male     0
3 female    -2
4 female     0
  sex is a factor with levels: female male
predict.earth with newdata: bx[4,3]:
  (Intercept) ldose sexmale
1           1    -2       1
2           1     0       1
3           1    -2       0
4           1     0       0
predict.earth: returning glm link predictions
> stopifnot(dim(c1b.predict) == c(4,1))
> check.almost.equal(c1b.predict, predict(c1bg, newdata), max=1e-10, msg="c1b multiple rows", verbose=TRUE)
c1b multiple rows OK
> 
> c1b.predict <- predict(c1b, newdata, type="response", trace=1)
get.earth.x from model.matrix.earth from predict.earth: x[4,2]:
     sex ldose
1   male    -2
2   male     0
3 female    -2
4 female     0
  sex is a factor with levels: female male
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[4,2]:
     sex ldose
1   male    -2
2   male     0
3 female    -2
4 female     0
  sex is a factor with levels: female male
predict.earth with newdata: bx[4,3]:
  (Intercept) ldose sexmale
1           1    -2       1
2           1     0       1
3           1    -2       0
4           1     0       0
predict.earth: returning glm response predictions
> stopifnot(dim(c1b.predict) == c(4,1))
> check.almost.equal(c1b.predict, predict(c1bg, newdata, type="response"), max=1e-10, msg="c1b multiple rows type=response", verbose=TRUE)
c1b multiple rows type=response OK
> 
> c1b.predict <- predict(c1b, newdata, type="terms", trace=0)
Warning: predict.earth: returning the earth (not glm) terms
> print(c1b.predict)
       sexmale      ldose
[1,] 0.1583333 -0.3642857
[2,] 0.1583333  0.0000000
[3,] 0.0000000 -0.3642857
[4,] 0.0000000  0.0000000
> c1be.predict <- predict(c1be, newdata, type="terms")
> print(c1be.predict)
      sexmale     ldose
[1,] 3.166667 -7.285714
[2,] 3.166667  0.000000
[3,] 0.000000 -7.285714
[4,] 0.000000  0.000000
> c1bg.predict <- predict(c1bg, newdata, type="terms")
> print(c1bg.predict)
         sex     ldose
1  0.5503717 -2.660535
2  0.5503717 -0.532107
3 -0.5503717 -2.660535
4 -0.5503717 -0.532107
attr(,"constant")
[1] -0.2622487
> 
> # commented out because multiple binomial pairs are no longer supported
> # cat("c2: double response glm model with two y binomial pairs\n")
> # SF2 <- cbind(numdead, numalive=20 - numdead, numdead2=numdead, numalive2=20 - numdead)
> # c2 <-  earth(SF2 ~ sex + ldose, glm=list(family="binomial"), linpreds=TRUE, trace=1, pmethod=PMETHOD, nk=NK, degree=1, keepxy=1)
> # c2e <-  earth(data.frame(sex, ldose), data.frame(numdead,numdead), linpreds=TRUE, trace=1, pmethod=PMETHOD, nk=NK, degree=1, keepxy=1)
> # c2g <- glm(SF ~ sex + ldose, family="binomial") # use this as a reference
> 
> # newdata <- data.frame(sex=sex[1], ldose=2)
> # c2.predict <- predict(c2, newdata, trace=1)
> # stopifnot(dim(c2.predict) == c(1,2))
> # check.almost.equal(c2.predict[,1], predict(c2g, newdata), max=1e-10, msg="c2", verbose=TRUE)
> #
> # c2.link.predict <- predict(c2, newdata, type="link", trace=1) # should be same as above because default is link
> # check.almost.equal(c2.link.predict, c2.predict, max=1e-10, msg="c2 link", verbose=TRUE)
> #
> # c2.predict <- predict(c2, newdata, type="response")
> # stopifnot(dim(c2.predict) == c(1,2))
> # check.almost.equal(c2.predict[,1], predict(c2g, newdata, type="response"), max=1e-10, msg="c2 multiple rows type=response", verbose=TRUE)
> #
> # newdata <- data.frame(sex=sex[c(1,3,7,9)], ldose=ldose[c(1,3,7,9)])
> # c2.predict <- predict(c2, newdata)
> # stopifnot(dim(c2.predict) == c(4,2))
> # check.almost.equal(c2.predict[,1], predict(c2g, newdata), max=1e-10, msg="c2 column1", verbose=TRUE)
> # check.almost.equal(c2.predict[,2], predict(c2g, newdata), max=1e-10, msg="c2 column2", verbose=TRUE)
> #
> # c2.predict <- predict(c2, newdata, type="response")
> # stopifnot(dim(c2.predict) == c(4,2))
> # check.almost.equal(c2.predict[,1], predict(c2g, newdata, type="response"), max=1e-10, msg="c2 column1 multiple rows type=response", verbose=TRUE)
> # check.almost.equal(c2.predict[,2], predict(c2g, newdata, type="response"), max=1e-10, msg="c2 column2 multiple rows type=response", verbose=TRUE)
> #
> # c2.predict <- predict(c2, newdata, type="earth", trace=1)
> # stopifnot(dim(c2.predict) == c(4,2))
> # check.almost.equal(c2.predict[,1], predict(c2e, newdata, trace=1), max=1e-10, msg="c2 column1 multiple rows type=earth", verbose=TRUE)
> # check.almost.equal(c2.predict[,2], predict(c2e, newdata, trace=1), max=1e-10, msg="c2 column2 multiple rows type=earth", verbose=TRUE)
> 
> cat("c3a: single response glm model with a boolean response, fitted values, keepxy=0\n")
c3a: single response glm model with a boolean response, fitted values, keepxy=0
> 
> mybool <- rep(c(FALSE, TRUE), times=c(6,6))
> data1 <- data.frame(mybool, sex, ldose)
> c3a <-  earth(mybool ~ sex + ldose, data=data1, glm=list(family="binomial"), linpreds=TRUE, trace=1, pmethod=PMETHOD, nk=NK, degree=1, keepxy=0)
x[12,2] with colnames sexmale ldose
y[12,1] with colname mybool, and values 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,...
Forward pass term 1, 2
Reached maximum RSq 0.9990 at 3 terms, 2 terms used (RSq 1.0000)
After forward pass GRSq 1.000 RSq 1.000
Prune none penalty 2 nprune null: selected 2 of 2 terms, and 1 of 2 preds
After pruning pass GRSq 1 RSq 1
GLM mybool devratio 1.00 dof 10/11 iters 23
> c3ag <- glm(mybool ~ sex + ldose, family="binomial") # use this as a reference
> c3ae <- earth(mybool ~ sex + ldose, data=data1, linpreds=TRUE, pmethod=PMETHOD, nk=NK, degree=1, keepxy=1)
> 
> c3a.predict <- predict(c3a, trace=1)
predict.earth: returning glm fitted.values
> c3ag.predict <- predict(c3ag, trace=1)
> # TODO why does max have to be big here?
> check.almost.equal(c3a.predict, c3ag.predict, max=1e-7, msg="c3a fitted values, type=default link, keepxy=0", verbose=TRUE)
c3a fitted values, type=default link, keepxy=0 OK
> c3a.predict <- predict(c3a, type="link", trace=1)
predict.earth: returning glm fitted.values
> c3ag.predict <- predict(c3ag, type="link", trace=1)
> check.almost.equal(c3a.predict, c3ag.predict, max=1e-7, msg="c3a fitted values, type=link, keepxy=0", verbose=TRUE)
c3a fitted values, type=link, keepxy=0 OK
> c3a.predict <- predict(c3a, type="response", trace=1)
predict.earth: returning glm fitted.values
> c3ag.predict <- predict(c3ag, type="response", trace=1)
> check.almost.equal(c3a.predict, c3ag.predict, max=1e-10, msg="c3a fitted values, type=response, keepxy=0", verbose=TRUE)
c3a fitted values, type=response, keepxy=0 OK
> c3a.predict <- predict(c3a, type="earth", trace=1)
predict.earth: returning earth (not glm) fitted.values 
> c3ae.predict <- predict(c3ae, trace=1)
predict.earth: returning earth fitted.values 
> check.almost.equal(c3a.predict, c3ae.predict, max=1e-10, msg="c3a fitted values, type=earth, keepxy=0", verbose=TRUE)
c3a fitted values, type=earth, keepxy=0 OK
> 
> c3a.response.predict <- predict(c3a, type="response")
> c3a.class.predict <- predict(c3a,type="class")
> stopifnot(c3a.class.predict == (c3a.response.predict > .5))
> 
> cat("c3b: single response glm model with a boolean response, fitted values, keepxy=1\n")
c3b: single response glm model with a boolean response, fitted values, keepxy=1
> 
> c3b <-  earth(mybool ~ sex + ldose, glm=list(family="binomial"), linpreds=TRUE, trace=1, pmethod=PMETHOD, nk=NK, degree=1, keepxy=1)
x[12,2] with colnames sexmale ldose
y[12,1] with colname mybool, and values 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,...
Forward pass term 1, 2
Reached maximum RSq 0.9990 at 3 terms, 2 terms used (RSq 1.0000)
After forward pass GRSq 1.000 RSq 1.000
Prune none penalty 2 nprune null: selected 2 of 2 terms, and 1 of 2 preds
After pruning pass GRSq 1 RSq 1
GLM mybool devratio 1.00 dof 10/11 iters 23
Warning: No 'data' argument to earth so 'keepxy' is limited

> c3bg <- glm(mybool ~ sex + ldose, family="binomial") # use this as a reference
> c3be <- earth(mybool ~ sex + ldose, linpreds=TRUE, pmethod=PMETHOD, nk=NK, degree=1, keepxy=0)
> 
> c3b.predict <- predict(c3b, trace=1) # fitted values
predict.earth: returning glm fitted.values
> c3bg.predict <- predict(c3bg, trace=1)
> check.almost.equal(c3b.predict, c3bg.predict, max=1e-7, msg="c3b fitted values, type=default link, keepxy=0", verbose=TRUE)
c3b fitted values, type=default link, keepxy=0 OK
> c3b.predict <- predict(c3b, type="link", trace=1)
predict.earth: returning glm fitted.values
> c3bg.predict <- predict(c3bg, type="link", trace=1)
> check.almost.equal(c3b.predict, c3bg.predict, max=1e-7, msg="c3b fitted values, type=link, keepxy=0", verbose=TRUE)
c3b fitted values, type=link, keepxy=0 OK
> c3b.predict <- predict(c3b, type="response", trace=1)
predict.earth: returning glm fitted.values
> c3bg.predict <- predict(c3bg, type="response", trace=1)
> check.almost.equal(c3b.predict, c3bg.predict, max=1e-10, msg="c3b fitted values, type=response, keepxy=0", verbose=TRUE)
c3b fitted values, type=response, keepxy=0 OK
> c3b.predict <- predict(c3b, type="earth", trace=1)
predict.earth: returning earth (not glm) fitted.values 
> c3be.predict <- predict(c3be, trace=1)
predict.earth: returning earth fitted.values 
> check.almost.equal(c3b.predict, c3be.predict, max=1e-10, msg="c3b fitted values, type=earth, keepxy=0", verbose=TRUE)
c3b fitted values, type=earth, keepxy=0 OK
> 
> c3b.response.predict <- predict(c3b, type="response")
> c3b.class.predict <- predict(c3b,type="cla")
> stopifnot(c3b.class.predict == (c3b.response.predict > .5))
> 
> cat("c3c: single response glm model with a boolean response\n")
c3c: single response glm model with a boolean response
> 
> c3c <-  earth(mybool ~ sex + ldose, data=data1, linpreds=TRUE, glm=list(family="binomial"), trace=1, pmethod=PMETHOD, nk=NK, degree=1, keepxy=0)
x[12,2] with colnames sexmale ldose
y[12,1] with colname mybool, and values 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,...
Forward pass term 1, 2
Reached maximum RSq 0.9990 at 3 terms, 2 terms used (RSq 1.0000)
After forward pass GRSq 1.000 RSq 1.000
Prune none penalty 2 nprune null: selected 2 of 2 terms, and 1 of 2 preds
After pruning pass GRSq 1 RSq 1
GLM mybool devratio 1.00 dof 10/11 iters 23
> c3cg <- glm(mybool ~ sex + ldose, data=data1, family="binomial") # use this as a reference
> c3ce <- earth(mybool ~ sex + ldose, data=data1, linpreds=TRUE, pmethod=PMETHOD, nk=NK, degree=1, keepxy=0)
> 
> newdata <- data.frame(sex=sex[1], ldose=2)
> c3c.predict <- predict(c3c, newdata)
> stopifnot(dim(c3c.predict) == c(1,1))
> check.almost.equal(c3c.predict, predict(c3cg, newdata), max=1e-10, msg="c3c", verbose=TRUE)
c3c OK
> 
> c3c.predict <- predict(c3c, newdata, type="response")
> stopifnot(dim(c3c.predict) == c(1,1))
> check.almost.equal(c3c.predict, predict(c3cg, newdata, type="response"), max=1e-10, msg="c3c type=response", verbose=TRUE)
c3c type=response OK
> 
> newdata <- data.frame(sex=sex[c(1,3,7,9)], ldose=ldose[c(1,3,7,9)])
> c3c.predict <- predict(c3c, newdata)
> stopifnot(dim(c3c.predict) == c(4,1))
> # TODO why does the max have to be bigger on this?
> check.almost.equal(c3c.predict, predict(c3cg, newdata), max=1e-7, msg="c3c multiple rows", verbose=TRUE)
c3c multiple rows OK
> 
> c3c.predict <- predict(c3c, newdata, type="response")
> stopifnot(dim(c3c.predict) == c(4,1))
> check.almost.equal(c3c.predict, predict(c3cg, newdata, type="response"), max=1e-10, msg="c3c multiple rows type=response", verbose=TRUE)
c3c multiple rows type=response OK
> 
> c3c.response.predict <- predict(c3c, type="response")
> c3c.class.predict <- predict(c3c,type="cl")
> stopifnot(c3c.class.predict == (c3c.response.predict > .5))
> 
> cat("c3d: single response glm model with a two level factor response\n")
c3d: single response glm model with a two level factor response
> cat("Expect \"did not converge warnings\", it doesn't matter for our purposes here\n")
Expect "did not converge warnings", it doesn't matter for our purposes here
> myfac <- gl(2, 3, length=12, labels = c("Control", "Treat"))
> c3d <-  earth(myfac ~ ldose + sex, data=data1, glm=list(family="binomial"), trace=0, pmethod=PMETHOD, nk=NK, degree=1)
Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
> c3d.class.predict <- predict(c3d,type="cl") # we also test here that the type can be abbreviated
> stopifnot(c3d.class.predict == myfac)
> 
> cat("c4: multiple response glm model with a factor response\n")
c4: multiple response glm model with a factor response
> fac3 <- factor(rep(c("A", "B", "C"), times=c(4,3,5)))
> cat("Expect \"did not converge warnings\", it doesn't matter for our purposes here\n")
Expect "did not converge warnings", it doesn't matter for our purposes here
> c4 <-  earth(fac3 ~ sex + ldose, linpreds=TRUE, glm=list(family="binomial"), trace=1, pmethod=PMETHOD, nk=NK, degree=1, keepxy=1)
x[12,2] with colnames sexmale ldose
y[12,3] with colnames A B C
Forward pass term 1, 2, 4
Reached nk 6
After forward pass GRSq -0.145 RSq 0.536
Prune none penalty 2 nprune null: selected 3 of 3 terms, and 2 of 2 preds
After pruning pass GRSq -0.145 RSq 0.536
Warning: glm.fit: algorithm did not converge
Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
GLM A devratio 1.00 dof 9/11 iters 25
GLM B devratio 0.06 dof 9/11 iters 4
Warning: glm.fit: algorithm did not converge
Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
GLM C devratio 1.00 dof 9/11 iters 25
Warning: the glm algorithm did not converge for responses "A" "C"
Warning: No 'data' argument to earth so 'keepxy' is limited

> c4g <- glm(fac3 ~ sex + ldose, family="binomial") # use this as a reference
Warning: glm.fit: algorithm did not converge
Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
> c4.notrace <-  earth(fac3 ~ sex + ldose, linpreds=TRUE, glm=list(family="binomial"), trace=0, pmethod=PMETHOD)
Warning: glm.fit: algorithm did not converge
Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
Warning: glm.fit: algorithm did not converge
Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
Warning: the glm algorithm did not converge for responses "A" "C"
> 
> newdata <- data.frame(sex=sex[1], ldose=2)
> c4.predict <- predict(c4, newdata)
> stopifnot(dim(c4.predict) == c(1,3))
> # minus needed on predict because of different handling of factors
> check.almost.equal(c4.predict[1,1], -predict(c4g, newdata), max=1e-8, msg="c4", verbose=TRUE)
c4 OK
> 
> newdata <- data.frame(sex=sex[c(1,3,7,9)], ldose=ldose[c(1,3,7,9)])
> c4.predict <- predict(c4, newdata)
> stopifnot(dim(c4.predict) == c(4,3))
> check.almost.equal(c4.predict[,1], -predict(c4g, newdata), max=1e-8, msg="c4 multiple rows", verbose=TRUE)
c4 multiple rows OK
> 
> c4.predict <- predict(c4, newdata, type="response")
> stopifnot(dim(c4.predict) == c(4,3))
> check.almost.equal(1-c4.predict[,1], predict(c4g, newdata, type="response"), max=1e-10, msg="c4 multiple rows type=response", verbose=TRUE)
c4 multiple rows type=response OK
> 
> cat("c5: multiple response glm model with two multi level factor responses\n")
c5: multiple response glm model with two multi level factor responses
> 
> fac3 <- factor(rep(c("A", "B", "C"), times=c(4,3,5)))
> fac4 <- factor(rep(c("P", "Q", "R", "S"), times=c(3,3,3,3)))
> big.dataframe <- data.frame(fac3, fac4)
> c5 <-  earth(data.frame(sex, ldose), big.dataframe, trace=1, pmethod=PMETHOD, nk=NK, degree=1, keepxy=1)
x[12,2] with colnames sexmale ldose
y[12,7] with colnames fac3A fac3B fac3C fac4P fac4Q fac4R fac4S
Forward pass term 1, 2, 4
Reached nk 6
After forward pass GRSq -0.074 RSq 0.565
Prune none penalty 2 nprune null: selected 3 of 3 terms, and 2 of 2 preds
After pruning pass GRSq -0.0737 RSq 0.565
> stopifnot(colnames(c5$coef) == c("fac3A", "fac3B", "fac3C",
+                                  "fac4P", "fac4Q", "fac4R", "fac4S"))
> stopifnot(is.null(c5$glm.bpairs))
> 
> cat("c6: multiple response earth model with mixed responses\n")
c6: multiple response earth model with mixed responses
> 
> big.dataframe2 <- data.frame(SF, fac3, fac4, SF+1, sex, fac4, SF+3)
> c6 <-  earth(data.frame(sex, ldose), big.dataframe2, trace=1, pmethod=PMETHOD, nk=NK, degree=1, keepxy=1)
x[12,2] with colnames sexmale ldose
y[12,18] with colnames numdead numalive fac3A fac3B fac3C fac4P fac4Q fac4R fac4...
Forward pass term 1, 2, 4
Reached nk 6
After forward pass GRSq 0.944 RSq 0.977
Prune none penalty 2 nprune null: selected 3 of 3 terms, and 2 of 2 preds
After pruning pass GRSq 0.944 RSq 0.977
> stopifnot(colnames(c6$coef) == c("numdead", "numalive", "fac3A", "fac3B", "fac3C",
+                                   "fac4P", "fac4Q", "fac4R", "fac4S", "numdead.1", "numalive.1",
+                                   "sex", "fac4.1P", "fac4.1Q", "fac4.1R", "fac4.1S",
+                                   "numdead.2", "numalive.2"))
> stopifnot(is.null(c6$glm.bpairs))
> 
> # residuals
> 
> a <- earth(pclass ~ ., data=etitanic)
> printh(residuals(a), max.print=3)
=== residuals(a)
        1st        2nd        3rd
1 0.6459266 -0.2575797 -0.3883469
2 0.7904775 -0.3372244 -0.4532531
3 1.0316575 -0.3335720 -0.6980855
> a <- earth(pclass ~ ., data=etitanic, glm=list(family="b"))
> printh(residuals(a), expect.warning=TRUE, max.print=3)
=== residuals(a) expect warning -->Warning: residuals.earth: returning earth (not glm) residuals
        1st        2nd        3rd
1 0.6459266 -0.2575797 -0.3883469
2 0.7904775 -0.3372244 -0.4532531
3 1.0316575 -0.3335720 -0.6980855
> printh(residuals(a, warn=FALSE), max.print=3)
=== residuals(a, warn = FALSE)
        1st        2nd        3rd
1 0.6459266 -0.2575797 -0.3883469
2 0.7904775 -0.3372244 -0.4532531
3 1.0316575 -0.3335720 -0.6980855
> printh(resid(a, type="earth"), max.print=3)
=== resid(a, type = "earth")
        1st        2nd        3rd
1 0.6459266 -0.2575797 -0.3883469
2 0.7904775 -0.3372244 -0.4532531
3 1.0316575 -0.3335720 -0.6980855
> printh(resid(a, type="deviance"), max.print=3)
=== resid(a, type = "deviance")
       1st        2nd        3rd
1 1.463565 -0.7712447 -0.9440797
2 2.002755 -0.9266706 -1.0226283
3 2.611499 -0.9184549 -1.5622542
> printh(resid(a, type="glm.pearson"), max.print=3)
=== resid(a, type = "glm.pearson")
       1st        2nd        3rd
1 1.385038 -0.5885288 -0.7493292
2 2.535727 -0.7323065 -0.8287859
3 5.409631 -0.7243429 -1.5454025
> printh(resid(a, type="glm.working"), max.print=3)
=== resid(a, type = "glm.working")
        1st       2nd       3rd
1  2.918329 -1.346366 -1.561494
2  7.429912 -1.536273 -1.686886
3 30.264104 -1.524673 -3.388269
> printh(resid(a, type="glm.response"), max.print=3)
=== resid(a, type = "glm.response")
        1st        2nd        3rd
1 0.6573382 -0.2572600 -0.3595878
2 0.8654089 -0.3490739 -0.4071918
3 0.9669576 -0.3441215 -0.7048640
> printh(resid(a, type="glm.partial"), max.print=3)
=== resid(a, type = "glm.partial")
  `h(age-26)` `h(26-age)`  survived `h(sibsp-1)` `h(1-sibsp)` `h(parch-2)`
1    2.551986    3.229034  3.868894     2.971321     2.716353     2.967871
2    6.823847    5.636241  8.380477     7.482904     7.813164     7.479454
3   29.658038   28.561316 29.608383    30.317096    30.647355    30.313645
  `h(2-parch)` `h(age-26)` `h(26-age)`  survived `h(sibsp-1)` `h(1-sibsp)`
1     2.814339   -1.286898   -1.291444 -1.323918    -1.226331    -1.459130
2     7.875285   -1.437891   -1.853336 -1.513824    -1.416238    -1.322303
3    30.709476   -1.426291   -1.825670 -1.540158    -1.404638    -1.310703
  `h(parch-2)` `h(2-parch)` `h(age-26)` `h(26-age)`  survived `h(sibsp-1)`
1    -1.308344    -1.430315   -1.238589  -1.8139051 -2.342634    -1.688705
2    -1.498251    -1.176736   -1.152683  -0.2297406 -2.468026    -1.814097
3    -1.486651    -1.165135   -2.854066  -2.0049559 -2.849421    -3.515480
  `h(1-sibsp)` `h(parch-2)` `h(2-parch)`
1    -1.266139    -1.631657    -1.398041
2    -2.247324    -1.757049    -2.386927
3    -3.948707    -3.458432    -4.088310
> expect.err(try(printh(resid(a, type="nonesuch"), max.print=3)), "Choose one of")
=== resid(a, type = "nonesuch")Error : type="nonesuch" is not allowed
Choose one of: "earth" "deviance" "response" "standardize" "delever" "pearson" "working" "partial" "glm.response" "glm.pearson" "glm.working" "glm.partial"
Got error as expected from try(printh(resid(a, type = "nonesuch"), max.print = 3))
> expect.err(try(printh(resid(a, type="g"), max.print=3)), "ambiguous") # type="g" is ambiguous
=== resid(a, type = "g")Error : type="g" is ambiguous
Choose one of: "earth" "deviance" "response" "standardize" "delever" "pearson" "working" "partial" "glm.response" "glm.pearson" "glm.working" "glm.partial"
Got error as expected from try(printh(resid(a, type = "g"), max.print = 3))
> expect.err(try(printh(resid(a, type="standardize"), max.print=3)), "model was not built with varmod.method") # model was not built with varmod.method
=== resid(a, type = "standardize")Error : "standardize" is not allowed because
the model was not built with varmod.method
Got error as expected from try(printh(resid(a, type = "standardize"), max.print = 3))
> 
> # tests based on Gavin Simpson's bug report
> # fit a MARS model allowing one-way interactions
> mod.Gamma <- earth(O3 ~ . - doy, data = ozone1, degree = 2, glm = list(family = Gamma))
> for(type in c("earth", "deviance", "glm.pearson", "glm.working", "glm.response", "glm.partial"))
+ {
+     cat("residuals.earth Gamma type=", type, ":\n", sep="")
+     print(head(resid(mod.Gamma, type = type), n=2))
+     print(tail(resid(mod.Gamma, type = type), n=2))
+ }
residuals.earth Gamma type=earth:
          O3
1 -0.7243326
2 -2.2761517
            O3
329 -2.4265537
330 -0.7557191
residuals.earth Gamma type=deviance:
          O3
1 -0.3273382
2 -0.1389893
           O3
329 -0.352996
330 -1.141034
residuals.earth Gamma type=glm.pearson:
          O3
1 -0.2926391
2 -0.1326260
            O3
329 -0.3127411
330 -0.7548319
residuals.earth Gamma type=glm.working:
          O3
1 0.06900048
2 0.02300727
            O3
329 0.04298682
330 0.18506071
residuals.earth Gamma type=glm.response:
          O3
1 -1.2411163
2 -0.7645259
           O3
329 -2.275278
330 -3.078834
residuals.earth Gamma type=glm.partial:
  `h(58-temp)` `h(ibh-1105)` `h(53-humidity)*h(temp-58)` `h(temp-58)*h(dpg-54)`
1   0.13967791   0.068767224                  0.06840770             0.06817591
2   0.06801493   0.008540681                  0.02241449             0.02218270
  `h(temp-58)*h(54-dpg)` `h(2-dpg)` `h(dpg-2)*h(ibt-115)`
1             0.07442982 0.09497502            0.07427533
2             0.02843660 0.04755558            0.02828212
  `h(humidity-46)*h(ibh-1105)` `h(vis-17)` `h(17-vis)` `h(wind-5)*h(1105-ibh)`
1                   0.06311208  0.08356335  0.06849208              0.06844222
2                   0.01711887  0.02011078  0.02249886              0.02244901
  `h(ibh-1105)*h(vis-40)`
1              0.07052912
2              0.02101241
    `h(58-temp)` `h(ibh-1105)` `h(53-humidity)*h(temp-58)`
329   0.06232471    0.05181521                  0.04239404
330   0.26087209    0.20550522                  0.18446793
    `h(temp-58)*h(dpg-54)` `h(temp-58)*h(54-dpg)` `h(2-dpg)`
329             0.04216225             0.04841615 0.03045335
330             0.18423614             0.19049004 0.17252724
    `h(dpg-2)*h(ibt-115)` `h(humidity-46)*h(ibh-1105)` `h(vis-17)` `h(17-vis)`
329            0.04826167                   0.04751573  0.03310658  0.04247842
330            0.19033556                   0.21976336  0.18216422  0.18455231
    `h(wind-5)*h(1105-ibh)` `h(ibh-1105)*h(vis-40)`
329              0.04242856              0.04099196
330              0.18450245              0.18553509
> mod.binomial <- earth(survived ~ ., data = etitanic, degree = 2, glm = list(family = binomial))
> for(type in c("earth", "deviance", "glm.pearson", "glm.working", "glm.response", "glm.partial"))
+ {
+     cat("residuals.earth binomial type=", type, ":\n", sep="")
+     print(head(residuals(mod.binomial, type = type), n=2))
+     print(tail(residuals(mod.binomial, type = type), n=2))
+ }
residuals.earth binomial type=earth:
     survived
1  0.03829050
2 -0.07121224
       survived
1045 -0.1782103
1046 -0.1782103
residuals.earth binomial type=deviance:
   survived
1 0.3251518
2 0.2593733
       survived
1045 -0.6051248
1046 -0.6051248
residuals.earth binomial type=glm.pearson:
   survived
1 0.2329892
2 0.1849578
       survived
1045 -0.4482411
1046 -0.4482411
residuals.earth binomial type=glm.working:
  survived
1 1.054284
2 1.034209
     survived
1045 -1.20092
1046 -1.20092
residuals.earth binomial type=glm.response:
    survived
1 0.05148896
2 0.03307782
       survived
1045 -0.1673051
1046 -0.1673051
residuals.earth binomial type=glm.partial:
     sexmale pclass3rd `sexmale*h(16-age)` `pclass2nd*sexmale`
1  3.0582428  3.463517            0.922184            1.321358
2 -0.1474563  3.443443            4.549463            1.301283
  `pclass3rd*h(4-sibsp)` `pclass3rd*sexmale` `h(age-32)`
1            0.029899131           0.6463292    1.233359
2            0.009824537           0.6262546    1.213285
       sexmale pclass3rd `sexmale*h(16-age)` `pclass2nd*sexmale`
1045 -2.382586 -3.821743            -1.33302          -0.9338465
1046 -2.382586 -3.821743            -1.33302          -0.9338465
     `pclass3rd*h(4-sibsp)` `pclass3rd*sexmale` `h(age-32)`
1045              0.2493061          -0.3861795   -1.021845
1046              0.2493061          -0.3861795   -1.021845
> # intercept only model
> 
> cat("a.intercept.only: intercept only logistic model\n\n")
a.intercept.only: intercept only logistic model

> # This seed chosen so call to earth below has one predictor model in 1st
> # cv fold and intercept-only in 2nd cv fold, that way we test both.
> set.seed(3)
> df <- data.frame(aaa = round(runif(18)), bbb = runif(18), ccc = rnorm(18))
> a.intercept.only <- earth(aaa ~ bbb + ccc, data = df, glm=list(family=binomial), trace=1, nfold=2)
x[18,2] with colnames bbb ccc
y[18,1] with colname aaa, and values 0, 1, 0, 0, 1, 1, 0, 0, 1, 1,...
Forward pass term 1, 2, 4, 6
RSq changed by less than 0.001 at 5 terms (DeltaRSq 0)
After forward pass GRSq -3.791 RSq 0.188
Prune backward penalty 2 nprune null: selected 1 of 5 terms, and 0 of 2 preds
After pruning pass GRSq 0 RSq 0
earth.glm: intercept-only earth model
GLM aaa devratio 0.00 dof 17/17 iters 4
Full model GRSq 0.000 RSq 0.000, starting cross validation
CV fold 1  Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
CVRSq -1.076   n.oof  8 56%   n.infold.nz  6 75%   n.oof.nz  6 60%
CV fold 2  CVRSq -0.120   n.oof 10 44%   n.infold.nz  6 60%   n.oof.nz  6 75%
CV all     CVRSq -0.598                  n.infold.nz 12 67%

> show.earth.models(a.intercept.only)

Print a.intercept.only 

GLM (family binomial, link logit):
 nulldev df       dev df   devratio     AIC iters converged
 22.9145 17   22.9145 17          0   24.91     4         1

Earth selected 1 of 5 terms, and 0 of 2 predictors
Termination condition: RSq changed by less than 0.001 at 5 terms
Importance: bbb-unused, ccc-unused
Number of terms at each degree of interaction: 1 (intercept only model)
Earth GCV 0.2491349  RSS 4  GRSq 0  RSq 0  CVRSq -0.5982021

Summary a.intercept.only 

Call: earth(formula=aaa~bbb+ccc, data=df, trace=1, glm=list(family=binomial),
            nfold=2)

GLM coefficients
                  aaa
(Intercept) 0.6931472

GLM (family binomial, link logit):
 nulldev df       dev df   devratio     AIC iters converged
 22.9145 17   22.9145 17          0   24.91     4         1

Earth selected 1 of 5 terms, and 0 of 2 predictors
Termination condition: RSq changed by less than 0.001 at 5 terms
Importance: bbb-unused, ccc-unused
Number of terms at each degree of interaction: 1 (intercept only model)
Earth GCV 0.2491349  RSS 4  GRSq 0  RSq 0  CVRSq -0.5982021

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

Cross validation:   nterms 1.50 sd 0.71    nvars 0.50 sd 0.71

  CVRSq    sd ClassRate    sd MaxErr    sd   AUC    sd MeanDev   sd CalibInt
 -0.598 0.676     0.725 0.035     -1 0.283 0.573 0.103    11.4 14.4    0.786
    sd CalibSlope sd
 0.442         NA NA

Summary a.intercept.only digits=3, details=TRUE

Call: earth(formula=aaa~bbb+ccc, data=df, trace=1, glm=list(family=binomial),
            nfold=2)

Earth coefficients
              aaa
(Intercept) 0.667

GLM coefficients
              aaa
(Intercept) 0.693

GLM deviance residuals:
   Min      1Q  Median      3Q     Max  
-1.482  -1.482   0.901   0.901   0.901  

GLM coefficients (family binomial, link logit)
            Estimate Std. Error z value Pr(>|z|)
(Intercept)    0.693      0.500    1.39     0.17

GLM (family binomial, link logit):
 nulldev df       dev df   devratio     AIC iters converged
    22.9 17      22.9 17          0    24.9     4         1

Earth selected 1 of 5 terms, and 0 of 2 predictors
Termination condition: RSq changed by less than 0.001 at 5 terms
Importance: bbb-unused, ccc-unused
Number of terms at each degree of interaction: 1 (intercept only model)
Earth GCV 0.249  RSS 4  GRSq 0  RSq 0  CVRSq -0.598

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

Cross validation:   nterms 1.50 sd 0.71    nvars 0.50 sd 0.71

  CVRSq    sd ClassRate    sd MaxErr    sd   AUC    sd MeanDev   sd CalibInt
 -0.598 0.676     0.725 0.035     -1 0.283 0.573 0.103    11.4 14.4    0.786
    sd CalibSlope sd
 0.442         NA NA

evimp a.intercept.only 

    nsubsets   gcv    rss

evimp a.intercept.only trim=FALSE

           nsubsets   gcv    rss
bbb-unused        0   0.0    0.0
ccc-unused        0   0.0    0.0

glm params: epsilon 1e-08 maxit 25 trace FALSE family binomial link logit 

plotmo a.intercept.only 
 plotmo grid:    bbb        ccc
           0.3547735 0.06386657
-------------------------------------------------------------------------------

> cat("\nsummary(a.intercept.only, details=TRUE)\n\n", sep="")

summary(a.intercept.only, details=TRUE)

> print(summary(a.intercept.only, details=TRUE))
Call: earth(formula=aaa~bbb+ccc, data=df, trace=1, glm=list(family=binomial),
            nfold=2)

Earth coefficients
                  aaa
(Intercept) 0.6666667

GLM coefficients
                  aaa
(Intercept) 0.6931472

GLM deviance residuals:
       Min          1Q      Median          3Q         Max  
-1.4823038  -1.4823038   0.9005166   0.9005166   0.9005166  

GLM coefficients (family binomial, link logit)
             Estimate Std. Error z value Pr(>|z|)
(Intercept) 0.6931472  0.4999999 1.38629  0.16566

GLM (family binomial, link logit):
 nulldev df       dev df   devratio     AIC iters converged
 22.9145 17   22.9145 17          0   24.91     4         1

Earth selected 1 of 5 terms, and 0 of 2 predictors
Termination condition: RSq changed by less than 0.001 at 5 terms
Importance: bbb-unused, ccc-unused
Number of terms at each degree of interaction: 1 (intercept only model)
Earth GCV 0.2491349  RSS 4  GRSq 0  RSq 0  CVRSq -0.5982021

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

Cross validation:   nterms 1.50 sd 0.71    nvars 0.50 sd 0.71

  CVRSq    sd ClassRate    sd MaxErr    sd   AUC    sd MeanDev   sd CalibInt
 -0.598 0.676     0.725 0.035     -1 0.283 0.573 0.103    11.4 14.4    0.786
    sd CalibSlope sd
 0.442         NA NA
> printh(predict(a.intercept.only))
=== predict(a.intercept.only)
            aaa
 [1,] 0.6931472
 [2,] 0.6931472
 [3,] 0.6931472
 [4,] 0.6931472
 [5,] 0.6931472
 [6,] 0.6931472
 [7,] 0.6931472
 [8,] 0.6931472
 [9,] 0.6931472
[10,] 0.6931472
[11,] 0.6931472
[12,] 0.6931472
[13,] 0.6931472
[14,] 0.6931472
[15,] 0.6931472
[16,] 0.6931472
[17,] 0.6931472
[18,] 0.6931472
> printh(predict(a.intercept.only, type="link"))
=== predict(a.intercept.only, type = "link")
            aaa
 [1,] 0.6931472
 [2,] 0.6931472
 [3,] 0.6931472
 [4,] 0.6931472
 [5,] 0.6931472
 [6,] 0.6931472
 [7,] 0.6931472
 [8,] 0.6931472
 [9,] 0.6931472
[10,] 0.6931472
[11,] 0.6931472
[12,] 0.6931472
[13,] 0.6931472
[14,] 0.6931472
[15,] 0.6931472
[16,] 0.6931472
[17,] 0.6931472
[18,] 0.6931472
> printh(predict(a.intercept.only, type="response"))
=== predict(a.intercept.only, type = "response")
            aaa
 [1,] 0.6666667
 [2,] 0.6666667
 [3,] 0.6666667
 [4,] 0.6666667
 [5,] 0.6666667
 [6,] 0.6666667
 [7,] 0.6666667
 [8,] 0.6666667
 [9,] 0.6666667
[10,] 0.6666667
[11,] 0.6666667
[12,] 0.6666667
[13,] 0.6666667
[14,] 0.6666667
[15,] 0.6666667
[16,] 0.6666667
[17,] 0.6666667
[18,] 0.6666667
> printh(predict(a.intercept.only, type="earth"))
=== predict(a.intercept.only, type = "earth")
            aaa
 [1,] 0.6666667
 [2,] 0.6666667
 [3,] 0.6666667
 [4,] 0.6666667
 [5,] 0.6666667
 [6,] 0.6666667
 [7,] 0.6666667
 [8,] 0.6666667
 [9,] 0.6666667
[10,] 0.6666667
[11,] 0.6666667
[12,] 0.6666667
[13,] 0.6666667
[14,] 0.6666667
[15,] 0.6666667
[16,] 0.6666667
[17,] 0.6666667
[18,] 0.6666667
> g <- a.intercept.only$glm.list[[1]]
> printh(predict(g, type="link"))
=== predict(g, type = "link")
        1         2         3         4         5         6         7         8 
0.6931472 0.6931472 0.6931472 0.6931472 0.6931472 0.6931472 0.6931472 0.6931472 
        9        10        11        12        13        14        15        16 
0.6931472 0.6931472 0.6931472 0.6931472 0.6931472 0.6931472 0.6931472 0.6931472 
       17        18 
0.6931472 0.6931472 
> printh(predict(g, type="response"))
=== predict(g, type = "response")
        1         2         3         4         5         6         7         8 
0.6666667 0.6666667 0.6666667 0.6666667 0.6666667 0.6666667 0.6666667 0.6666667 
        9        10        11        12        13        14        15        16 
0.6666667 0.6666667 0.6666667 0.6666667 0.6666667 0.6666667 0.6666667 0.6666667 
       17        18 
0.6666667 0.6666667 
> 
> new.df <- df[3:5, ]
> printh(predict(a.intercept.only, type="response"))
=== predict(a.intercept.only, type = "response")
            aaa
 [1,] 0.6666667
 [2,] 0.6666667
 [3,] 0.6666667
 [4,] 0.6666667
 [5,] 0.6666667
 [6,] 0.6666667
 [7,] 0.6666667
 [8,] 0.6666667
 [9,] 0.6666667
[10,] 0.6666667
[11,] 0.6666667
[12,] 0.6666667
[13,] 0.6666667
[14,] 0.6666667
[15,] 0.6666667
[16,] 0.6666667
[17,] 0.6666667
[18,] 0.6666667
> printh(predict(a.intercept.only, newdata=new.df, trace=1, type="link"))
=== predict(a.intercept.only, newdata = new.df, trace = 1, type = "link")get.earth.x from model.matrix.earth from predict.earth: x[3,3]:
  aaa        bbb        ccc
3   0 0.22820188 -0.5784837
4   0 0.01532989 -0.9423007
5   1 0.12898156 -0.2037282
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[3,2]:
         bbb        ccc
3 0.22820188 -0.5784837
4 0.01532989 -0.9423007
5 0.12898156 -0.2037282
predict.earth with newdata: bx[3,1]:
  (Intercept)
1           1
2           1
3           1
predict.earth: returning glm link predictions

           aaa
[1,] 0.6931472
[2,] 0.6931472
[3,] 0.6931472
> printh(predict(a.intercept.only, newdata=new.df, trace=1, type="response"))
=== predict(a.intercept.only, newdata = new.df, trace = 1, type = "response")get.earth.x from model.matrix.earth from predict.earth: x[3,3]:
  aaa        bbb        ccc
3   0 0.22820188 -0.5784837
4   0 0.01532989 -0.9423007
5   1 0.12898156 -0.2037282
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: mf[3,2]:
         bbb        ccc
3 0.22820188 -0.5784837
4 0.01532989 -0.9423007
5 0.12898156 -0.2037282
predict.earth with newdata: bx[3,1]:
  (Intercept)
1           1
2           1
3           1
predict.earth: returning glm response predictions

           aaa
[1,] 0.6666667
[2,] 0.6666667
[3,] 0.6666667
> printh(predict(a.intercept.only, newdata=new.df, type="earth"))
=== predict(a.intercept.only, newdata = new.df, type = "earth")
           aaa
[1,] 0.6666667
[2,] 0.6666667
[3,] 0.6666667
> printh(predict(a.intercept.only, newdata=new.df, type="class"))
=== predict(a.intercept.only, newdata = new.df, type = "class")
     aaa
[1,]   1
[2,]   1
[3,]   1
> # cat("Expect Warning: predict.earth: returning the earth (not glm) terms\n")
> printh(predict(a.intercept.only, newdata=new.df, type="terms"))
=== predict(a.intercept.only, newdata = new.df, type = "terms")Warning: predict.earth: returning the earth (not glm) terms

    
[1,]
[2,]
[3,]
> 
> set.seed(1235)
> a <- earth(survived ~ ., data=etitanic, glm=list(family=binomial), nfold=2)
Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
> plot.earth.models(list(a.intercept.only, a), main="plot.earth.models\nlist(a.intercept.only, a)")
> plot.earth.models(list(a, a.intercept.only), main="plot.earth.models\nlist(a, a.intercept.only)", legend.pos="topleft", jitter=.01)
> # nothing will plot for the next call
> plot.earth.models(list(a.intercept.only, a.intercept.only), main="plot.earth.models\nlist(a.intercept.only, a.intercept.only)")
> 
> # test position of legend and "intercep-only model" message when only one term in model
> a.intercept.pruned <- update(a.intercept.only, nprune=1, nfold=1)
update.earth: using 18 by 3 data argument from original call to earth
x[18,2] with colnames bbb ccc
y[18,1] with colname aaa, and values 0, 1, 0, 0, 1, 1, 0, 0, 1, 1,...
Forward pass term 1, 2, 4, 6
RSq changed by less than 0.001 at 5 terms (DeltaRSq 0)
After forward pass GRSq -3.791 RSq 0.188
nprune=1
Prune backward penalty 2 nprune 1: selected 1 of 5 terms, and 0 of 2 preds
After pruning pass GRSq 0 RSq 0
earth.glm: intercept-only earth model
GLM aaa devratio 0.00 dof 17/17 iters 4
> show.earth.models(a.intercept.pruned)

Print a.intercept.pruned 

GLM (family binomial, link logit):
 nulldev df       dev df   devratio     AIC iters converged
 22.9145 17   22.9145 17          0   24.91     4         1

Earth selected 1 of 5 terms, and 0 of 2 predictors
Termination condition: RSq changed by less than 0.001 at 5 terms
Importance: bbb-unused, ccc-unused
Number of terms at each degree of interaction: 1 (intercept only model)
Earth GCV 0.2491349    RSS 4    GRSq 0    RSq 0

Summary a.intercept.pruned 

Call: earth(formula=aaa~bbb+ccc, data=df, trace=1, glm=list(family=binomial),
            nprune=1, nfold=1)

GLM coefficients
                  aaa
(Intercept) 0.6931472

GLM (family binomial, link logit):
 nulldev df       dev df   devratio     AIC iters converged
 22.9145 17   22.9145 17          0   24.91     4         1

Earth selected 1 of 5 terms, and 0 of 2 predictors
Termination condition: RSq changed by less than 0.001 at 5 terms
Importance: bbb-unused, ccc-unused
Number of terms at each degree of interaction: 1 (intercept only model)
Earth GCV 0.2491349    RSS 4    GRSq 0    RSq 0

Summary a.intercept.pruned decomp="none", digits=5, fixed.point=FALSE, details=TRUE

Call: earth(formula=aaa~bbb+ccc, data=df, trace=1, glm=list(family=binomial),
            nprune=1, nfold=1)

Earth coefficients
                aaa
(Intercept) 0.66667

GLM coefficients
                aaa
(Intercept) 0.69315

GLM deviance residuals:
     Min        1Q    Median        3Q       Max  
-1.48230  -1.48230   0.90052   0.90052   0.90052  

GLM coefficients (family binomial, link logit)
            Estimate Std. Error z value Pr(>|z|)
(Intercept)  0.69315    0.50000  1.3863   0.1657

GLM (family binomial, link logit):
 nulldev df       dev df   devratio     AIC iters converged
   22.91 17     22.91 17          0    24.9     4         1

Earth selected 1 of 5 terms, and 0 of 2 predictors
Termination condition: RSq changed by less than 0.001 at 5 terms
Importance: bbb-unused, ccc-unused
Number of terms at each degree of interaction: 1 (intercept only model)
Earth GCV 0.24913    RSS 4    GRSq 0    RSq 0

evimp a.intercept.pruned 

    nsubsets   gcv    rss

evimp a.intercept.pruned trim=FALSE

           nsubsets   gcv    rss
bbb-unused        0   0.0    0.0
ccc-unused        0   0.0    0.0

glm params: epsilon 1e-08 maxit 25 trace FALSE family binomial link logit 

plotmo a.intercept.pruned 
 plotmo grid:    bbb        ccc
           0.3547735 0.06386657
-------------------------------------------------------------------------------

> 
> # misc tests
> 
> cat("---misc 1---\n")
---misc 1---
> sex1 <- factor(rep(c("male", "female"), times=c(6,6)))
> sex2 <- factor(rep(c("male", "female"), times=c(6,6)))
> earth(numdead, cbind(sex1, sex2, sex1), trace=1) # one duplicate name
x[12,1] with colname numdead, and values 1, 4, 9, 13, 18, 20, 0, 2, 6,...
y[12,3] with colnames sex1 sex2 sex1.1
Forward pass term 1, 2, 4
RSq changed by less than 0.001 at 3 terms (DeltaRSq 0)
After forward pass GRSq -3.446 RSq 0.081
Prune backward penalty 2 nprune null: selected 1 of 3 terms, and 0 of 1 preds
After pruning pass GRSq 0 RSq 0
Selected 1 of 3 terms, and 0 of 1 predictors
Termination condition: RSq changed by less than 0.001 at 3 terms
Importance: numdead-unused
Number of terms at each degree of interaction: 1 (intercept only model)

             GCV RSS GRSq RSq
sex1   0.2975207   3    0   0
sex2   0.2975207   3    0   0
sex1.1 0.2975207   3    0   0
All    0.8925620   9    0   0
> sex1 <- factor(rep(c("male", "female"), times=c(6,6)))
> sex2 <- factor(rep(c("male", "female"), times=c(6,6)))
> earth(numdead, cbind(sex1, sex2, sex1, sex1), trace=1) # two duplicate names
x[12,1] with colname numdead, and values 1, 4, 9, 13, 18, 20, 0, 2, 6,...
y[12,4] with colnames sex1 sex2 sex1.1 sex1.2
Forward pass term 1, 2, 4
RSq changed by less than 0.001 at 3 terms (DeltaRSq 0)
After forward pass GRSq -3.446 RSq 0.081
Prune backward penalty 2 nprune null: selected 1 of 3 terms, and 0 of 1 preds
After pruning pass GRSq 0 RSq 0
Selected 1 of 3 terms, and 0 of 1 predictors
Termination condition: RSq changed by less than 0.001 at 3 terms
Importance: numdead-unused
Number of terms at each degree of interaction: 1 (intercept only model)

             GCV RSS GRSq RSq
sex1   0.2975207   3    0   0
sex2   0.2975207   3    0   0
sex1.1 0.2975207   3    0   0
sex1.2 0.2975207   3    0   0
All    1.1900826  12    0   0
> 
> # test column expansion when y is a data frame in earth.default
> 
> cat("---misc 2---\n")
---misc 2---
> ldose  <- rep(0:5, 2) - 2
> ldose1 <- c(0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 0.3, 1.4, 2.5, 3.6, 4.7, 5.8)
> sex <- factor(rep(c("male", "female"), times=c(6,6)))
> sex2 <- sex
> sex3 <- factor(rep(c("male", "female", "andro"), times=c(6,4,2)))
> fac3 <- factor(c("lev2", "lev2", "lev1", "lev1", "lev3", "lev3",
+                  "lev2", "lev2", "lev1", "lev1", "lev3", "lev3"))
> facdead <- factor(c("dead2", "dead2", "dead3", "dead1", "dead3", "dead3",
+                     "dead1", "dead2", "dead1", "dead1", "dead3", "dead3"))
> 
> isex <- as.double(sex3) # sex3 as an index
> df1 <- data.frame(sex2, d_=facdead, sex, sex, isex)
> af <-  earth(data.frame(sex3,ldose,fac3,isex), df1, trace=1, pmethod=PMETHOD, nk=NK, degree=2)
x[12,6] with colnames sex3female sex3male ldose fac3lev2 fac3lev3 isex
y[12,7] with colnames sex2 d_dead1 d_dead2 d_dead3 sex sex.1 isex
Forward pass term 1, 2, 4
Reached nk 6
After forward pass GRSq 0.297 RSq 0.791
Prune none penalty 3 nprune null: selected 3 of 3 terms, and 2 of 6 preds
After pruning pass GRSq 0.297 RSq 0.791
> 
> cat("---misc 3---\n")
---misc 3---
> 
> # strings in input matrices, get converted to factors and a warning issued
> # TODO would like to improve the error message (says 'x' even when 'y')
> # TODO Apr 2013 warning no longer issued (R changed), is that ok?
> 
> ldose  <- rep(0:5, 2) - 2
> ldose1 <- c(0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 0.3, 1.4, 2.5, 3.6, 4.7, 5.8)
> sex2 <- rep(c("male", "female"), times=c(6,6))
> # y cannot be a character variable
> expect.err(try(earth(sex2, sex2, trace=1)), "y is a character variable: ")
Error : y is a character variable: "male", "male", "male", ...
Got error as expected from try(earth(sex2, sex2, trace = 1))
> expect.err(try(earth(sex2~ldose1, trace=1)), "y is a character variable: ")
Error : y is a character variable: "male", "male", "male", ...
Got error as expected from try(earth(sex2 ~ ldose1, trace = 1))
> # but note that this is ok
> earth(sex2, data.frame(sex2=sex2), trace=1)
x[12,1] with colname xmale, and values 1, 1, 1, 1, 1, 1, 0, 0, 0, 0,...
y[12,1] with colname sex2, and values 1, 1, 1, 1, 1, 1, 0, 0, 0, 0,...
Forward pass term 1, 2
Reached maximum RSq 0.9990 at 3 terms, 2 terms used (RSq 1.0000)
After forward pass GRSq 1.000 RSq 1.000
Prune backward penalty 2 nprune null: selected 2 of 2 terms, and 1 of 1 preds
After pruning pass GRSq 1 RSq 1
Selected 2 of 2 terms, and 1 of 1 predictors
Termination condition: Reached maximum RSq 0.9990 at 2 terms
Importance: xmale
Number of terms at each degree of interaction: 1 1 (additive model)
GCV 0    RSS 0    GRSq 1    RSq 1
> 
> # test update.earth with bpairs argument (for now always do forward pass if bpairs)
> 
> cat("---misc 4---\n")
---misc 4---
> volumei <- as.integer(trees$Volume)
> x1 <- trees$Height
> a <- earth(x1, cbind(volumei, 100-volumei), glm=list(family=binomial))
> update(a, trace=1, glm=list(family=binomial))
update.earth: using 31 by 1 x argument from original call to earth
update.earth: using 31 by 2 y argument from original call to earth
x[31,1] with colname x1, and values 70, 65, 63, 72, 81, 83, 66, 7...
y[31,2] with colnames volumei cbind(volumei,100-volumei)2
earth and glm: unweighted
Response columns volumei and cbind(volumei,100-volumei)2 are a binomial pair (3100 obs in total)
yfrac[31,1] with colname volumei, and values 0.1, 0.1, 0.1, 0.16, 0.18, 0...
Skipped forward pass
Prune backward penalty 2 nprune null: selected 2 of 5 terms, and 1 of 1 preds
After pruning pass GRSq 0.239 RSq 0.338
GLM volumei devratio 0.33 dof 29/30 iters 4
GLM (family binomial, link logit):
 nulldev df       dev df   devratio     AIC iters converged
 382.433 30   255.079 29      0.333   405.1     4         1

Earth selected 2 of 5 terms, and 1 of 1 predictors
Termination condition: RSq changed by less than 0.001 at 5 terms
Importance: x1
Number of terms at each degree of interaction: 1 1 (additive model)
Earth GCV 0.02132819    RSS 0.5393967    GRSq 0.2394863    RSq 0.337508
> a <- earth(x1, cbind(volumei, 100-volumei), glm=list(family=binomial))
> update(a, trace=1, glm=list(family=binomial))
update.earth: using 31 by 1 x argument from original call to earth
update.earth: using 31 by 2 y argument from original call to earth
x[31,1] with colname x1, and values 70, 65, 63, 72, 81, 83, 66, 7...
y[31,2] with colnames volumei cbind(volumei,100-volumei)2
earth and glm: unweighted
Response columns volumei and cbind(volumei,100-volumei)2 are a binomial pair (3100 obs in total)
yfrac[31,1] with colname volumei, and values 0.1, 0.1, 0.1, 0.16, 0.18, 0...
Skipped forward pass
Prune backward penalty 2 nprune null: selected 2 of 5 terms, and 1 of 1 preds
After pruning pass GRSq 0.239 RSq 0.338
GLM volumei devratio 0.33 dof 29/30 iters 4
GLM (family binomial, link logit):
 nulldev df       dev df   devratio     AIC iters converged
 382.433 30   255.079 29      0.333   405.1     4         1

Earth selected 2 of 5 terms, and 1 of 1 predictors
Termination condition: RSq changed by less than 0.001 at 5 terms
Importance: x1
Number of terms at each degree of interaction: 1 1 (additive model)
Earth GCV 0.02132819    RSS 0.5393967    GRSq 0.2394863    RSq 0.337508
> 
> source("test.epilog.R")
