Reputation: 21
I am trying to use paste0 so that I can run a series of linear models (with a quadratic term), one for each independent variable.
Unfortunately, when I use the more complicated form (shown in last statement) R seems to not recognize the comma that needs to go between the model statement and the data statement.
Any ideas?
Chem<-structure(list(PE = c(9L, 8L, 8L, 9L, 5L, 6L, 10L, 9L, 11L, 9L,
7L, 7L, 7L, 10L, 13L, 14L, 5L, 6L, 10L, 12L, 14L, 13L, 12L, 12L,
7L, 7L, 6L, 12L, 9L, 14L), ROR5 = c(13, 13, 13, 12.2, 10, 9.8,
9.9, 10.3, 9.5, 9.9, 7.9, 7.3, 7.8, 6.5, 24.9, 24.6, 14.9, 13.8,
13.5, 14.9, 15.4, 11.6, 14.2, 13.8, 12, 11, 13.8, 11.5, 6.4,
3.8), DE = c(0.7, 0.7, 0.4, 0.2, 0.4, 0.5, 0.5, 0.3, 0.4, 0.4,
0.4, 0.6, 0.4, 0.4, 0, 0, 1.1, 0.6, 0.5, 0.3, 0.3, 0.4, 0.2,
0.1, 0.5, 0.3, 0.2, 0.4, 0.7, 0.6), SALESGR5 = c(20.2, 17.2,
14.5, 12.9, 13.6, 12.1, 10.2, 11.4, 13.5, 12.1, 10.8, 15.4, 11,
18.7, 16.2, 16.1, 13.7, 20.9, 14.3, 29.1, 15.2, 18.7, 16.7, 12.6,
15, 12.8, 14.9, 15.4, 16.1, 6.8), EPS5 = c(15.5, 12.7, 15.1,
11.1, 8, 14.5, 7, 8.7, 5.9, 4.2, 16, 4.9, 3, -3.1, 16.9, 16.9,
48.9, 36, 16, 22.8, 15.1, 22.1, 18.7, 18, 14.9, 10.8, 9.6, 11.7,
-2.8, -11.1), NPM1 = c(7.2, 7.3, 7.9, 5.4, 6.7, 3.8, 4.8, 4.5,
3.5, 4.6, 3.4, 5.1, 5.6, 1.3, 12.5, 11.2, 5.8, 10.9, 8.4, 4.9,
21.9, 8.1, 8.2, 5.6, 3.6, 5, 4.4, 7.2, 6.8, 0.9), PAYOUTR1 = c(0.43,
0.38, 0.41, 0.57, 0.32, 0.51, 0.38, 0.48, 0.57, 0.49, 0.49, 0.27,
0.32, 0.38, 0.32, 0.47, 0.1, 0.16, 0.4, 0.36, 0.23, 0.2, 0.37,
0.34, 0.36, 0.34, 0.31, 0.51, 0.22, 1)), class = "data.frame", row.names = c(NA,
-30L))
IV<-'SALESGR5'
linear<-lm(paste0('PE~',IV),data=Chem)
qm<-lm(PE~SALESGR5+I(SALESGR5^2),data=Chem)
quad<-lm(paste0('PE~',IV,'+I(',IV,'^2),data=Chem'))
paste0('PE~',IV,'+I(',IV,'^2),data=Chem')
For completeness, the error message is
Error in str2lang(x) : <text>:1:26: unexpected ','
1: PE~SALESGR5+I(SALESGR5^2),
^
Upvotes: 0
Views: 44