3

I am trying to plot my values and fit them with curve using nls model. But I am getting back an error saying that there are no starting values for my variables.

conc <- c(1.83, 3.66, 7.32, 14.65, 29.30, 58.59, 117.19, 468.75, 937.5, 1875, 3750)  
avg <- c(0.02, 0.03, 0.05, 0.09, 0.23, 0.40, 0.60, 0.79, 0.98, 0.82, 1)

DataSet <- data.frame(conc, avg)

ggplot(DataSet, aes(x = conc, y = avg)) + 
  geom_point() +
  scale_x_log10() + 
  stat_smooth(aes(x=conc, y = avg), method = "nls", 
              formula = "avg~Emax*(conc^Hill)/((EC50^Hill)+(conc^Hill))",
              method.args=list(start=c(Emax = 1, EC50 = 100, Hill = 2)),
              se = FALSE)

# Warning message:
# Computation failed in `stat_smooth()`:
# parameters without starting value in 'data': avg, conc 
apitsch
  • 1,532
  • 14
  • 31
  • If you look at a scatterplot of the raw data, you will see the data points with avg < 1000 look as if they lie on a smooth curve, while the two data points with avg > 1000 do not seem to lie on a smooth curve with the rest of the data. It might be worth your time to verify the values for these two data points. – James Phillips Jul 15 '18 at 19:48

1 Answers1

5

You need to adjust x in formula as scale_x_log10() has been used for axis. Hence the inverse of log10 (e.g. ^10) should be used for x in formula.

The solution will be as:

library(ggplot2)

ggplot(DataSet, aes(x = conc, y = avg)) + 
  geom_point() +
  scale_x_log10() +
  stat_smooth(method = "nls", 
              formula = y~Emax*((10^x)^Hill)/((EC50^Hill)+((10^x)^Hill)),
              method.args=list(start=c(Emax = 1, EC50 = 100, Hill = 2)),
              se = FALSE)

enter image description here

MKR
  • 19,739
  • 4
  • 23
  • 33
  • 2
    Thanks! Now it works! And now I am really embarrassed for that stupid math error. – Tomáš Kroupa Jul 15 '18 at 23:54
  • No worries. You can accept the answer by clicking on `Tick` symbol in left of answer box so that it is helpful to future users. Thanks. – MKR Jul 16 '18 at 05:02