gpt4 book ai didi

r - R中的非线性逻辑回归包

转载 作者:行者123 更新时间:2023-12-01 03:18:15 24 4
gpt4 key购买 nike

是否有执行非线性逻辑回归的 R 包?

换句话说:我有 glm,我可以使用它 glm (cbind (success, failure) ~ variable 1 + variable2, data = df, family = binomial (link = 'logit')),我可以使用 nlsnls (y ~ a * x^2 + b * x + c, data = df).

我想要一些采用公式 cbind (success, failure) ~ int - slo * x + gap/(1 + x/sca) 的函数(其中 xsuccessfailure 是唯一的数据,其他一切都是参数)具有 binomial (link = 'logit') 家庭,即将两者结合起来。我一直在搜索谷歌,但没能找到类似的东西。

最佳答案

试试 gnlm::bnlr()。默认链接是 logit,您可以指定数据和参数的非线性函数。我包含两个答案,具体取决于 gapsca 是数据还是参数。

library(gnlm)

gapsca是数据的情况下:

## 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

如果 gapsca 是参数:

## 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

关于r - R中的非线性逻辑回归包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45362548/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com