aboutsummaryrefslogtreecommitdiff
path: root/R/drfit.R
diff options
context:
space:
mode:
Diffstat (limited to 'R/drfit.R')
-rw-r--r--R/drfit.R111
1 files changed, 60 insertions, 51 deletions
diff --git a/R/drfit.R b/R/drfit.R
index 20f4426..70e05df 100644
--- a/R/drfit.R
+++ b/R/drfit.R
@@ -51,6 +51,7 @@ drfit <- function(data, startlogEC50 = NA, chooseone=TRUE,
splitted <- split(data,data$substance)
for (i in substances) {
tmp <- splitted[[i]]
+ fit <- FALSE
if (length(tmp$response) == 0) {
nodata = TRUE
} else {
@@ -73,29 +74,31 @@ drfit <- function(data, startlogEC50 = NA, chooseone=TRUE,
if (responseathighestdose < 0.5) {
inactive <- FALSE
- if (lognorm) {
- m <- try(nls(response ~ pnorm(-log10(dose),-logEC50,slope),
- data=tmp,
- start=list(logEC50=startlogEC50[[i]],slope=1)))
+ if (linearlogis) {
+ m <- try(nls(response ~ linearlogisf(dose,1,f,logEC50,b),
+ data=tmp,
+ start=list(f=f0,logEC50=startlogEC50[[i]],b=b0)))
if (!inherits(m, "try-error")) {
- s <- summary(m)
+ fit <- TRUE
ri <- ri + 1
+ s <- summary(m)
sigma[[ri]] <- s$sigma
rsubstance[[ri]] <- i
rn[[ri]] <- n
rlld[[ri]] <- log10(lowestdose)
rlhd[[ri]] <- log10(highestdose)
- mtype[[ri]] <- "lognorm"
+ mtype[[ri]] <- "linearlogis"
logEC50[[ri]] <- coef(m)[["logEC50"]]
- b[[ri]] <- NA
- f[[ri]] <- NA
+ slope[[ri]] <- NA
if (logEC50[[ri]] > rlhd[[ri]]) {
logEC50[[ri]] <- NA
- slope[[ri]] <- NA
stderrlogEC50[[ri]] <- NA
+ b[[ri]] <- NA
+ f[[ri]] <- NA
} else {
- slope[[ri]] <- coef(m)[["slope"]]
stderrlogEC50[[ri]] <- s$parameters["logEC50","Std. Error"]
+ b[[ri]] <- coef(m)[["b"]]
+ f[[ri]] <- coef(m)[["f"]]
}
}
}
@@ -106,56 +109,62 @@ drfit <- function(data, startlogEC50 = NA, chooseone=TRUE,
m <- try(nls(response ~ plogis(-log10(dose),-logEC50,slope),
data=tmp,
start=list(logEC50=startlogEC50[[i]],slope=1)))
- if (!inherits(m, "try-error")) {
- s <- summary(m)
- ri <- ri + 1
- rsubstance[[ri]] <- i
- rn[[ri]] <- n
- rlld[[ri]] <- log10(lowestdose)
- rlhd[[ri]] <- log10(highestdose)
- mtype[[ri]] <- "logis"
- sigma[[ri]] <- s$sigma
- logEC50[[ri]] <- coef(m)[["logEC50"]]
- b[[ri]] <- NA
- f[[ri]] <- NA
- if (logEC50[[ri]] > rlhd[[ri]]) {
- logEC50[[ri]] <- NA
- slope[[ri]] <- NA
- stderrlogEC50[[ri]] <- NA
- } else {
- slope[[ri]] <- coef(m)[["slope"]]
- stderrlogEC50[[ri]] <- s$parameters["logEC50","Std. Error"]
+ if (chooseone==FALSE || fit==FALSE) {
+ if (!inherits(m, "try-error")) {
+ fit <- TRUE
+ ri <- ri + 1
+ s <- summary(m)
+ sigma[[ri]] <- s$sigma
+ rsubstance[[ri]] <- i
+ rn[[ri]] <- n
+ rlld[[ri]] <- log10(lowestdose)
+ rlhd[[ri]] <- log10(highestdose)
+ mtype[[ri]] <- "logis"
+ logEC50[[ri]] <- coef(m)[["logEC50"]]
+ b[[ri]] <- NA
+ f[[ri]] <- NA
+ if (logEC50[[ri]] > rlhd[[ri]]) {
+ logEC50[[ri]] <- NA
+ slope[[ri]] <- NA
+ stderrlogEC50[[ri]] <- NA
+ } else {
+ slope[[ri]] <- coef(m)[["slope"]]
+ stderrlogEC50[[ri]] <- s$parameters["logEC50","Std. Error"]
+ }
}
}
}
- if (linearlogis) {
- m <- try(nls(response ~ linearlogisf(dose,1,f,logEC50,b),
- data=tmp,
- start=list(f=f0,logEC50=startlogEC50[[i]],b=b0)))
- if (!inherits(m, "try-error")) {
- s <- summary(m)
- ri <- ri + 1
- rsubstance[[ri]] <- i
- rn[[ri]] <- n
- rlld[[ri]] <- log10(lowestdose)
- rlhd[[ri]] <- log10(highestdose)
- mtype[[ri]] <- "linearlogis"
- sigma[[ri]] <- s$sigma
- logEC50[[ri]] <- coef(m)[["logEC50"]]
- slope[[ri]] <- NA
- if (logEC50[[ri]] > rlhd[[ri]]) {
- logEC50[[ri]] <- NA
- stderrlogEC50[[ri]] <- NA
+ if (lognorm) {
+ m <- try(nls(response ~ pnorm(-log10(dose),-logEC50,slope),
+ data=tmp,
+ start=list(logEC50=startlogEC50[[i]],slope=1)))
+ if (chooseone==FALSE || fit==FALSE) {
+ if (!inherits(m, "try-error")) {
+ fit <- TRUE
+ ri <- ri + 1
+ s <- summary(m)
+ sigma[[ri]] <- s$sigma
+ rsubstance[[ri]] <- i
+ rn[[ri]] <- n
+ rlld[[ri]] <- log10(lowestdose)
+ rlhd[[ri]] <- log10(highestdose)
+ mtype[[ri]] <- "lognorm"
+ logEC50[[ri]] <- coef(m)[["logEC50"]]
b[[ri]] <- NA
f[[ri]] <- NA
- } else {
- stderrlogEC50[[ri]] <- s$parameters["logEC50","Std. Error"]
- b[[ri]] <- coef(m)[["b"]]
- f[[ri]] <- coef(m)[["f"]]
+ if (logEC50[[ri]] > rlhd[[ri]]) {
+ logEC50[[ri]] <- NA
+ slope[[ri]] <- NA
+ stderrlogEC50[[ri]] <- NA
+ } else {
+ slope[[ri]] <- coef(m)[["slope"]]
+ stderrlogEC50[[ri]] <- s$parameters["logEC50","Std. Error"]
+ }
}
}
}
+
} else {
inactive <- TRUE
}

Contact - Imprint