Code Monkey home page Code Monkey logo

clinicaltrialutilities.jl-535c2557-d7d0-564d-8ff9-4ae146c18cfe's Introduction

ClinicalTrialUtilities

VERSION 0.2.0 INCOMATIBLE WITH 0.1.x

Clinical trial related calculation: descriptive statistics, power and sample size calculation, power simulations, confidence interval, pharmacokinetics/pharmacodynamics parameters calculation.

Build Status Build status codecov Coverage Status

Description

The package is designed to perform calculations related to the planning and analysis of the results of clinical trials. The package includes the basic functions described below, as well as a few modules to perform specific calculations.

Content

using Pkg; Pkg.add("ClinicalTrialUtilities");

or

using Pkg; Pkg.clone("https://github.com/PharmCat/ClinicalTrialUtilities.jl.git");

And then to perform tests:

Pkg.test("ClinicalTrialUtilities");

NB! Hypothesis types:

  • :ea - Equality: two-sided;
  • :ei - Equivalencens: two one-sided hypothesis;
  • :ns - Non-Inferiority / Superiority: one-sided hypothesis, for some cases you should use two-sided hypothesis for Non-Inferiority/Superiority, you can use alpha/2 for this;

Descriptive statistics.

descriptives(data::DataFrame; sort = NaN, vars = NaN, stats = [:n, :mean, :sd, :sem, :uq, :median, :lq])::DataFrame

Sample size estimation for clinical trial.

ctsamplen(;param=:notdef, type=:notdef, group=:notdef, alpha=0.05, beta=0.2, diff=0, sd=0, a=0, b=0, k=1, logscale=false)

param (Parameter type):

  • :mean - Means;
  • :prop - Proportions;
  • :or - Odd Ratio;

type (Hypothesis type):

  • :ea - Equality;
  • :ei - Equivalencens;
  • :ns - Non-Inferiority / Superiority (!one-sided hypothesis!);
  • :mcnm - McNemar's Equality test;

group (group num):

  • :one - One sample;
  • :two - Two sample, result is for one group, second group size = n * k;

alpha - Alpha (o < α < 1) (default=0.05);

beta - Beta (o < β < 1) (default=0.2); power = 1 - β;

diff - difference/equivalence margin/non-inferiority/superiority margin;

sd - Standard deviation (σ, for Means only);

a - Group A (μ₀/p₀) - Test group;

b - Group B (μ₁/p₁) - Reference group or reference value;

k - Na/Nb (after sample size estimation second group size: Na=k*Nb, only for two sample design) (default=1);

logscale - diff is log transformed for OR:

  • true - diff is already in log-scale, no transformation required (default);
  • false - diff is not in log-scale, will be transformed;

Power estimation for clinical trials.

ctpower(;param=:notdef, type=:notdef, group=:notdef, alpha=0.05, logdiff=false, diff=0, sd=0, a=0, b=0, n=0, k=1)

param (Parameter type):

  • :mean - Means;
  • :prop - Proportions;
  • :or - Odd Ratio;

type (Hypothesis type):

  • :ea - Equality;
  • :ei - Equivalence;
  • :ns - Non-Inferiority / Superiority;
  • :mcnm - McNemar's Equality test;

group (group num):

  • :one - one sample;
  • :two - Two sample;

alpha - Alpha (0 < α < 1) (default=0.05);

n - Subjects number;

diff - difference/equivalence margin/non-inferiority/superiority margin;

sd - Standard deviation (σ, for Means only);

a - Group A (μ₀/p₀) - Test group;

b - Group B (μ₁/p₁) - Reference group or reference value;

k - Na/Nb (after sample size estimation second group size: Na=k*Nb, only for two sample design) (default=1);

logscale - diff is log transformed for OR:

  • true - diff is already in log-scale, no transformation required (default);
  • false - diff is not in log-scale, will be transformed;

Sample size estimation for bioequivalence study (iterative procedure).

besamplen(;alpha=0.05, beta=0.2, theta0=0.95, theta1=0.8, theta2=1.25, cv=0.0, logscale=true, design=:d2x2, method=:owenq)

alpha - Alpha (o < α < 1) (default=0.05);

beta - Beta (o < β < 1) (default=0.2); power = 1 - β;

theta0 - T/R Ratio (default=0.95);

