knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(bendr) 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
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 = bendr::fitdr(drc.formula,data.logged) summary(fitObject$curve.fit) pSingle = plot_single_drc(fitObject) + xlab("log(concentration)") + ylab("effect") pSingle #ggsave("/path/to/image.png",pSingle,width="8",height="6",units="in")
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 = fitdr_multi(drc.formula,mdata,2:3,conc) pMulti = plot_multi_drc(fo,plot.layout='multi') pMulti
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.