diff --git a/bs/.development/ECDF.R b/bs/.development/ECDF.R new file mode 100644 index 0000000..e4e2331 --- /dev/null +++ b/bs/.development/ECDF.R @@ -0,0 +1,68 @@ +# Calculation of empirical cumulative distribution function (ECDF) + +n <- 20 +randoms <- runif(n, 1, 10) +how_often <- sample.int(3, n, replace = TRUE) +sample <- numeric(sum(how_often)) +counter <- 1 +for (i in 1:n) { + sample[counter:(counter + how_often[i] - 1)] <- rep(randoms[i], how_often[i]) + counter <- counter + how_often[i] +} +sample <- sort(sample) +unique_sample <- unique(sample) +total_observations <- length(sample) +ecdf <- sapply(unique_sample, function(x) { + sum(sample <= x) / total_observations +}) +ecdf + +df <- data.frame(x = unique_sample, y = ecdf) +library(ggplot2) +ggplot(data = df, aes(x = x, y = y)) + + geom_step() + + geom_label(aes(label = round(x, 2))) + +# If the ECDF value is F_n(5) = 0.5 +# it means 50% of the sample values are less than or equal to 5. +# The CDF corresponds to a theoretical probability distribution (e.g. normal, exponential). +# It is the integral of the probability density function (PDF) + +# PDF are the d-functions in R +# CDF are the p-functions in R +# The q-functions in R compute the quantiles of a distribution. +# They are the inverse of the CDF. +# In simple terms, the quantile tells you the value of x +# below which a proportion p of the data lies. + +# Empirical quantiles +n <- 20 +randoms <- runif(n, 1, 10) +how_often <- sample.int(3, n, replace = TRUE) +sample <- numeric(sum(how_often)) +counter <- 1 +for (i in 1:n) { + sample[counter:(counter + how_often[i] - 1)] <- rep(randoms[i], how_often[i]) + counter <- counter + how_often[i] +} +sample <- sort(sample) +n <- length(sample) + +ps <- seq(0, 1, 0.1) +qq <- data.frame( + empirical = numeric(length(ps)), + theoretical = numeric(length(ps)) +) +for (i in 1:length(ps)) { + # i = p * (n + 1) + idx <- ps[i] * (n + 1) + if (floor(idx) == 0) { + idx <- 1 + } else if (ceiling(idx) >= n) { + idx <- n + } + qq$empirical[i] <- (sample[ceiling(idx)] + sample[floor(idx)] ) / 2 + qq$theoretical[i] <- qunif(p = ps[i], min = 1, max = 10) +} +plot(qq$theoretical, qq$empirical) +abline(0, 1, col = "red", lty = 2) diff --git a/bs/.development/overview_doseresponse.R b/bs/.development/overview_doseresponse.R deleted file mode 100644 index 86032d7..0000000 --- a/bs/.development/overview_doseresponse.R +++ /dev/null @@ -1,22 +0,0 @@ -df <- read.csv("bs/inst/test_data/lc50_testfile.csv", header = TRUE, sep = ";") -head(df) -res <- bs:::ic50(df, "abs", "conc", "names", "neg", "pos") -resDF <- lapply(res, function(x) { - if (inherits(x, "errorClass")) { - return(NULL) - } - return(x[[1]]) -}) -resDF <- resDF[!is.null(resDF)] -resDF <- resDF[!sapply(resDF, is.null)] -resDF <- Reduce(rbind, resDF) -resP <- lapply(res, function(x) { - if (inherits(x, "errorClass")) { - return(NULL) - } - return(x[[2]]) -}) -resP <- resP[!is.null(resP)] -resP <- resP[!sapply(resP, is.null)] - -bs:::create_plot_pages(resP) diff --git a/bs/.development/run_app.R b/bs/.development/run_app.R deleted file mode 100644 index 4fca893..0000000 --- a/bs/.development/run_app.R +++ /dev/null @@ -1,9 +0,0 @@ -# Run in browser - -# setwd("/home/konrad/Documents/Biostats") -# shinylive::export("./App", "docs", verbose = TRUE) -# httpuv::runStaticServer("docs") - -Sys.setenv(RUN_MODE = "BROWSER") -library(bs) -run_app() diff --git a/bs/.development/tinyplot_test.R b/bs/.development/tinyplot_test.R deleted file mode 100644 index b20409f..0000000 --- a/bs/.development/tinyplot_test.R +++ /dev/null @@ -1,29 +0,0 @@ -library(tinyplot) -library("grid") -library("ggplotify") - -f <- formula(uptake ~ conc | Treatment) - - -p <- as.ggplot( - expression( - tinyplot( - f, - data = CO2, - # facet = "by", - # facet.args = list(bg = "grey90"), - type = "boxplot", - palette = "dark2", - grid = TRUE, - axes = "l", - facet = Treatment ~ Type, - facet.args = list(col = "white", bg = "black"), - main = "CO2 uptake by conc and Treatment" - ) - ) -) -p - - -p2 <- as.ggplot(expression(plot(rnorm(10)))) -p2 diff --git a/bs/.development/warningPlot.R b/bs/.development/warningPlot.R deleted file mode 100644 index f5c27ed..0000000 --- a/bs/.development/warningPlot.R +++ /dev/null @@ -1,43 +0,0 @@ -library(ggplot2) - -df <- data.frame( - x = rep(c("A", "B"), each = 10), - y = c(1:9, Inf, 11:19, NA) -) - -p <- tryCatch( - { - ggplot(df, aes(x, y)) + - geom_boxplot() + - ggtitle("Boxplot with Non-finite Values") - }, - warning = function(w) { - message("Warning captured: Non-finite values removed from the data") - NULL - }, - error = function(e) { - message("Error captured: ", e$message) - NULL - } -) - -if (!is.null(p)) print(p) - - -test <- tryCatch( - { - print(p) - }, - warning = function(w) { - message("Warning captured: Non-finite values removed from the data") - return(w) - }, - error = function(e) { - message("Error captured: ", e$message) - NULL - } -) - -test - -