theta1 - Lower Level (default=0.8);

theta2 - Upper level (default=1.25);

cv - coefficient of variation;

logscale - theta1, theta2, theta0: if true - make log transformation (default true);

design - trial design;

  • :parallel
  • :d2x2 (default)
  • :d2x2x4
  • :d2x4x4
  • :d2x3x3
  • :d2x4x2
  • :d3x3
  • :d3x6x3

method - calculating method: Owen's Q Function | NonCentral T | Shifted;

  • :owenq (default)
  • :nct
  • :shifted

Power estimation for bioequivalence trials.

bepower(;alpha=0.05, theta1=0.8, theta2=1.25, theta0=0.95, cv=0.0, n=0, logscale=true, design=:d2x2, method=:owenq)

alpha - Alpha (0 < α < 1) (default=0.05);

theta1 - Lower Level (default=0.8);

theta2 - Upper level (default=1.25);

theta0 - T/R Ratio (default=0.95);

cv - coefficient of variation;

n - subject number;

logscale - theta1, theta2, theta0: if true - make log transformation (default true);

design - trial design;

  • :parallel
  • :d2x2 (default)
  • :d2x2x4
  • :d2x4x4
  • :d2x3x3
  • :d2x4x2
  • :d3x3
  • :d3x6x3

method - calculating method: Owen's Q Function | NonCentral T, Shifted;

  • :owenq (default)
  • :nct
  • :shifted

Take CV from known CI and subject number.

cvfromci(;alpha = 0.05, theta1 = 0.8, theta2 = 1.25, n, design=:d2x2, mso=false, cvms=false)

alpha - Alpha (o < alpha < 1) (default=0.05);

beta - Beta (o < beta < 1) (default=0.2); power = 1 - beta;

theta1 - Lower Level (default=0.8);

theta2 - Upper level (default=1.25);

n - subject n;

design - trial design;

  • :parallel
  • :d2x2 (default)
  • :d2x2x4
  • :d2x4x4
  • :d2x3x3
  • :d2x4x2
  • :d3x3
  • :d3x6x3

mso

Calculate MS only

  • false(default)
  • true

cvms

Calculate CV and MS

  • false(default)
  • true

Get pooled CV from multiple sources.

pooledcv(data::DataFrame; cv=:cv, df=:df, alpha=0.05, returncv=true)::ConfInt

data::DataFrame - Dataframe with CV data

cv::Symbol - CV column in dataframe

df::Symbol - DF column in dataframe

alpha - Alpha for var/cv confidence interval.

returncv - Return CV or var:

  • true - return cv
  • false - return var
  • Confidence interval calculation - Doc

    • oneProp
    • oneMeans
    • twoProp
    • twoMeans
    • cmh
  • Pharmacokinetics calculation - Doc

    • nca
  • Simulations - Doc

    • bepower
    • bepowerSIM
    • ctPropPower
    • ctPropSampleN
    • ctMeansPower
    • ctMeansPowerFS

Confidence intervals

struct ConfInt
    lower::Float64
    upper::Float64
    estimate::Float64
end

Pharmacokinetics noncompartment analysis output

struct NCA
    result::DataFrame
    elimination::DataFrame
    settings::DataFrame
    textout::String
    errorlog::String
    errors::Array
end
#Sample size for one proportion equality
ctsamplen(param=:prop, type=:ea, group=:one, a=0.3, b=0.5)
#Equivalence for two means
ctsamplen(param=:mean, type=:ei, group=:two, diff=0.3, sd=1, a=0.3, b=0.5)
#Odd ratio non-inferiority
ctsamplen(param=:or, type=:ns, diff=-0.1, a=0.3, b=0.5, k=2)
#Odd ratio equality
ctsamplen(param=:or, type=:ea, a=0.3, b=0.5, k=2)

#Power
ctpower(param=:mean, type=:ea, group=:one, a=1.5, b=2, sd=1,n=32, alpha=0.05)

#Bioequivalence sample size
besamplen(alpha=0.05,  theta1=0.8, theta2=1.25, theta0=0.95, cv=0.15, method=:owenq)
besamplen(cv=0.20, method=:nct)
besamplen(cv=0.347, design=:parallel)
besamplen(cv=0.40)
besamplen(cv=0.347, design=:d2x2x4, method=:nct)

