File: test.degree.Rout.save

package info (click to toggle)
r-cran-plotmo 3.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,400 kB
  • sloc: sh: 13; makefile: 2
file content (166 lines) | stat: -rw-r--r-- 8,179 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
> # test.pre.R: test the degree1 and degree2 and related args
> 
> source("test.prolog.R")
> library(earth)
Loading required package: Formula
Loading required package: plotmo
Loading required package: plotrix
> library(plotmo)
> 
> # test character degree1 and degree2 (added in plotmo version 1.3-0)
> 
> data(ozone1)
> a80 <- earth(O3~., data=ozone1, degree=2)
> plotmo(a80, degree1="i", degree2="t",
+        caption='degree1="i", degree2="t"')
 plotmo grid:    vh wind humidity temp    ibh dpg   ibt vis   doy
               5760    5       64   62 2112.5  24 167.5 120 205.5
> plotmo(a80, degree1="^temp$", degree2="^dpg$",
+        caption='degree1="^temp$", degree2="^dpg$"')
 plotmo grid:    vh wind humidity temp    ibh dpg   ibt vis   doy
               5760    5       64   62 2112.5  24 167.5 120 205.5
> # Expect Warning: "nonesuch1" in degree1 does not regex-match any variables, ditto for degree2
> plotmo(a80, degree1=c("temp", "nonesuch1"), degree2="vis",
+        caption='degree1=c("temp", "nonesuch1"), degree2="vis")')
Warning: "nonesuch1" in degree1 does not regex-match any names
         Available names are "vh" "wind" "humidity" "temp" "ibh" "dpg" "ibt" "vis" "doy"
 plotmo grid:    vh wind humidity temp    ibh dpg   ibt vis   doy
               5760    5       64   62 2112.5  24 167.5 120 205.5
> # Expect above warnings and also Warning: nothing to plot
> plotmo(a80, degree1="nonesuch1", degree2="nonesuch2")
Warning: "nonesuch1" in degree1 does not regex-match any names
         Available names are "vh" "wind" "humidity" "temp" "ibh" "dpg" "ibt" "vis" "doy"
Warning: "nonesuch2" in degree2 does not regex-match any names
         Available names are "vh" "wind" "humidity" "temp" "ibh" "dpg" "ibt" "vis" "doy"
Warning: plotmo: nothing to plot
> 
> # tests for plotmo version 3.3.7 (degree1 and degree2 handling changed)
> 
> data(etitanic)
> a81 <- earth(survived~., data=etitanic, degree=2)
> options(warn=1) # print warnings as they occur
> plotmo(a81)
 plotmo grid:    pclass  sex age sibsp parch
                    3rd male  28     0     0
> 
> # degree1 tests
> par(mfrow=c(3,3), mar=c(1,2.5,2,1), oma=c(0,0,4,0))
> plotmo(a81, do.par=FALSE, degree1="pclass", degree2=0, main='degree1="pclass"',
+        caption="test degree1 with strings")
 plotmo grid:    pclass  sex age sibsp parch
                    3rd male  28     0     0
> options(warn=2) # treat warnings as errors
> expect.err(try(plotmo(a81, do.par=FALSE, degree1="survived", degree2=0)), '"survived" in degree1 does not regex-match any names')
Error : (converted from warning) "survived" in degree1 does not regex-match any names
         Available names are "pclass" "sex" "age" "sibsp" "parch"
Got expected error from try(plotmo(a81, do.par = FALSE, degree1 = "survived", degree2 = 0))
> options(warn=1) # print warnings as they occur
> plotmo(a81, do.par=FALSE, degree1="sibsp", degree2=0, main='degree1="sibsp"')
 plotmo grid:    pclass  sex age sibsp parch
                    3rd male  28     0     0
> # parch does not appear in the standard degree1 plotmo plots, but we can still specify it explictly
> plotmo(a81, do.par=FALSE, degree1="parch", degree2=0, trace=0, main='degree1="parch"')
 plotmo grid:    pclass  sex age sibsp parch
                    3rd male  28     0     0
> plotmo(a81, do.par=FALSE, degree1=c("sibsp", "pclass"), degree2=0, main='degree1=c("sibsp", "pclass")')
 plotmo grid:    pclass  sex age sibsp parch
                    3rd male  28     0     0
> par(org.par)
> 
> # degree2 tests
> par(mfrow=c(3,3), mar=c(1,2.5,2,1), oma=c(0,0,4,0))
> plotmo(a81, do.par=FALSE, degree1=0, degree2="pclass", main='degree2="pclass"',
+        caption="test degree2 with two strings")
> plotmo(a81, do.par=FALSE, degree1=0, degree2=c("age", "se"), persp.theta=-35,
+        main='degree2=c("age", "se")\npersp.theta=-35')
> plotmo(a81, do.par=FALSE, degree1=0, degree2="ag", main='degree2="ag"')
> plotmo(a81, do.par=FALSE, degree1=0, degree2=c("sex", "sibsp"), main='degree2=c("sex", "sibsp"')
> plotmo(a81, do.par=FALSE, degree1=0, degree2=c("sibsp", "sex"), main='degree2=c("sibsp", "sex")')
> options(warn=2) # treat warnings as errors
> expect.err(try(plotmo(a81, do.par=FALSE, degree1=0, degree2=c("pclass", "nonesuch"))), "\"nonesuch\" in degree2 does not regex-match any names")
Error : (converted from warning) "nonesuch" in degree2 does not regex-match any names
         Available names are "pclass" "sex" "age" "sibsp" "parch"
