-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcounting_process.Rd
81 lines (77 loc) · 3.17 KB
/
counting_process.Rd
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
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/counting_process.R
\name{counting_process}
\alias{counting_process}
\title{Process survival data into counting process format}
\usage{
counting_process(x, arm)
}
\arguments{
\item{x}{A data frame with no missing values and contain variables:
\itemize{
\item \code{stratum}: Stratum.
\item \code{treatment}: Treatment group.
\item \code{tte}: Observed time.
\item \code{event}: Binary event indicator, \code{1} represents event,
\code{0} represents censoring.
}}
\item{arm}{Value in the input \code{treatment} column that indicates
treatment group value.}
}
\value{
A data frame grouped by \code{stratum} and sorted within stratum by \code{tte}.
It only includes rows with at least one event in the population, at least one subject
is at risk in both treatment group and control group.
Other variables in this represent the following within each stratum at
each time at which one or more events are observed:
\itemize{
\item \code{event_total}: Total number of events
\item \code{event_trt}: Total number of events at treatment group
\item \code{n_risk_total}: Number of subjects at risk
\item \code{n_risk_trt}: Number of subjects at risk in treatment group
\item \code{s}: Left-continuous Kaplan-Meier survival estimate
\item \code{o_minus_e}: In treatment group, observed number of events minus expected
number of events. The expected number of events is estimated by assuming
no treatment effect with hypergeometric distribution with parameters total
number of events, total number of events at treatment group and number of
events at a time. (Same assumption of log-rank test under the null
hypothesis)
\item \code{var_o_minus_e}: Variance of \code{o_minus_e} under the same assumption.
}
}
\description{
Produces a data frame that is sorted by stratum and time.
Included in this is only the times at which one or more event occurs.
The output dataset contains stratum, TTE (time-to-event),
at risk count, and count of events at the specified TTE
sorted by stratum and TTE.
}
\details{
The function only considered two group situation.
The tie is handled by the Breslow's Method.
The output produced by \code{\link[=counting_process]{counting_process()}} produces a counting process
dataset grouped by stratum and sorted within stratum by increasing times
where events occur. The object is assigned the class "counting_process". It
also has the attribute "ratio", which is the ratio of the events in the
treatment arm compared to the control arm in the input time-to-event data. If
the input data was generated by \code{\link[=sim_pw_surv]{sim_pw_surv()}}, the ratio attribute is
simply obtained from the attribute of the same name from the input object.
Otherwise, the returned ratio is the empirical ratio of treatment to control
events.
}
\examples{
# Example 1
x <- data.frame(
stratum = c(rep(1, 10), rep(2, 6)),
treatment = rep(c(1, 1, 0, 0), 4),
tte = 1:16,
event = rep(c(0, 1), 8)
)
counting_process(x, arm = 1)
# Example 2
x <- sim_pw_surv(n = 400)
y <- cut_data_by_event(x, 150) |> counting_process(arm = "experimental")
# Weighted logrank test (Z-value and 1-sided p-value)
z <- sum(y$o_minus_e) / sqrt(sum(y$var_o_minus_e))
c(z, pnorm(z))
}