0

Example dataset:

x <- 1:5
y <- c(0.01,0.02,0.05,0.1,0.2)

df <- data.frame(x, y)

My goal is to fit this data to a logistic function. I know logistic functions are normally used for binomial data, but in this case my data is continuous.

Since the y variable represents a proportion, the maximum possible value is 1. So I need to specify the asymptote as 1.

I know I can create a self-starting logistic function with nls and SSlogis like this:

model <- nls(y ~ SSlogis(x, Asym, xmid, scal),df)

But I'm unsure of how (or if I can) specify the asymptote.

Additionally, once I have the model, how can I forecast/plot future values? Similar to what this person did here.

Help much appreciated!

rawr
  • 20,481
  • 4
  • 44
  • 78
  • 3
    "Since the y variable represents a proportion, the maximum possible value is 1." Are you absolutely sure that you want to fit the logistic function and not do logistic regression, i.e., `plot(y ~ x, data = df, xlim = c(0, 30), ylim = c(0, 1)); fit <- glm(y ~ x, data = df, family = "binomial"); summary(fit);curve(predict(fit, newdata = data.frame(x = x), type = "response"), add = TRUE)`? – Roland Mar 05 '21 at 06:48
  • Addendum: If you want to do logistic regression you should specify `weights` as documented in `help("family")`. – Roland Mar 05 '21 at 07:26
  • @Roland Sorry, yes this is what I want, thank you very much! – Brayden Gerrard Mar 05 '21 at 16:40

0 Answers0