[R] Nonlinear logistic regression fitting

J C Nash pro|jcn@@h @end|ng |rom gm@||@com
Wed Jul 29 20:28:28 CEST 2020


My earlier posting on this thread was misleading. I thought the OP was trying to
fit a sigmoid to data. The problem is about fitting 0,1 responses.

The reproducible example cleared this up. Another strong demonstration that
a "simple reproducible example" can bring clarity so much more quickly than
general discussion.

JN


On 2020-07-29 8:56 a.m., Sebastien Bihorel wrote:
> #install.packages(gnlm)
> #require(gnlm)
> set.seed(12345)
> 
> nx <- 10
> x <- c(
>   rep(0, 3*nx),
>   rep(c(10, 30, 100, 500, 1000), each = nx)
> )
> rnd <- runif(length(x))
> a <- log(0.2/(1-0.2))
> b <- log(0.7/(1-0.7)) - a
> c <- 30
> likelihood <- a + b*x/(c+x)
> p <- exp(likelihood) / (1 + exp(likelihood))
> resp <- ifelse(rnd <= p, 1, 0)
> 
> df <- data.frame(
>   x = x,
>   resp = resp,
>   nresp = 1- resp
> )
> 
> head(df)
> 
> # glm can only assume linear effect of x, which is the wrong model
> glm_mod <- glm(
>   resp~x,
>   data = df,
>   family = 'binomial'
> )
> glm_mod
> 
> # Using gnlm package, estimate a model model with just intercept, and a model with predictor effect
> int_mod <- gnlm::bnlr( y = df[,2:3], link = 'logit', mu = ~ p_a, pmu = c(a) )
> emax_mod <- gnlm::bnlr( y = df[,2:3], link = 'logit',  mu = ~ p_a + p_b*x/(p_c+x),  pmu = c(a, b, c) )
> 
> int_mod
> emax_mod



More information about the R-help mailing list