Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Xavier Gaeta MD PhD

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
128 changes: 128 additions & 0 deletions R/nephro.R
Original file line number Diff line number Diff line change
Expand Up @@ -769,3 +769,131 @@ Schwartz.Bedside <- function(creatinine, ht, age)
} else
stop ("Some variables are not defined")
}

CKiD.U25.cystatin <- function(cystatin, age, sex)
# CKiD U25 calculation for Cystatin C only
# Requires Cystatin C level, age, sex
{
if (!is.null(age) & !is.null(cystatin) & !is.null(sex))
{
cystatin <- as.numeric(cystatin)
age <- as.numeric(age)
sex <- as.numeric(sex) # 0 = male, 1 = female
n <- length(cystatin)

if (length(age) == n)
{
if ( (min(age)<1) | (max(age)>25)) cat("\nWarning: there are age values <1 or >25 years; for those children, eGFR values might be invalid\n")

# Identify missing data and store the index
idx <- c(1:n)[is.na(cystatin)]

# Replace missing data with fake data to avoid problems with formulas
cystatin[is.na(cystatin)] <- 10

coeff <- if(age < 12){
if(sex == 1) 79.9*1.004 ^ (age-12)
else 87.2*1.011 ^ (age-15)
} else if(age < 15) {
if(sex == 1) 79.9*0.974 ^ (age-12)
else 87.2*1.011 ^ (age-15)
} else if (age < 18) {
if(sex == 1) 79.9*0.974 ^ (age-12)
else 87.2*0.960 ^ (age-15)
} else {
if(sex == 1) 77.1
else 68.3
}

eGFR <- coeff / cystatin

# Restore missing data at the indexed positions
eGFR[idx] <- NA

# Output
round(eGFR, 1)

} else
stop ("Different number of observations between variables")
} else
stop ("Some variables are not defined")
}

CKiD.U25.creatinine <- function(creatinine, age, ht, sex)
# CKiD U25 calculation for creatinine only
# Requires creatinine, age, ht (in cm), sex
{
if (!is.null(creatinine) & !is.null(ht) & !is.null(age) & !is.null(sex))
{
creatinine <- as.numeric(creatinine)
ht <- as.numeric(ht)
age <- as.numeric(age)
sex <- as.numeric(sex) # 0 = male, 1 = female
n <- length(creatinine)

if (length(ht) == n)
{
if ( (min(age)<1) | (max(age)>25)) cat("\nWarning: there are age values <1 or >25 years; for those children, eGFR values might be invalid\n")

# Identify missing data and store the index
idx <- c(1:n)[is.na(creatinine) | is.na(ht)]

# Replace missing data with fake data to avoid problems with formulas
creatinine[is.na(creatinine)] <- 10
ht[is.na(ht)] <- 10

coeff <- if(age < 12){
if(sex == 1) 36.1*1.008 ^ (age - 12)
else 39*1.008 ^ (age - 12)
} else if (age < 18) {
if(sex == 1) 36.1*1.023 ^ (age - 12)
else 39*1.045 ^ (age - 12)
} else {
if(sex == 1) 41.4
else 50.8
}

eGFR <- coeff * (ht / 100) / creatinine

# Restore missing data at the indexed positions
eGFR[idx] <- NA

# Output
round(eGFR, 1)

} else
stop ("Different number of observations between variables")
} else
stop ("Some variables are not defined")
}

CKiD.U25.combined <- function(creatinine, cystatin, age, ht, sex, verbose = FALSE)
# CKiD U25 calculation for both creatinine and Cystatin C
# Requires serum Cr, Cystatin C level, age, ht (in cm), sex
{
if (!is.null(creatinine) & !is.null(ht) & !is.null(age) &
!is.null(cystatin) & !is.null(sex))
{
creatinine <- as.numeric(creatinine)
cystatin <- as.numeric(cystatin)
ht <- as.numeric(ht)
age <- as.numeric(age)
sex <- as.numeric(sex) # 0 = male, 1 = female

# Return the average of the two other calculations
eGFRU25.cr <- CKiD.U25.creatinine(creatinine = creatinine, age = age,
ht = ht, sex = sex)
eGFRU25.cys <- CKiD.U25.cystatin(cystatin = cystatin, age = age, sex = sex)
eGFRU25.avg <- (eGFRU25.cys + eGFRU25.cr) / 2

## Determine if we should return all the component parts or just the result
## of the combined calculation
if(verbose) {
return(round(cbind(eGFRU25.cr, eGFRU25.cys, eGFRU25.avg),1))
} else {
return(round(eGFRU25.avg, 1))
}

} else
stop ("Some variables are not defined")
}
61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Nephro with CKiD U25 equations
**Xavier Gaeta MD, PhD**

## Nephro - CKiD U25

This is a fork of the R
[**nephro**](https://cran.r-project.org/web/packages/nephro/index.html "CRAN repository for original nephro package, currently v1.4")
package that’s hosted on CRAN.org which includes functions to calculate
pediatric eGFR based on the following publication:

Pierce CB, Muñoz A, Ng DK, Warady BA, Furth SL, Schwartz GJ. **Age- and
sex-dependent clinical equations to estimate glomerular filtration rates
in children and young adults with chronic kidney disease.** *Kidney
International*. 2021;99(4):948–956.
[doi:10.1016/j.kint.2020.10.047](https://doi.org/10.1016/j.kint.2020.10.047 "Persistent DOI link for Pierce et al. paper")

## Installation

You can install the package from Github

``` r
devtools::install_github("xgaeta/nephro-CKiD")
```

then include the package in your script:

``` r
library(nephro)
```

## Using the functions

These new equations follow the same style as the rest of the package,
including sex as a binary variable with 0 for male and 1 for female.
Height is provided in cm. They currently use US based equations. Outputs
are in mL/min/1.73m<sup>2</sup>.

``` r
CKiD.U25.cystatin(cystatin = 1.2, age = 9.5, sex = 1)
```

[1] 65.9

``` r
CKiD.U25.creatinine(creatinine = 0.8, age = 9.5, sex = 1, ht = 132)
```

[1] 58.4

``` r
CKiD.U25.combined(creatinine = 0.8, cystatin = 1.2, age = 9.5, sex = 1, ht = 132, verbose = TRUE)
```

eGFRU25.cr eGFRU25.cys eGFRU25.avg
[1,] 58.4 65.9 62.2

[Pull requests have been
filed](https://github.com/cran/nephro/pull/1 "Current status of CKiD U25 pull request")
to merge these equations into the main
[**nephro**](https://cran.r-project.org/web/packages/nephro/index.html "CRAN repository for original nephro package, currently v1.4")
package