Skip to content

Commit 14c58b8

Browse files
committed
passing local checks
1 parent c61825a commit 14c58b8

26 files changed

+3230
-25
lines changed

DESCRIPTION

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ Imports:
2727
isotone,
2828
multcomp,
2929
PMCMRplus,
30-
bmd,
3130
dplyr,
3231
ggplot2,
3332
scales,
@@ -38,5 +37,7 @@ Imports:
3837
purrr,
3938
tidyr,
4039
rlang,
41-
MASS
40+
MASS,
41+
stringr,
42+
tidyselect
4243
Remotes: DoseResponse/bmd

R/Endpoints.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#' levels(g) <- c("0", "I", "II")
3232
#' pavaMean(x,g)
3333
pavaMean <- function(x,g,alternative = "greater"){
34-
require(PMCMRplus)
34+
requireNamespace("PMCMRplus", quietly = TRUE)
3535
alternative <- match.arg(alternative, choices = c("greater", "less"))
3636
xold <- x
3737
if (alternative == "less") {
@@ -169,7 +169,7 @@ summaryZG <- function (object, verbose=F,...)
169169
#' res <- PMCMRplus::williamsTest(x ~ g)
170170
#' getwilliamRes(res)
171171
getwilliamRes <- function(william,n=NULL){
172-
if(class(william)=="try-error"){
172+
if(inherits(william,"class")=="try-error"){
173173
if(is.null(n)) stop("when the test does not return a valid results, you need to specify
174174
the number of hypotheses. ")
175175
return(rep(NA,n=n))

R/data_description.R

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
#' @rdname drcHelper_datasets
1313
"test_cases_data"
1414

15+
#' test_cases_res for validation purpose
16+
#'
17+
#' @docType data
18+
#' @keywords datasets
19+
#' @rdname drcHelper_datasets
20+
"test_cases_res"
1521

1622
#' exampleHistData from StatCharrms
1723
#'
@@ -49,11 +55,6 @@
4955
#' @rdname drcHelper_datasets
5056
"dat_noED50"
5157

52-
#' test_cases_data for validation purpose
53-
#'
54-
#' @docType data
55-
#' @keywords datasets
56-
"test_cases_data"
5758

5859
#' An example dataset from study type OECD 201
5960
#'

R/drc_Helper.R

Lines changed: 118 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ ED.plus <- function(object, respLev, maxEff = TRUE, trend = "Increase", range =
169169
}
170170
}
171171
} else {
172-
require(bmd)
172+
requireNamespace("bmd", quietly = TRUE)
173173
# tmp <- lapply(cross2(respLev,modList),function(l){
174174
# x <- l[[1]]
175175
# y <- l[[2]]
@@ -456,7 +456,7 @@ plot.modList <- function(modList, respLev = NULL, data = NULL,
456456
return(newdata)
457457
})
458458
predData$Model <- factor(predData$Model, levels = unique(predData$Model))
459-
require(ggplot2)
459+
requireNamespace("ggplot2", quietly = TRUE)
460460
p <- ggplot(ex1, aes_(x = ~conc0, y = as.name(responseName))) +
461461
geom_ribbon(data = predData, aes_(x = as.name(doseName),
462462
y = ~p, ymin = ~pmin,
@@ -886,3 +886,119 @@ simDRdata <- function(nosim, fct, mpar, xerror, xpar = 1, yerror = "rnorm",
886886
}
887887
return(dat)
888888
}
889+
890+
891+
892+
#' Simulate Hierarchical Dose-Response Data
893+
#'
894+
#' This function simulates dose-response data with a hierarchical structure:
895+
#' n doses, m tanks per dose, and optionally k individuals per tank, with variance components
896+
#' at both the tank and individual levels.
897+
#'
898+
#' @param n_doses Number of dose levels
899+
#' @param dose_range Vector of length 2 specifying the min and max dose values
900+
#' @param m_tanks Number of tanks per dose
901+
#' @param k_individuals Number of individuals per tank (only used if include_individuals = TRUE)
902+
#' @param var_tank Variance at the tank level
903+
#' @param var_individual Variance at the individual level (only used if include_individuals = TRUE)
904+
#' @param include_individuals Logical, whether to simulate individual-level data (TRUE) or only tank-level data (FALSE)
905+
#' @param response_function Function that calculates the response given a dose
906+
#' @param ... Additional parameters to pass to the response_function
907+
#'
908+
#' @return A data frame containing the simulated dose-response data
909+
#' @export
910+
#'
911+
#' @examples
912+
#' # Simulate data with individuals
913+
#' sim_data_with_individuals <- simulate_dose_response(
914+
#' n_doses = 5,
915+
#' dose_range = c(0, 20),
916+
#' m_tanks = 3,
917+
#' include_individuals = TRUE
918+
#' )
919+
#'
920+
#' # Simulate data without individuals (tank-level only)
921+
#' sim_data_tanks_only <- simulate_dose_response(
922+
#' n_doses = 5,
923+
#' dose_range = c(0, 20),
924+
#' m_tanks = 3,
925+
#' include_individuals = FALSE
926+
#' )
927+
simulate_dose_response <- function(n_doses,
928+
dose_range = c(0, 20),
929+
m_tanks = 3,
930+
k_individuals = 10,
931+
var_tank = 4,
932+
var_individual = 2,
933+
include_individuals = TRUE,
934+
response_function = NULL,
935+
...) {
936+
937+
# Set default response function if not provided
938+
if (is.null(response_function)) {
939+
response_function <- function(dose, lower = 0, upper = 100, ED50 = 10, slope = 1) {
940+
lower + (upper - lower) / (1 + exp(-slope * (dose - ED50)))
941+
}
942+
}
943+
944+
# Define doses
945+
doses <- seq(dose_range[1], dose_range[2], length.out = n_doses)
946+
947+
if (include_individuals) {
948+
# Simulate data with individuals
949+
950+
# Create a data frame with all combinations of dose, tank, and individual
951+
simulated_data <- expand.grid(
952+
Dose = doses,
953+
Tank = 1:m_tanks,
954+
Individual = 1:k_individuals
955+
)
956+
957+
# Calculate the base response for each dose (vectorized)
958+
simulated_data$BaseResponse <- response_function(simulated_data$Dose, ...)
959+
960+
# Generate tank-level random effects (vectorized)
961+
# First, create a unique identifier for each dose-tank combination
962+
simulated_data$DoseTank <- paste(simulated_data$Dose, simulated_data$Tank, sep = "_")
963+
unique_dose_tanks <- unique(simulated_data$DoseTank)
964+
965+
# Generate tank effects for each unique dose-tank combination
966+
tank_effects <- stats::rnorm(length(unique_dose_tanks), mean = 0, sd = sqrt(var_tank))
967+
names(tank_effects) <- unique_dose_tanks
968+
969+
# Add tank effects to the data frame
970+
simulated_data$TankEffect <- tank_effects[simulated_data$DoseTank]
971+
972+
# Generate individual-level random effects (vectorized)
973+
simulated_data$IndividualEffect <- stats::rnorm(nrow(simulated_data), mean = 0, sd = sqrt(var_individual))
974+
975+
# Calculate the final response
976+
simulated_data$Response <- simulated_data$BaseResponse + simulated_data$TankEffect + simulated_data$IndividualEffect
977+
978+
# Clean up the data frame by removing intermediate columns
979+
simulated_data <- simulated_data[, c("Dose", "Tank", "Individual", "Response")]
980+
981+
} else {
982+
# Simulate data at tank level only
983+
984+
# Create a data frame with all combinations of dose and tank
985+
simulated_data <- expand.grid(
986+
Dose = doses,
987+
Tank = 1:m_tanks
988+
)
989+
990+
# Calculate the base response for each dose (vectorized)
991+
simulated_data$BaseResponse <- response_function(simulated_data$Dose, ...)
992+
993+
# Generate tank-level random effects (vectorized)
994+
simulated_data$TankEffect <- stats::rnorm(nrow(simulated_data), mean = 0, sd = sqrt(var_tank))
995+
996+
# Calculate the final response (no individual effects)
997+
simulated_data$Response <- simulated_data$BaseResponse + simulated_data$TankEffect
998+
999+
# Clean up the data frame by removing intermediate columns
1000+
simulated_data <- simulated_data[, c("Dose", "Tank", "Response")]
1001+
}
1002+
1003+
return(simulated_data)
1004+
}

R/ordinal.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ getEC50 <- function(mod,approximate = FALSE){
6464
#'
6565
#' @examples
6666
#' # Assuming `glmm_model` is a fitted glmmPQL model
67-
#' library(MASS)
68-
#' glmm_model <- glmmPQL(yt ~ dose,random= ~1 | Obs,family= quasibinomial(link="logit"),data=pvi_example)
67+
#' ## library(MASS)
68+
#' glmm_model <- MASS::glmmPQL(yt ~ dose,random= ~1 | Obs,family= quasibinomial(link="logit"),data=pvi_example)
6969
#' dose_result <- dose.p.glmmPQL(glmm_model)
7070
#' print(dose_result)
7171
#'

R/prelimnary.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#'
77
#' @param testdata A data frame containing the dose and response data.
88
#' @param ylab A string for the y-axis label. Default is "Response".
9-
#' @param xlab A string for the x-axis label. Default is "Test Concentration [nominal, mg a.s./L]".
9+
#' @param xlab A string for the x-axis label. Default is `"Test Concentration [nominal, mg a.s./L]"`.
1010
#' @param title A string for the plot title. Default is "Measured Variable".
1111
#' @param dose_col name of the dose column, default being "Dose". description
1212
#' @param response_col name of the response column. description
@@ -58,7 +58,7 @@ prelimPlot1 <- function(testdata, dose_col = "Dose", response_col = "Response",
5858
#'
5959
#' @param testdata A data frame containing the dose and response data.
6060
#' @param ylab A string for the y-axis label. Default is "Response".
61-
#' @param xlab A string for the x-axis label. Default is "Test Concentration [nominal, mg a.s./L]".
61+
#' @param xlab A string for the x-axis label. Default is `"Test Concentration [nominal, mg a.s./L]"`.
6262
#' @param title A string for the plot title. Default is "Measured Variable".
6363
#' @param dosecol name of the dose column, default being "Dose". description
6464
#' @param response_col name of the response column. description
@@ -95,7 +95,7 @@ prelimPlot2 <- function(testdata, ylab = "Response", xlab = "Test Concentration
9595
#'
9696
#' @param testdata A data frame containing the dose and response data.
9797
#' @param ylab A string for the y-axis label. Default is "Response".
98-
#' @param xlab A string for the x-axis label. Default is "Test Concentration [nominal, mg a.s./L]".
98+
#' @param xlab A string for the x-axis label. Default is `"Test Concentration [nominal, mg a.s./L]"`.
9999
#' @param title A string for the plot title. Default is "Measured Variable".
100100
#' @param a the quantile for corresponding CI for mean. default is qnorm(0.975).
101101
#' @param dosecol name of the dose column, default being "Dose". description

0 commit comments

Comments
 (0)