Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
25f9d79
added validation dunnett
Zhenglei-BCS Sep 22, 2025
2832336
Add Statistical Test Validation Framework and Configuration
Zhenglei-BCS Sep 22, 2025
3f1020e
Refactor code structure for improved readability and maintainability
Zhenglei-BCS Sep 22, 2025
73c3fab
minor updates
Sep 22, 2025
ac28196
updated badge
Zhenglei-BCS Sep 22, 2025
79bf792
add devcontainer
Zhenglei-BCS Sep 22, 2025
837aa46
Add comprehensive tests and validation for data matching logic
Zhenglei-BCS Sep 23, 2025
74b87dc
Add endpoint data type analysis and fixed validation logic for Dunnet…
Zhenglei-BCS Sep 23, 2025
7049d99
Add validation summaries, test scripts, and updated tolerances for Du…
Zhenglei-BCS Sep 23, 2025
3a1af28
Add comprehensive validation functions and debugging scripts for FG00225
Zhenglei-BCS Sep 23, 2025
90611d3
Add script to investigate multiple studies with multiple endpoints an…
Zhenglei-BCS Sep 23, 2025
7f070b4
Add comprehensive validation reports and detailed analysis for Dunnet…
Zhenglei-BCS Sep 23, 2025
ffb0143
Enhance devcontainer.json with R support features
Zhenglei-BCS Sep 23, 2025
6b03acb
Update README and _pkgdown.yml with contribution guidelines and navba…
Zhenglei-BCS Sep 23, 2025
1ade5ba
additional attempts to fix
Zhenglei-BCS Sep 23, 2025
98e8d35
zml
Zhenglei-BCS Sep 23, 2025
a8922a2
Refactor navbar structure and article organization in _pkgdown.yml fo…
Zhenglei-BCS Sep 23, 2025
e14107c
test
Zhenglei-BCS Sep 23, 2025
90d6c78
successful Dunnett Testing Validation, Almost
Sep 23, 2025
1b62483
Merge branch 'dev' of https://github.com/Bayer-Group/drcHelper into dev
Zhenglei-BCS Sep 24, 2025
49b1f9c
Fix article links in _pkgdown.yml and update figure captions in drcHe…
Zhenglei-BCS Sep 24, 2025
12d237c
clean up
Sep 24, 2025
363e357
added knitr-setup.R
Zhenglei-BCS Sep 24, 2025
cbd0232
Add new navbar links for CA test verification and MCP test validation…
Zhenglei-BCS Sep 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",

"features": {
"ghcr.io/rocker-org/devcontainer-features/r-apt:0": {
// See: https://github.com/rocker-org/devcontainer-features/blob/main/src/r-apt/README.md#options
//
// Use RSupport (incl languageserver and httpgd) spand bspm
"vscodeRSupport": "full",
"installBspm": true,
//
// But turn off Radian (R console), devtools, extre Markdown support and debugger
// You can add each of these individually or jointly. See the table at
// https://github.com/rocker-org/devcontainer-features/blob/main/src/r-apt/README.md#options
"installRadian": false,
"installDevTools": false,
"installRMarkdown": false,
"installVscDebugger": false,
"useTesting": false
}

},

// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
// use httpgd as the plotting device
"r.plot.useHttpgd": true,
//
// turn these two on with Radian
//"r.rterm.linux": "/usr/local/bin/radian",
//"r.bracketedPaste": true,
//
// some guidance for the editor on R files
"[r]": {
"editor.wordSeparators": "`~!@#%$^&*()-=+[{]}\\|;:'\",<>/?"
},
// see https://stackoverflow.com/questions/68858490/disable-r-linting-in-vscode
"r.lsp.diagnostics": false
}
}
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [ 8787 ],
//
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "R -q -e 'install.packages(\"tidyverse\")'",

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"

}
41 changes: 41 additions & 0 deletions .github/instructions/copilot_instructions.instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
applyTo: '**/*.md'
---

# Project Context and Coding Guidelines
This project is an R-package dessigned to facilitate the analysis of dose-response data. The package provides functions for data preprocessing, visualization, dose-response model fitting, NOEC calculations.
The package is intended for use by researchers and practitioners in toxicology, pharmacology, and related fields.

