我正在尝试拟合具有近50 个变量的非线性模型(因为存在年份固定效应)。问题是我有太多的变量,我无法像这样写出完整的公式
nl_exp = as.formula(y ~ t1*year.matrix[,1] + t2*year.matrix[,2]
+... +t45*year.matirx[,45] + g*(x^d))
nl_model = gnls(nl_exp, start=list(t=0.5, g=0.01, d=0.1))
Run Code Online (Sandbox Code Playgroud)
其中y是二元响应变量,year.matirx是 45 列的矩阵(表示 45 个不同的年份),x是自变量。需要估计的参数是t1, t2, ..., t45, g, d。
我有很好的起始值t1, ..., t45, g, d。但是我不想为这个非线性回归写一个很长的公式。
我知道如果模型是线性的,则表达式可以简化为
l_model = lm(y ~ factor(year) + ...)
Run Code Online (Sandbox Code Playgroud)
factor(year)在gnls函数中尝试过,但它不起作用。此外,我也尝试过
nl_exp2 = as.formula(y ~ t*year.matrix + g*(x^d))
nl_model2 = gnls(nl_exp2, start=list(t=rep(0.2, 45), g=0.01, d=0.1))
它还会返回我的错误消息。
那么,有没有简单的方法来写下非线性公式和 中的起始值R?