Nonlinear logistic regression package in R -
is there r package performs nonlinear logistic regression?
in more words: have glm
, can go glm (cbind (success, failure) ~ variable 1 + variable2, data = df, family = binomial (link = 'logit'))
, , can use nls
go nls (y ~ * x^2 + b * x + c, data = df)
.
i'd have function take formula cbind (success, failure) ~ int - slo * x + gap / (1 + x / sca)
(where x
, success
, , failure
data , else parametres) binomial (link = 'logit')
family, i.e. combine both things. i've been scouring google , haven't been able find that.
try gnlm::bnlr()
. default link logit , can specify nonlinear function of data , parameters. include 2 answers depending on whether or not gap
, sca
data or parameters.
library(gnlm)
in case of gap
, sca
data:
## if gap , sca 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))
output:
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
in case gap
, sca
parameters:
## if gap , sca 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))
output:
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
Comments
Post a Comment