Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我只是想写一个 R 函数,它给我这个表达式的回归函数:y~(k,l,m,n)。这些字母代表非线性函数中的参数。当我以封闭形式(y〜())编写模型时,这个R函数应该从模型中提取回归函数。它可以是具有两个或多个参数的任何非线性函数。谁能帮我怎么做?
我认为你的症结在于得到一个可以解析的公式
你不能只是有y~(a,b,d),你需要一些函数名,即y ~ f(a, b, d)
y~(a,b,d)
y ~ f(a, b, d)
然后您可以使用all.vars提取变量名称并创建模型矩阵并编写您的拟合函数
all.vars
例如
all.vars(y ~ f(a,b,d)) ## [1] "y" "a" "b" "d" # get the response as.character(y ~ f(a,b,d))[2] ## [1] "y"
您可以使用这些从搜索路径中提取对象