diff options
Diffstat (limited to 'R/drfit.R')
-rw-r--r-- | R/drfit.R | 16 |
1 files changed, 11 insertions, 5 deletions
@@ -117,15 +117,16 @@ drfit <- function(data, startlogEC50 = NA, chooseone=TRUE, runit[[ri]] <- unit rlld[[ri]] <- log10(lowestdose) rlhd[[ri]] <- log10(highestdose) - mtype[[ri]] <- "linlogit" logEC50[[ri]] <- coef(m)[["logEC50"]] if (logEC50[[ri]] > rlhd[[ri]]) { + mtype[[ri]] <- "no fit" logEC50[[ri]] <- NA stderrlogEC50[[ri]] <- NA a[[ri]] <- NA b[[ri]] <- NA c[[ri]] <- NA } else { + mtype[[ri]] <- "linlogit" stderrlogEC50[[ri]] <- s$parameters["logEC50","Std. Error"] a[[ri]] <- coef(m)[["logEC50"]] b[[ri]] <- coef(m)[["b"]] @@ -150,15 +151,16 @@ drfit <- function(data, startlogEC50 = NA, chooseone=TRUE, runit[[ri]] <- unit rlld[[ri]] <- log10(lowestdose) rlhd[[ri]] <- log10(highestdose) - mtype[[ri]] <- "probit" logEC50[[ri]] <- coef(m)[["logEC50"]] c[[ri]] <- NA if (logEC50[[ri]] > rlhd[[ri]]) { + mtype[[ri]] <- "no fit" logEC50[[ri]] <- NA stderrlogEC50[[ri]] <- NA a[[ri]] <- NA b[[ri]] <- NA } else { + mtype[[ri]] <- "probit" stderrlogEC50[[ri]] <- s$parameters["logEC50","Std. Error"] a[[ri]] <- coef(m)[["logEC50"]] b[[ri]] <- coef(m)[["scale"]] @@ -183,16 +185,17 @@ drfit <- function(data, startlogEC50 = NA, chooseone=TRUE, runit[[ri]] <- unit rlld[[ri]] <- log10(lowestdose) rlhd[[ri]] <- log10(highestdose) - mtype[[ri]] <- "logit" logEC50[[ri]] <- a[[ri]] <- coef(m)[["logEC50"]] b[[ri]] <- coef(m)[["scale"]] c[[ri]] <- NA if (logEC50[[ri]] > rlhd[[ri]]) { + mtype[[ri]] <- "no fit" logEC50[[ri]] <- NA stderrlogEC50[[ri]] <- NA a[[ri]] <- NA b[[ri]] <- NA } else { + mtype[[ri]] <- "logit" stderrlogEC50[[ri]] <- s$parameters["logEC50","Std. Error"] } } @@ -215,7 +218,6 @@ drfit <- function(data, startlogEC50 = NA, chooseone=TRUE, runit[[ri]] <- unit rlld[[ri]] <- log10(lowestdose) rlhd[[ri]] <- log10(highestdose) - mtype[[ri]] <- "weibull" a[[ri]] <- coef(m)[["location"]] b[[ri]] <- coef(m)[["shape"]] sqrdev <- function(logdose) { @@ -224,11 +226,13 @@ drfit <- function(data, startlogEC50 = NA, chooseone=TRUE, logEC50[[ri]] <- nlm(sqrdev,startlogEC50[[i]])$estimate c[[ri]] <- NA if (logEC50[[ri]] > rlhd[[ri]]) { + mtype[[ri]] <- "no fit" logEC50[[ri]] <- NA stderrlogEC50[[ri]] <- NA a[[ri]] <- NA b[[ri]] <- NA } else { + mtype[[ri]] <- "weibull" stderrlogEC50[[ri]] <- NA } } @@ -280,6 +284,7 @@ drplot <- function(drresults, data, dtype = "std", alpha = 0.95, pointsize = 12, colors = 1:8, devoff=T, lpos="topright") { + # Check if all data have the same unit unitlevels <- levels(as.factor(drresults$unit)) if (length(unitlevels) == 1) { unit <- unitlevels @@ -289,7 +294,7 @@ drplot <- function(drresults, data, dtype = "std", alpha = 0.95, # Get the plot limits on the x-axis (log of the dose) if(is.data.frame(data)) { - if (min(data$dose == 0)) { + if (min(data$dose) == 0) { cat("At least one of the dose levels is 0 - this is not a valid dose.") } else { lld <- log10(min(data$dose)) @@ -336,6 +341,7 @@ drplot <- function(drresults, data, dtype = "std", alpha = 0.95, # Plot the data either as raw data or as error bars if(is.data.frame(data)) { splitted <- split(data,data$substance) + # n is the index for the dose-response curves n <- 0 if (bw) colors <- rep("black",length(dsubstances)) # Loop over the substances in the data |