## Coding Guidelines
1. **Language**: All code should be written in R, following the tidyverse style guide.
2. **Documentation**: Use Roxygen2 for documenting functions, including descriptions, parameters, return values, and examples.
3. **Testing**: Implement unit tests using the testthat package to ensure code reliability and correctness. Use describe and it blocks for clarity.
4. **Version Control**: Use Git for version control, with clear and descriptive commit messages.
5. **Code Style**: Follow consistent naming conventions (snake_case for variables and functions), indentation, and spacing.
6. **Dependencies**: Minimize external dependencies and ensure all required packages are listed in the DESCRIPTION file.
7. **Error Handling**: Implement robust error handling and input validation to ensure functions behave predictably.
8. **Performance**: Optimize code for performance, especially for large datasets, while maintaining readability.
9. **Collaboration**: Encourage code reviews and collaborative development practices to maintain code quality.
10. **Licensing**: Ensure all code complies with the project's licensing terms (GPL-3).
11. **Data Privacy**: Ensure that any data used or shared complies with relevant data privacy regulations and guidelines.
12. **Continuous Integration**: Set up CI/CD pipelines to automate testing and deployment processes.
13. **Examples**: Provide clear and concise examples in the documentation to illustrate function usage.
14. **Changelog**: Maintain a changelog to document significant changes, enhancements, and bug fixes.
15. **Community Standards**: Adhere to community standards and best practices for R package development.
16. **Sustainability**: Write code that is maintainable and easy to understand for future developers.
17. **Reproducibility**: Ensure that analyses and results can be reproduced by others using the package.


## Project-Specific Context
1. **Dose-Response Models**: Familiarize yourself with common dose-response models (e.g., logistic, probit) and their applications in toxicology.
2. **NOEC Calculations**: Understand the methodologies for calculating No Observed Effect Concentrations (NOEC) and their significance in risk assessment.
3. **Data Formats**: Be aware of common data formats used in dose-response studies and ensure compatibility with the package functions.
4. **Visualization**: Utilize ggplot2 for creating informative and publication-quality visualizations of dose-response data.
5. **User Base**: Consider the needs and expertise of the target user base, which may include researchers with varying levels of statistical knowledge.
6. **Regulatory Standards**: Be aware of relevant regulatory standards and guidelines that may impact the analysis and interpretation of dose-response data.
7. **Interdisciplinary Collaboration**: Recognize that users may come from diverse scientific backgrounds and ensure the package is accessible to a broad audience.
8. **Updates and Maintenance**: Plan for regular updates to the package to incorporate new methodologies, address user feedback, and ensure compatibility with evolving R standards.
9. **Educational Resources**: Consider providing tutorials, vignettes, or other educational resources to help users understand dose-response analysis concepts and effectively utilize the package.


When generating code, answering questions, or reviewing changes, please adhere to these guidelines and context to ensure consistency and quality across the project. Please clean up any temporary file, comments or notes before finalizing the code. Keep the code efficient, readable, and well-documented.
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ S3method(print,tskresult)
S3method(summary,StepDownRSCABS)
S3method(tsk,data.frame)
S3method(tsk,numeric)
S3method(tsk_auto,data.frame)
S3method(tsk_auto,numeric)
export("%>%")
export(ECx_rating)
export(ED.ZG)
Expand Down Expand Up @@ -83,6 +85,7 @@ export(summaryZG)
export(test_overdispersion)
export(treatment2dose)
export(tsk)
export(tsk_auto)
export(williamsTest_JG)
import(dplyr)
import(ggplot2)
Expand Down
108 changes: 108 additions & 0 deletions R/brsr_tsk.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,114 @@
#'
tsk <- function(...) UseMethod("tsk")

