if (FALSE) {
library(HelpersMG)
# _______________________________________________________________
# right censored distribution with gamma distribution
# _______________________________________________________________
# Detection limit
DL <- 100
# Generate 100 random data from a gamma distribution
obc <- rgamma(100, scale=20, shape=2)
# remove the data below the detection limit
obc[obc>DL] <- +Inf
# search for the parameters the best fit these censored data
result <- cutter(observations=obc, upper_detection_limit=DL,
cut_method="censored")
result
plot(result, xlim=c(0, 150), breaks=seq(from=0, to=150, by=10), col.mcmc=NULL)
plot(result, xlim=c(0, 150), breaks=seq(from=0, to=150, by=10))
# _______________________________________________________________
# The same data seen as truncated data with gamma distribution
# _______________________________________________________________
obc <- obc[is.finite(obc)]
# search for the parameters the best fit these truncated data
result <- cutter(observations=obc, upper_detection_limit=DL,
cut_method="truncated")
result
plot(result, xlim=c(0, 150), breaks=seq(from=0, to=150, by=10))
# _______________________________________________________________
# left censored distribution with gamma distribution
# _______________________________________________________________
# Detection limit
DL <- 10
# Generate 100 random data from a gamma distribution
obc <- rgamma(100, scale=20, shape=2)
# remove the data below the detection limit
obc[obcUDL] <- +Inf
# search for the parameters the best fit these truncated data
result1_gamma <- cutter(observations=obc, lower_detection_limit=LDL,
upper_detection_limit = UDL,
distribution="gamma",
cut_method="censored", n.iter=5000, debug=0)
result1_normal <- cutter(observations=obc, lower_detection_limit=LDL,
upper_detection_limit = UDL,
distribution="normal",
cut_method="censored", n.iter=5000)
result1_lognormal <- cutter(observations=obc, lower_detection_limit=LDL,
upper_detection_limit = UDL,
distribution="lognormal",
cut_method="censored", n.iter=5000)
result1_Weibull <- cutter(observations=obc, lower_detection_limit=LDL,
upper_detection_limit = UDL,
distribution="Weibull",
cut_method="censored", n.iter=5000)
result1_generalized.gamma <- cutter(observations=obc, lower_detection_limit=LDL,
upper_detection_limit = UDL,
distribution="generalized.gamma",
cut_method="censored", n.iter=5000)
result2_gamma <- cutter(observations=obc, lower_detection_limit=LDL,
upper_detection_limit = UDL,
distribution="gamma",
n.mixture=2,
cut_method="censored", n.iter=5000)
result2_normal <- cutter(observations=obc, lower_detection_limit=LDL,
upper_detection_limit = UDL,
distribution="normal",
n.mixture=2,
cut_method="censored", n.iter=5000)
result2_lognormal <- cutter(observations=obc, lower_detection_limit=LDL,
upper_detection_limit = UDL,
distribution="lognormal",
n.mixture=2,
cut_method="censored", n.iter=5000)
result2_Weibull <- cutter(observations=obc, lower_detection_limit=LDL,
upper_detection_limit = UDL,
distribution="Weibull",
n.mixture=2,
cut_method="censored", n.iter=5000)
result2_generalized.gamma <- cutter(observations=obc, lower_detection_limit=LDL,
upper_detection_limit = UDL,
distribution="generalized.gamma",
n.mixture=2,
cut_method="censored", n.iter=5000)
compare_AIC(nomixture.gamma=result1_gamma,
nomixture.normal=result1_normal,
nomixture.lognormal=result1_lognormal,
nomixture.Weibull=result1_Weibull,
nomixture.generalized.gamma=result1_generalized.gamma,
mixture.gamma=result2_gamma,
mixture.normal=result2_normal,
mixture.lognormal=result2_lognormal,
mixture.Weibull=result2_Weibull,
mixture.generalized.gamma=result2_generalized.gamma)
plot(result2_gamma, xlim=c(0, 600), breaks=seq(from=0, to=600, by=10))
plot(result2_generalized.gamma, xlim=c(0, 600), breaks=seq(from=0, to=600, by=10))
# _______________________________________________________________
# left and right censored distribution
# _______________________________________________________________
# Generate 100 random data from a gamma distribution
obc <- rgamma(100, scale=20, shape=2)
# Detection limit
LDL <- 10
# remove the data below the detection limit
obc[obcUDL] <- +Inf
# search for the parameters the best fit these censored data
result <- cutter(observations=obc, lower_detection_limit=LDL,
upper_detection_limit=UDL,
cut_method="censored")
result
plot(result, xlim=c(0, 150), col.DL=c("black", "grey"),
col.unobserved=c("green", "blue"),
breaks=seq(from=0, to=150, by=10))
# _______________________________________________________________
# Example with two values for lower detection limits
# corresponding at two different methods of detection for example
# with gamma distribution
# _______________________________________________________________
obc <- rgamma(50, scale=20, shape=2)
# Detection limit for sample 1 to 50
LDL1 <- 10
# remove the data below the detection limit
obc[obc
Run the code above in your browser using DataLab