-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
94 lines (77 loc) · 2.94 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# package: nphPower
<!-- badges: start -->
<!-- badges: end -->
Package: nphPower provides functions to perform combination test including maximum weighted logrank test (MWLR) and projection test, to calculate sample size with MWLR in a simulation-free approach allowing for staggered entry, drop-out etc, to visualize the design parameters and to simulate survival data with flexible design input.
## Installation
You can install the released version of nphPower from [CRAN](https://CRAN.R-project.org) with:
```
install.packages("nphPower")
```
``` {r}
library("nphPower")
```
And the development version from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
#devtools::install_github("hcheng99/nphPower")
```
## Example 1 - perform maximum weighted logrank test
This is a basic example which shows you how to perform maximum weighted logrank test.
Load the lung data and only keep columns for analysis.
```{r}
lung <- nphPower::lung
tmpd <- with(lung, data.frame(time = SurvTime, stat = 1-censor, grp = Treatment))
```
Generate the weight functions for maxcombo test
```{r}
wmax <- gen.wgt(method = "Maxcombo")
```
Perform the test using pooled Kaplan-Meier estimate of CDF as base function and visualize the weight functions
```{r, fig.width=4, fig.width=5}
t1 <- MaxLRtest(tmpd, Wlist = wmax, base = c("KM"),
alternative = c("two.sided"))
plot(t1)
```
## Example 2 - sample size under proportional hazard
The design setting is: 5 years' entry time and 5 years' follow-up time;
Median survival for control group is 10 years. The hazard ratio comparing treatment and control is 0.5.
```{r}
t_enrl <- 5; t_fup <- 5 ; lmd0 <- -log(0.2)/10 ; HR <- 0.5
eg1 <- pwr2n.LR(method = "schoenfeld", lambda0 = lmd0,
lambda1 = lmd0*HR, entry = t_enrl, fup = t_fup)
```
## Example 3 - sample size under nonproportional hazard
Design setting: patients are enrolled within 12 months and the
last enrolled patient has at least 18 months' follow-up. The
medial survival time for control group is 12 months. The treatment
has delayed effects. The hazard ratio is 0.75 after 6 months.
Maxcombo test is used.
```{r}
t_enrl <- 12; t_fup <- 18; lmd0 <- log(2)/12
f_hr_delay <- function(x){(x<=6)+(x>6)*0.75}
f_haz0 <- function(x){lmd0*x^0}
snph1 <- pwr2n.NPH(entry = t_enrl, fup = t_fup, Wlist = wmax,
k = 50, ratio = 2, CtrlHaz = f_haz0, hazR = f_hr_delay)
```
## Example 4 - trial data simulation
A time-to-event data set with settings in example 3 is simulated.
```{r}
N <- round(snph1$totalN, digits = 0)
set.seed(12345)
simu1 <- simu.trial(type = "time", trial_param = c(N,t_enrl,
t_fup), bsl_dist = "weibull", bsl_param = c(1,lmd0),
HR_fun = f_hr_delay, ratio = 1)
```
More functions can be found in the package.