#' Auto-trimmed TSK Analysis
#'
#' This function automatically determines the appropriate trim level for TSK analysis
#' and applies it. It first tries with no trimming, and if that fails due to responses
#' not spanning the required range, it automatically calculates and applies the minimum
#' required trim level based on the data characteristics.
#'
#' The automatic trimming is triggered when the response proportions don't increase
#' from the trim level to 1-trim level, which typically occurs when responses are
#' too close to 0% or 100% at the extreme doses.
#'
#' @param x A numeric vector of doses (for numeric method) or a data frame
#' containing columns 'x', 'n', and 'r' (for data.frame method).
#' @param n A numeric vector of total counts (for numeric method only).
#' @param r A numeric vector of response counts (for numeric method only).
#' @param control A numeric value indicating the control dose (default is 0).
#' @param conf.level A numeric value indicating the confidence level (default is 0.95).
#' @param use.log.doses A logical value indicating whether to use log-transformed
#' doses (default is TRUE).
#' @param max.trim A numeric value indicating the maximum allowed trim level
#' (default is 0.45, must be < 0.5).
#' @param ... Additional arguments passed to the tsk function.
#' @return The result of the TSK analysis with automatic trimming applied.
#' @export
#' @examples
#' \dontrun{
#' # With numeric vectors - data that needs trimming
#' doses <- c(0, 1, 2, 3, 4, 5)
#' total <- rep(20, 6)
#' responses <- c(0, 2, 8, 14, 18, 20) # Goes from 0 to 100%
#' result <- tsk_auto(doses, total, responses)
#'
#' # With data frame - moderate responses that may not need trimming
#' data <- data.frame(
#' x = c(0.1, 0.5, 1, 2, 4, 8),
#' n = rep(20, 6),
#' r = c(2, 5, 8, 12, 15, 17)
#' )
#' result <- tsk_auto(data)
#'
#' # Using hamilton dataset (if available)
#' if (exists("hamilton")) {
#' # Try with one of the hamilton datasets
#' result <- tsk_auto(hamilton$dr1a)
#' }
#' }
tsk_auto <- function(x, ...) {
UseMethod("tsk_auto")
}

#' @rdname tsk_auto
#' @method tsk_auto numeric
#' @export
tsk_auto.numeric <- function(x, n, r, control = 0, conf.level = 0.95,
use.log.doses = TRUE, max.trim = 0.45, ...) {
input <- data.frame(x = x, n = n, r = r)
tsk_auto.data.frame(input, control = control, conf.level = conf.level,
use.log.doses = use.log.doses, max.trim = max.trim, ...)
}

#' @rdname tsk_auto
#' @method tsk_auto data.frame
#' @export
tsk_auto.data.frame <- function(x, control = 0, conf.level = 0.95,
use.log.doses = TRUE, max.trim = 0.45, ...) {
input <- x

# Validate max.trim
if (max.trim <= 0 || max.trim >= 0.5) {
stop("max.trim must be between 0 and 0.5 (exclusive).")
}

# First try with no trimming
result <- tryCatch({
tsk(input, control = control, trim = 0, conf.level = conf.level,
use.log.doses = use.log.doses, ...)
}, error = function(e) {
# Only apply auto-trimming for specific trim-related errors
if (grepl("responses do not increase from trim to 1-trim", e$message)) {
# Extract suggested trim from error message
suggested_trim_match <- regmatches(e$message,
regexpr("consider using this trim: [0-9.]+", e$message))

if (length(suggested_trim_match) > 0) {
suggested_trim <- as.numeric(sub("consider using this trim: ", "", suggested_trim_match))

# Apply a small buffer to ensure success, but cap at max.trim
auto_trim <- min(suggested_trim + 0.001, max.trim)

message(paste("Auto-trimming applied: trim =", round(auto_trim, 4)))
message(paste("Reason: Responses don't span the full range from 0 to 1"))

# Try again with calculated trim
tsk(input, control = control, trim = auto_trim, conf.level = conf.level,
use.log.doses = use.log.doses, ...)
} else {
# Re-throw if we can't parse the suggested trim
stop(e)
}
} else {
# Re-throw other errors
stop(e)
}
})

return(result)
}

#' TSK Analysis for Numeric Input
#'
#' This function performs TSK analysis for numeric input.
Expand Down
16 changes: 16 additions & 0 deletions R/data_description.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,22 @@ NULL
"DixonQ"


#' Hamilton dose-response datasets
#'
#' Example dose-response data given in Hamilton (1977).
#' Note that, as per Hamilton (1978), the confidence intervals
#' given in Hamilton (1977) for these data sets are incorrect.
#'
#' @author B R S Recht
#' @docType data
#' @keywords datasets
#' @format A list containing ten data frames: dr1a, dr1b, dr1c,
#' dr1d, dr1e, dr4a, dr4b, dr4c, dr4d, dr4e
#' @source Hamilton, 1977.
#' @references \url{https://github.com/brsr/tsk}
"hamilton"


#' Fake data from collembola juveniles
#'
#' @docType data
Expand Down
Loading
Loading