|
a |
|
b/R/results.R |
|
|
1 |
#The exported methods for the results from |
|
|
2 |
#predict from parameters simulations |
|
|
3 |
|
|
|
4 |
#' @include study.R sfn.R eventPrediction_package.R |
|
|
5 |
NULL |
|
|
6 |
|
|
|
7 |
##' Class that contains results from the predict function of the \code{Study} object |
|
|
8 |
##' |
|
|
9 |
##' Three of the slots of this class (grid, critical.data, predict.data) are data frames with |
|
|
10 |
##' the number of events, recruitment details and cumulative time at risk at given time. See the |
|
|
11 |
##' vignette for details of these data frames and the \code{AnalysisResults} class in general. |
|
|
12 |
##' |
|
|
13 |
##' @param critical.HR The critical hazard ratio at the time the critical number of events |
|
|
14 |
##' is expected to occur or NA if single arm trial |
|
|
15 |
##' @param critical.data A data frame with 1 row contain the time, event and recruitment details |
|
|
16 |
##' for the time at which the critical number of events is expected to occur. |
|
|
17 |
##' The data frame has 0 rows if the expected time is > study duration or the trial had a single arm |
|
|
18 |
##' @param critical.events.req the number of events (not rounded) required for the study's |
|
|
19 |
##' requested power and alpha or NA if single arm study |
|
|
20 |
##' @param av.hr The average hazard ratio = the study hazard ratio if no lag, see the |
|
|
21 |
##' vignette for how this is calculated if there is a lag. For single arm studies this is NA. |
|
|
22 |
##' @param grid A data frame with rows contain the time, event and recruitment details |
|
|
23 |
##' at times used to plot the event curves |
|
|
24 |
##' @param predict.data A data frame with rows contain the time, event and recruitment details |
|
|
25 |
##' at times / number of events requested to predicted by the user when calling the predict function. |
|
|
26 |
##' @param study The \code{Study} object used to calculate the results |
|
|
27 |
##' @param list The \code{Sfn} objects containing the survival functions for the results. |
|
|
28 |
##' @export |
|
|
29 |
setClass( "AnalysisResults", |
|
|
30 |
slots= c( critical.HR = "numeric", critical.data="data.frame", |
|
|
31 |
critical.events.req = "numeric", av.hr = "numeric", |
|
|
32 |
grid="data.frame",predict.data="data.frame",study="Study", |
|
|
33 |
sfns="list") ) |
|
|
34 |
|
|
|
35 |
# Constructor for AnalysisResults class |
|
|
36 |
# should not be called by users |
|
|
37 |
# @param ... parameters to be passed to the new("AnalysisResults",...) function |
|
|
38 |
# @return An object of type AnalysisResults |
|
|
39 |
AnalysisResults <- function(...){ |
|
|
40 |
new("AnalysisResults",...) |
|
|
41 |
} |
|
|
42 |
|
|
|
43 |
|
|
|
44 |
##' @name show |
|
|
45 |
##' @rdname show-methods |
|
|
46 |
##' @aliases show,AnalysisResults-method |
|
|
47 |
##' @export |
|
|
48 |
setMethod("show", signature(object="AnalysisResults"), |
|
|
49 |
function(object) { |
|
|
50 |
|
|
|
51 |
show(object@study) |
|
|
52 |
if(!is.na(object@av.hr)){ |
|
|
53 |
cat(paste("Average HR",round(object@av.hr,digits=2),"\n")) |
|
|
54 |
} |
|
|
55 |
|
|
|
56 |
if(nrow(object@predict.data)>0){ |
|
|
57 |
cat("Predicted Values:\n") |
|
|
58 |
print(object@predict.data) |
|
|
59 |
} |
|
|
60 |
if(nrow(object@critical.data)>0){ |
|
|
61 |
cat("Critical Number of Events:\n") |
|
|
62 |
print(object@critical.data) |
|
|
63 |
} |
|
|
64 |
if(!is.na(object@critical.HR)){ |
|
|
65 |
cat(paste("Critical HR",round(object@critical.HR,digits=2),"\n")) |
|
|
66 |
} |
|
|
67 |
|
|
|
68 |
} |
|
|
69 |
) |
|
|
70 |
|
|
|
71 |
|
|
|
72 |
##' @name summary |
|
|
73 |
##' @param options A \code{DisplayOptions} object |
|
|
74 |
##' @rdname summary-methods |
|
|
75 |
##' @aliases summary,AnalysisResults-method |
|
|
76 |
##' @export |
|
|
77 |
setMethod('summary',signature(object="AnalysisResults") , |
|
|
78 |
function(object, options = DisplayOptions()) { |
|
|
79 |
cat(getFromParameterText(object,options)) |
|
|
80 |
} |
|
|
81 |
) |
|
|
82 |
|
|
|
83 |
|
|
|
84 |
##' @name LatexSurvivalFn |
|
|
85 |
##' @rdname LatexSurvivalFn-methods |
|
|
86 |
##' @aliases LatexSurvivalFn,AnalysisResults-method |
|
|
87 |
##' @param decimalplaces The number of decimal places to output for the |
|
|
88 |
##' rate and shape parameters |
|
|
89 |
##' @export |
|
|
90 |
setMethod("LatexSurvivalFn", |
|
|
91 |
signature("AnalysisResults"), |
|
|
92 |
function(results,decimalplaces=3){ |
|
|
93 |
|
|
|
94 |
shape <- c("a","\\alpha") |
|
|
95 |
|
|
|
96 |
if(!isSingleArm(results@study)){ |
|
|
97 |
ans <- "Control Arm:\n" |
|
|
98 |
lambda <- c("\\lambda_{c1}","\\lambda_{c2}") |
|
|
99 |
} |
|
|
100 |
else{ |
|
|
101 |
ans <- '' |
|
|
102 |
lambda <- c("\\lambda_1","\\lambda_2") |
|
|
103 |
} |
|
|
104 |
lambda <- c(lambda,"\\lambda_d") |
|
|
105 |
|
|
|
106 |
|
|
|
107 |
ans <- paste(ans,LatexSurvivalFn(results@sfns[[1]],decimalplaces=decimalplaces,lambda=lambda,shape=shape)) |
|
|
108 |
|
|
|
109 |
if(!isSingleArm(results@study)){ |
|
|
110 |
lambda <- c("\\lambda_{e1}","\\lambda_{e2}","\\lambda_d") |
|
|
111 |
ans <- paste(ans,"Experimental Arm:\n") |
|
|
112 |
ans <- paste(ans,LatexSurvivalFn(results@sfns[[2]],decimalplaces=decimalplaces,lambda=lambda,shape=shape)) |
|
|
113 |
} |
|
|
114 |
|
|
|
115 |
if(results@sfns[[1]]@dropout.lambda!=0){ |
|
|
116 |
ans <- paste(ans,"Dropout rate given by \\( \\lambda_d \\)") |
|
|
117 |
if(results@sfns[[1]]@dropout.shape!=1){ |
|
|
118 |
ans <- paste(ans,"and shape given by \\( \\alpha \\)") |
|
|
119 |
} |
|
|
120 |
ans <- paste(ans,".",sep="") |
|
|
121 |
} |
|
|
122 |
ans |
|
|
123 |
} |
|
|
124 |
) |
|
|
125 |
|
|
|
126 |
|