knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(drfit)
library(tibble)
library(dplyr)
library(ggplot2)

You can read your data from csv,tsv or excel:

fname = "/path/to/file"
require(readr)
fdata = readr::read_csv(fname)
fdata = readr::read_tsv(fname)
require(readxl)
fdata = readxl::read_excel(fname)
names(fdata)
View(fdata)

But for a quick test, we generate some dummy data:

sdata = as_tibble(
  data.frame(
    conc=c(1,10,100,1000,5000),
    effect=c(12,27,69,86,98)
  ))

then we set the formula for the dose response model

##SET the model formula here
drc.formula = effect ~ 100 / (1 + 10^((logEC50-logconc) * slope))

if you want to adapt the dose response curve to the maximum and minimum effect values, use this formula instead

loe = min(sdata$effect)
hie = max(sdata$effect)
drc.formula.dyn = substitute(effect ~ bottom + ((top-bottom)/(1+10^((logEC50-logconc)*slope))),list(top = hie, bottom=loe))

Here is an example for fitting a single dose-response curve

data.logged = sdata %>% mutate(logconc = log10(conc))

fitObject = drfit(drc.formula,data.logged)
summary(fitObject$curve.fit)
plot_single_drc(fitObject) + xlab("log(concentration)") + ylab("effect")

#ggsave("/path/to/image.png",p,width="8",height="6",units="in")

Reporting goodness of fit

R^2 is considered inadequate for nonlinear fits (https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2892436/) Instead, use akaike's An Information Criterion(AIC).

mdata = as_tibble(
  data.frame(
    conc=c(1,10,100,1000,5000),
    effectA=c(12,27,69,86,98),
    effectB=c(15,23,64,82,91)
  ))

fo = drfit::drfit_multi(drc.formula,mdata,2:3,conc)
plot_multi_drc(fo,plot.layout='multi')


alxbetz/bendr documentation built on Aug. 2, 2020, 2:06 a.m.