是否存在执行非线性逻辑回归的R包?
更多的话:我有glm
,我可以glm (cbind (success, failure) ~ variable 1 + variable2, data = df, family = binomial (link = 'logit'))
,我可以使用nls
去nls (y ~ a * x^2 + b * x + c, data = df)
。
我希望有一些功能可以采用公式cbind (success, failure) ~ int - slo * x + gap / (1 + x / sca)
(其中x
,success
和failure
是唯一的数据,其他一切都是参数)与一个binomial (link = 'logit')
家庭,即结合两件事。我一直在淘谷歌,但却找不到那样的东西。
答案 0 :(得分:2)
试试gnlm::bnlr()
。默认链接是logit,您可以指定数据和参数的非线性函数。我会根据gap
和sca
是数据还是参数来包含两个答案。
library(gnlm)
如果gap
和sca
是数据:
## if gap and sca are data:
set.seed(1)
dat <- data.frame( x = rnorm(10),
gap = rnorm(10),
sca = rnorm(10),
y = rbinom(10,1,0.4))
y_cbind = cbind(dat$y, 1-dat$y)
attach(dat)
bnlr(y=y_cbind, mu = ~ int - slo * x + gap / (1 + x / sca), pmu = c(0,0))
输出:
Call:
bnlr(y = y_cbind, mu = ~int - slo * x + gap/(1 + x/sca), pmu = c(0,
0))
binomial distribution
Response: y_cbind
Log likelihood function:
{
m <- plogis(mu1(p))
-sum(wt * (y[, 1] * log(m) + y[, 2] * log(1 - m)))
}
Location function:
~int - slo * x + gap/(1 + x/sca)
-Log likelihood 2.45656
Degrees of freedom 8
AIC 4.45656
Iterations 8
Location parameters:
estimate se
int -1.077 0.8827
slo -1.424 1.7763
Correlations:
1 2
1 1.0000 0.1358
2 0.1358 1.0000
如果gap
和sca
是参数:
## if gap and sca are parameters:
detach(dat)
set.seed(2)
dat <- data.frame( x = rbinom(1000,1,0.3),
y = rbinom(1000,1,0.4))
y_cbind = cbind(dat$y, 1-dat$y)
attach(dat)
bnlr(y=y_cbind, mu = ~ int - slo * x + gap / (1 + x / sca), pmu = c(0,0,0,1))
输出:
Call:
bnlr(y = y_cbind, mu = ~int - slo * x + gap/(1 + x/sca), pmu = c(0,
0, 0, 1))
binomial distribution
Response: y_cbind
Log likelihood function:
{
m <- plogis(mu1(p))
-sum(wt * (y[, 1] * log(m) + y[, 2] * log(1 - m)))
}
Location function:
~int - slo * x + gap/(1 + x/sca)
-Log likelihood 672.9106
Degrees of freedom 996
AIC 676.9106
Iterations 7
Location parameters:
estimate se
int -0.22189 2.1007
slo 0.03828 3.6051
gap -0.20273 2.0992
sca 0.99885 0.3956
Correlations:
1 2 3 4
1 1.0000 1.859 -0.9993 -281.45
2 1.8587 1.000 -1.8592 -82.06
3 -0.9993 -1.859 1.0000 281.64
4 -281.4530 -82.061 281.6443 1.00