Home > database >  Is there R library or way to draw sigmoid function and get equation from raw data
Is there R library or way to draw sigmoid function and get equation from raw data

Time:11-17

enter image description here

This plot means drugs Concentration.

And I want to change this plot like sigmoid plot which is a curve.

[raw data]

μM <- c(0.01, 0.03, 0.1, 0.3, 1, 3, 10, 30)
log_μM <- log(c(0.01, 0.03, 0.1, 0.3, 1, 3, 10, 30))
DMSO <- c(97.01, 98.43, 98.29, 97.66, 96.51, 88.39, 38.54, 2.63) # D137
log_DMSO <- log(c(97.01, 98.43, 98.29, 97.66, 96.51, 88.39, 38.54, 2.63))

The raw data is small, but I want to express it well, and get the R-Square value.

CodePudding user response:

On the original (not log-log) scale, a sigmoid curve turns out to be a good fit.

## pack data into a data frame (best practice)
dd <- data.frame(μM, DMSO)
## fit with "self-starting 4-parameter logistic model"
fit <- nls(DMSO ~ SSfpl(μM, l_asy, r_asy, xmid, scal), data = dd)
## plot:
par(las = 1, bty = "l") ## cosmetic
plot(DMSO ~ μM, data = dd)  ## points
mvec <- seq(min(μM), max(μM), length.out = 101)
pvec <-predict(fit, newdata = data.frame(μM = mvec))
lines(mvec, pvec)

enter image description here

If you want to plot this on a log-log scale, just add log = "xy" to the plot() command, but note that the plot won't look sigmoidal:

enter image description here

The ?SSfpl web page gives the equation

l_asy (r_asy-l_asy)/(1 exp((xmid-μM)/scal))

coef(fit) will give you the estimated coefficients.

As for R^2: you can calculate an R^2 value via 1-mean(residuals(fit)^2)/var(μM) (I think — the second term might be off by factor of n/(n-1) or so because var() uses n-1 in the denominator ...) but there's lots of discussion (which you should read!) about why you might not want to/why it might not mean what you think it means ...

PS: it's a nuisance to have a variable name (μM) that can't easily be typed on a plain keyboard — might want to reconsider that choice ...

  • Related