使用library(dplyr)
# example dataset (picking useful columns)
dt % select(drat, mpg, disp, hp, wt, am)
# specify which columns we want as y (dependent) and x (independent)
ynames
xnames
# get unique values of the grouping variable am
groupvalues = unique(dt$am)
expand.grid(ynames,xnames,groupvalues) %>%
data.frame() %>%
select(y=Var1, x=Var2, group=Var3) %>%
mutate(formula = paste0(y," ~ B0*(",x,"^B1)*exp(B2*",x,")")) %>%
group_by(y,x,group,formula) %>%
do({ m1
start=c(B0 = 45, B1 = 0.2, B2 = 0.0007))
RSS
TSS
data.frame(RSS,TSS) })
# y x group formula RSS TSS
# 1 drat disp 0 drat ~ B0*(disp^B1)*exp(B2*disp) 1.3090406 2.770242
# 2 drat disp 1 drat ~ B0*(disp^B1)*exp(B2*disp) 1.1155372 1.590400
# 3 drat hp 0 drat ~ B0*(hp^B1)*exp(B2*hp) 2.1707337 2.770242
# 4 drat hp 1 drat ~ B0*(hp^B1)*exp(B2*hp) 0.8342527 1.590400
# 5 drat wt 0 drat ~ B0*(wt^B1)*exp(B2*wt) 2.2100162 2.770242
# 6 drat wt 1 drat ~ B0*(wt^B1)*exp(B2*wt) 1.1885811 1.590400
# 7 mpg disp 0 mpg ~ B0*(disp^B1)*exp(B2*disp) 98.4815286 264.587368
# 8 mpg disp 1 mpg ~ B0*(disp^B1)*exp(B2*disp) 46.8674036 456.309231
# 9 mpg hp 0 mpg ~ B0*(hp^B1)*exp(B2*hp) 74.9295161 264.587368
# 10 mpg hp 1 mpg ~ B0*(hp^B1)*exp(B2*hp) 112.5548955 456.309231
# 11 mpg wt 0 mpg ~ B0*(wt^B1)*exp(B2*wt) 104.2894519 264.587368
# 12 mpg wt 1 mpg ~ B0*(wt^B1)*exp(B2*wt) 71.1402536 456.309231方法无法对.ajax()做任何事情,因为remote只是remote的包装,不多与你的不同。 .ajax()采用与remote完全相同的选项,因为它是内部使用的jQuery方法。在这种情况下,为.ajax()创建自定义方法毫无意义。