以R中的mtcars为例:我想对mpg和disp之间的关系进行非线性回归,每个柱面和每组对比 . 在我的情况下,我有一个比mtcars大得多的数据帧 . 我知道没有足够的数据 . 但为了简化问题,我将始终使用mtcars,但假设我们有足够的数据来进行多组非线性回归,公式为tanh类型 . 我想为每个cyl和每组vs做一个tanh类型的回归,所以我尝试了:

mtcars2 <-list()
reg2 <-list()
attach(mtcars)
for (i in levels(cyl))
{
    mtcars2[[i]] <-
        groupedData( mpg ~ disp | vs,
             data = subset(mtcars,cyl==i))
    reg2[[i]] <- nlsList(mpg ~ A + B * tanh(disp/C), data=mtcars2[[i]],
                   start = list(A=1, B=1, C=0.5), na.action = na.omit)
}

我想通过绘图(mycars2 [[i]])和tanh回归来做散点图 . 不幸的是我总是有错误:

dim(x) must have positive length

你可以帮帮我吗?我可以直接使用吗?

nlme() or other functions to do regressions and xyplot results?

非常感谢你!