#Bioequivalence power for 2x2 design, default method - OwensQ
bepower(alpha=0.05, logscale=true, theta1=0.8, theta2=1.25, theta0=0.95, cv=0.2, n=20, design=:d2x2, method=:owenq)
#Same
bepower(alpha=0.05, cv=0.2, n=20, design=:d2x2)
#Bioequivalence power for cv 14%, 21 subjects, default OwensQ method, logscale false
bepower(alpha=0.1, logscale=false, theta1=-0.1, theta2=0.1, theta0=0, cv=0.14, n=21)
#Bioequivalence power for cv 14%, 21 subjects, shifted method, logscale false
bepower(alpha=0.1, logscale=false, theta1=-0.1, theta2=0.1, theta0=0, cv=0.14, n=21, method=:shifted)
#Simple notations
bepower(cv=0.4, n=35, design=:d2x4x4)
bepower(cv=0.14, n=21)

#CV from CI
cvfromci(;alpha = 0.05, theta1 = 0.9, theta2 = 1.25, n=30, design=:d2x2x4)

#Polled CV
data = DataFrame(cv = Float64[], df = Int[])
push!(data, (0.12, 12))
push!(data, (0.2, 20))
push!(data, (0.25, 30))
pooledcv(data; cv=:cv, df=:df, alpha=0.05, returncv=true)

  • Owen's T function:
owensT(h::Float64,a::Float64)::Float64
  • Owen's Q function (a,b always should be >= 0):
owensQ(nu, t::Float64, delta::Float64, a::Float64, b::Float64)::Float64
  • Distributions
  • StatsBase
  • Statistics
  • QuadGK
  • SpecialFunctions
  • Random
  • Roots
  • DataFrames

Clinical Trial Utilities

Author: Vladimir Arnautov aka PharmCat

Copyright © 2019 Vladimir Arnautov aka PharmCat ([email protected])

OwensQ/PowerTOST functions rewritten from https://github.com/Detlew/PowerTOST by Detlew Labes, Helmut Schuetz, Benjamin Lang

Calculation based on Chow S, Shao J, Wang H. 2008. Sample Size Calculations in Clinical Research. 2nd Ed. Chapman & Hall/CRC Biostatistics Series.

Connor R. J. 1987. Sample size for testing differences in proportions for the paired-sample design. Biometrics 43(1):207-211. page 209.

Phillips KF.Power of the Two One-Sided Tests Procedure in BioequivalenceJ Pharmacokin Biopharm. 1990;18(2):137–44. doi: 10.1007/BF01063556

Diletti D, Hauschke D, Steinijans VW.Sample Size Determination for Bioequivalence Assessment by Means of Confidence IntervalsInt J Clin Pharmacol Ther Toxicol. 1991;29(1):1–8.

Owen, D B (1965) "A Special Case of a Bivariate Non-central t-Distribution" Biometrika Vol. 52, pp.437-446.

FORTRAN code by J. Burkhardt, license GNU LGPL

D.B. Owen "Tables for computing bivariate normal Probabilities" The Annals of Mathematical Statistics, Vol. 27 (4) Dec. 1956, pp. 1075-1090

matlab code by J. Burkhardt license GNU LGPL

If you want to check and get R code - you can find some here: http://powerandsamplesize.com/Calculators/

Some ideas was taken from R project packages:

PropCIs by Ralph Scherer https://cran.r-project.org/web/packages/PropCIs/index.html

pairwiseCI by Frank Schaarschmidt, Daniel Gerhard https://CRAN.R-project.org/package=pairwiseCI

binGroup by Boan Zhang, Christopher Bilder, Brad Biggerstaff, Frank Schaarschmidt Brianna Hitt https://CRAN.R-project.org/package=binGroup

proportion by M.Subbiah, V.Rajeswaran https://CRAN.R-project.org/package=proportion

binom by Sundar Dorai-Raj https://CRAN.R-project.org/package=binom

DescTools https://CRAN.R-project.org/package=DescTools

ORCI by Libo Sun https://CRAN.R-project.org/package=ORCI

metafor by Wolfgang Viechtbauer https://cran.r-project.org/package=metafor

clinicaltrialutilities.jl-535c2557-d7d0-564d-8ff9-4ae146c18cfe's People

Contributors

pharmcat avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.