【问题标题】:Nonlinear logistic regression package in RR中的非线性逻辑回归包
【发布时间】:2017-07-27 23:24:12
【问题描述】:

是否有执行非线性逻辑回归的 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') 系列,即结合这两件事。我一直在搜索谷歌,但没有找到类似的东西。

【问题讨论】:

  • 我没有阅读所有内容,但是 ctrl+F 似乎找不到 logistic 除了逻辑 函数binomial 找不到logit 链接函数和所有示例都使用名为 Dref 的东西,我不知道那是什么。我尝试将gnm 与我在那里描述的公式一起使用,但它给了我一个object 'int' not found 错误。如果你告诉我可以在那里完成,但我会进一步研究。
  • 这篇博文向您展示了如何使用 gmm 进行操作,但您需要构建一些方程式并仔细检查这些人的逻辑! r-bloggers.com/…
  • gap 和 sca 数据或参数是否需要估计?
  • x是唯一的数据,gap和sca和slo和int都是参数

标签: r logistic-regression non-linear-regression


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2021-01-03
    • 2021-11-23
    • 1970-01-01
    • 2020-11-28
    • 2018-01-26
    • 1970-01-01
    • 1970-01-01
    • 2016-08-09
    • 2011-10-14
    相关资源
    最近更新 更多