我正在尝试使用gam功能。但我收到一个错误,表明二进制运算符的非数字参数。我尝试使用lapply(样本,as.numeric),但它没有工作我也尝试as.numeric(示例$ VOl),即使这不能解决我的问题。
library(mgcv)
par(mfrow = c(2,2))
model<-gam(lmpg~SP*lhp+WT*lhp+I(SP^2)+I(WT^2)+I(lhp)^2)+VOL
plot(model)
par(mfrow = c(1,1))
我的样本看起来像这样
VOL SP WT lmpg lhp
1 89 96 17.5 4.180522 3.891820
2 92 97 20.0 4.025352 4.007333
3 92 97 20.0 4.023564 4.007333
4 92 105 20.0 3.891820 4.248495
5 92 96 20.0 3.839452 3.970292
6 89 105 20.0 3.832980 4.248495
7 92 97 20.0 3.815512 4.007333
8 50 98 22.5 4.080922 4.127134
9 50 98 22.5 3.975936 4.127134
10 94 107 22.5 3.770459 4.382027
11 89 103 22.5 3.716008 4.290459
12 50 113 22.5 3.711130 4.521789
13 99 113 22.5 3.711130 4.521789
14 89 103 22.5 3.698830 4.290459
15 89 100 22.5 3.678829 4.189655
16 89 103 22.5 3.671225 4.290459
17 91 106 22.5 3.660994 4.356709
18 50 113 22.5 3.658420 4.521789
19 91 106 22.5 3.642836 4.356709
20 103 109 25.0 3.742420 4.499810
21 99 110 25.0 3.711130 4.521789
22 107 101 25.0 3.706228 4.304065
23 101 111 25.0 3.688879 4.553877
24 96 105 25.0 3.671225 4.394449
25 89 111 25.0 3.658420 4.553877
26 50 110 25.0 3.648057 4.521789
27 117 110 25.0 3.648057 4.521789
28 99 110 25.0 3.648057 4.521789
29 102 109 25.0 3.384390 4.499810
30 104 90 27.5 3.848018 3.951244
31 107 112 27.5 3.591818 4.634729
32 114 103 27.5 3.586293 4.430817
33 101 103 27.5 3.586293 4.430817
34 97 111 27.5 3.566712 4.624973
35 113 111 27.5 3.563883 4.624973
36 101 102 27.5 3.558201 4.394449
37 98 106 27.5 3.558201 4.499810
38 88 106 27.5 3.555348 4.499810
39 86 109 30.0 3.502550 4.624973
40 86 109 30.0 3.493473 4.624973
41 92 120 30.0 3.475067 4.867534
42 113 106 30.0 3.471966 4.553877
43 106 106 30.0 3.471966 4.553877
44 92 109 30.0 3.471966 4.624973
45 88 106 30.0 3.471966 4.553877
46 102 105 30.0 3.449988 4.532599
47 99 108 30.0 3.449988 4.605170
48 111 108 30.0 3.446808 4.605170
49 103 107 30.0 3.446808 4.584967
50 86 120 30.0 3.440418 4.867534
51 101 109 35.0 3.517498 4.744932
52 101 109 35.0 3.484312 4.744932
53 101 109 35.0 3.443618 4.744932
54 124 109 35.0 3.443618 4.744932
55 113 133 35.0 3.414443 5.192957
56 113 125 35.0 3.363842 5.075174
57 124 115 35.0 3.332205 4.867534
58 92 102 35.0 3.332205 4.564348
59 101 109 35.0 3.332205 4.744932
60 94 104 35.0 3.332205 4.605170
61 115 105 35.0 3.332205 4.605170
62 111 120 35.0 3.321432 4.976734
63 116 107 40.0 3.242592 4.787492
64 131 114 40.0 3.230804 4.941642
65 123 114 40.0 3.173878 4.941642
66 121 117 40.0 3.161247 5.010635
67 50 122 40.0 3.161247 5.105945
68 114 122 40.0 3.161247 5.105945
69 127 122 40.0 3.161247 5.105945
70 123 122 40.0 3.161247 5.105945
71 112 148 40.0 3.157000 5.501258
72 50 160 40.0 3.152736 5.634790
73 135 121 40.0 3.152736 5.087596
74 132 121 40.0 3.139833 5.087596
75 160 110 45.0 3.131137 4.941642
76 129 110 45.0 3.131137 4.941642
77 129 121 45.0 2.970414 5.164786
78 50 165 45.0 2.895912 5.774552
79 115 140 45.0 2.844909 5.472271
80 50 147 45.0 2.833213 5.572154
81 119 157 45.0 2.815409 5.686975
82 107 130 55.0 2.580217 5.463832
任何人都可以帮我解决这个错误。提前谢谢。
答案 0 :(得分:0)
尝试:
library(mgcv)
model.mcgv<-gam(lmpg~SP*lhp+WT*lhp+I(SP^2)+I(WT^2)+I(lhp^2)+VOL,
family=gaussian, data=sample)
par(mfrow=c(2,2))
plot(model.mcgv, all.terms=T)
我认为这可能是mcvg::plot.gam
中的错误。查看代码,似乎有一个参数all.terms
默认为FALSE
。如果FALSE
,则该方法设置n.para <- 0
并存在您收到的错误。