Got expected error from try(plotmo(a81, do.par = FALSE, degree1 = 0, degree2 = c("pclass",     "nonesuch")))
> expect.err(try(plotmo(a81, do.par=FALSE, degree1=0, degree2=c("nonesuch1", "nonesuch2"))), "\"nonesuch1\" in degree2 does not regex-match any names")
Error : (converted from warning) "nonesuch1" in degree2 does not regex-match any names
         Available names are "pclass" "sex" "age" "sibsp" "parch"
Got expected error from try(plotmo(a81, do.par = FALSE, degree1 = 0, degree2 = c("nonesuch1",     "nonesuch2")))
> expect.err(try(plotmo(a81, do.par=FALSE, degree1=0, degree2=c("nonesuch", "pclass"))), "\"nonesuch\" in degree2 does not regex-match any names")
Error : (converted from warning) "nonesuch" in degree2 does not regex-match any names
         Available names are "pclass" "sex" "age" "sibsp" "parch"
Got expected error from try(plotmo(a81, do.par = FALSE, degree1 = 0, degree2 = c("nonesuch",     "pclass")))
> options(warn=1) # print warnings as they occur
> par(org.par)
> 
> par(mfrow=c(2,2), mar=c(1,2.5,2,1), oma=c(0,0,4,0))
> 
> # check that order of strings in two string degree2 is observed
> cat('\n\ndegree2=c("age", "se"):\n')


degree2=c("age", "se"):
> plotmo(a81, do.par=FALSE, degree1=0,
+        degree2=c("age", "se"), main='degree2=c("age", "se")')
> cat('\n\ndegree2=c("se", "age"):\n')


degree2=c("se", "age"):
> plotmo(a81, do.par=FALSE, degree1=0,
+        degree2=c("se", "age"), main='degree2=c("se", "age")')
> 
> # check handling of bad strings in two string degree2
> cat('\n\ndegree2=c("nonesuch", "age"):\n')


degree2=c("nonesuch", "age"):
> try(plotmo(a81, do.par=FALSE, degree1=0,
+     degree2=c("nonesuch", "age"), main='degree2=c("nonesuch", "age")'))
Warning: "nonesuch" in degree2 does not regex-match any names
         Available names are "pclass" "sex" "age" "sibsp" "parch"
Warning: plotmo: nothing to plot
> cat('\n\ndegree2=c("age", "nonesuch"):\n')


degree2=c("age", "nonesuch"):
> try(plotmo(a81, do.par=FALSE, degree1=0,
+        degree2=c("age", "nonesuch"),
+        main='degree2=c("age", "nonesuch")'))
Warning: "nonesuch" in degree2 does not regex-match any names
         Available names are "pclass" "sex" "age" "sibsp" "parch"
Warning: plotmo: nothing to plot
> cat('\n\ndegree2=c("nevermore", "nonesuch"):\n')


degree2=c("nevermore", "nonesuch"):
> try(plotmo(a81, do.par=FALSE, degree1=0,
+        degree2=c("nevermore", "nonesuch"),
+        main='degree2=c("nevermore", "nonesuch")'))
Warning: "nevermore" in degree2 does not regex-match any names
         Available names are "pclass" "sex" "age" "sibsp" "parch"
Warning: plotmo: nothing to plot
> # follow should still plot the degree1 plot even though degree2 spec is wrong
> cat('\n\ndegree1=1, degree2=c("nevermore", "nonesuch"):\n')


degree1=1, degree2=c("nevermore", "nonesuch"):
> try(plotmo(a81, do.par=FALSE, degree1=1,
+        degree2=c("nevermore", "nonesuch"),
+        main='degree1=1\ndegree2=c("nevermore", "nonesuch")'))
Warning: "nevermore" in degree2 does not regex-match any names
         Available names are "pclass" "sex" "age" "sibsp" "parch"
 plotmo grid:    pclass  sex age sibsp parch
                    3rd male  28     0     0
> 
> # expect warning: both elements of degree2 are the same
> cat('\n\ndegree2=c("sex", "sex"):\n')


degree2=c("sex", "sex"):
> try(plotmo(a81, do.par=FALSE, degree1=0,
+        degree2=c("sex", "sex"),
+        main='degree1=1\ndegree2=c("sex", "sex")'))
Warning: both elements of degree2 are the same
> 
> par(org.par)
> 
> source("test.epilog.R")