|
a |
|
b/R/summaryText.R |
|
|
1 |
#File which outputs the summary text for the |
|
|
2 |
#predict from parameters part of the package |
|
|
3 |
#In future refactoring away this summary text |
|
|
4 |
#(maybe replacing with a table of output) will |
|
|
5 |
#improve maintainability? |
|
|
6 |
|
|
|
7 |
##' @include common.R |
|
|
8 |
NULL |
|
|
9 |
|
|
|
10 |
# Creates the text to be output when calling |
|
|
11 |
# summary of an AnalysisResults object |
|
|
12 |
# |
|
|
13 |
# @param object An AnalysisResults object |
|
|
14 |
# @param options DisplayOptions |
|
|
15 |
# @return The summary text |
|
|
16 |
getFromParameterText <-function(object,options){ |
|
|
17 |
study <- object@study |
|
|
18 |
daysinyear <- standarddaysinyear() |
|
|
19 |
####### generate summary text about assumptions ###### |
|
|
20 |
#### Start date ###### |
|
|
21 |
startd <- as.Date( options@StartDate, format="%d/%m/%Y") |
|
|
22 |
date2 <- as.Date(startd+(0:length(t))*daysinyear/12, format="%d/%m/%Y") |
|
|
23 |
date <- format(date2, format="%d/%m/%Y") |
|
|
24 |
date3 <- format(date2, format="%b %Y") |
|
|
25 |
|
|
|
26 |
recruit.txt <- '' |
|
|
27 |
if( options@Trecruit ) { |
|
|
28 |
recruit.txt <- paste0( study@N,' patients recruited, ') |
|
|
29 |
if(!is.infinite(study@followup)){ |
|
|
30 |
recruit.txt <- paste0(recruit.txt,"and are followed for ",study@followup," ",options@Time,", ") |
|
|
31 |
} |
|
|
32 |
} |
|
|
33 |
|
|
|
34 |
ratio.txt <- '' |
|
|
35 |
if( options@Tratio && !isSingleArm(study) ) { |
|
|
36 |
ratio.txt <- paste0('ratio nE/nC=',study@r,', ') |
|
|
37 |
} |
|
|
38 |
|
|
|
39 |
acc.txt <- '' |
|
|
40 |
if( options@Tacc) { |
|
|
41 |
if( study@k==1 ) { |
|
|
42 |
acc.txt <- paste0( study@acc.period,' ', options@Time,' accrual (uniform accrual, k=', study@k, ').' ) |
|
|
43 |
} |
|
|
44 |
else{ |
|
|
45 |
acc.txt <- paste0( study@acc.period, ' ', options@Time, ' accrual (non-uniform accrual, k=', study@k, ').' ) |
|
|
46 |
} |
|
|
47 |
} |
|
|
48 |
|
|
|
49 |
|
|
|
50 |
median.txt <- '' |
|
|
51 |
hr.txt <- '' |
|
|
52 |
|
|
|
53 |
if(!isNullLag(study@lag.settings) ){ |
|
|
54 |
|
|
|
55 |
if( options@Tmedian) { |
|
|
56 |
median.txt <- paste0('Lag time: T=', study@lag.settings@Lag.T, " ", options@Time, ', ', options@Control, |
|
|
57 |
' for [0,T] ', study@lag.settings@ctrlSpec@text, |
|
|
58 |
" ", options@Time,' and for [T,S] ', options@Control," " , |
|
|
59 |
study@ctrlSpec@text, " ", options@Time, "." ) |
|
|
60 |
|
|
|
61 |
|
|
|
62 |
} |
|
|
63 |
|
|
|
64 |
if( options@Thr && !isSingleArm(study) ) { |
|
|
65 |
hr.txt <- paste0('HR([0,T])=', study@lag.settings@L.HazardRatio, ' and HR([T,S])=', |
|
|
66 |
study@HR, ', which gives an average HR=',round( object@av.hr, digits=2 ),'. ') |
|
|
67 |
} |
|
|
68 |
|
|
|
69 |
} |
|
|
70 |
else{ |
|
|
71 |
|
|
|
72 |
if( options@Tmedian) { |
|
|
73 |
median.txt <- paste0( options@Control," ", study@ctrlSpec@text," ", options@Time,' (lambda=',round( object@sfns[[1]]@lambda, digits=2 ),'). ') |
|
|
74 |
if(!isSingleArm(study)) |
|
|
75 |
median.txt <- paste0(median.txt, options@Exp,' ', study@ctrlSpec@experimentaltext(study@HR,study@shape), |
|
|
76 |
" ",options@Time,' (lambda=', round( object@sfns[[2]]@lambda, digits=2 ),').') |
|
|
77 |
} |
|
|
78 |
|
|
|
79 |
if( options@Thr && !isSingleArm(study)) { |
|
|
80 |
hr.txt <- paste0('HR(', options@Exp, ':', options@Control, ')=', round( study@HR, digits=2 ),', ') |
|
|
81 |
} |
|
|
82 |
} |
|
|
83 |
|
|
|
84 |
|
|
|
85 |
if(options@Tmedian){ |
|
|
86 |
if(object@study@shape!=1) |
|
|
87 |
median.txt <- paste(median.txt," Weibull survival function shape=",object@study@shape,".",sep="") |
|
|
88 |
else{ |
|
|
89 |
median.txt <- paste(median.txt," Exponential survival function.",sep="") |
|
|
90 |
} |
|
|
91 |
} |
|
|
92 |
|
|
|
93 |
|
|
|
94 |
dropout.txt <- "" |
|
|
95 |
if(options@Dropout){ |
|
|
96 |
if(!is.infinite(object@study@dropout[[1]]@median)){ |
|
|
97 |
dropout.txt <- paste(options@Control,"dropout:",object@study@dropout[[1]]@text,options@Time) |
|
|
98 |
} |
|
|
99 |
|
|
|
100 |
if(!isSingleArm(study) && !is.infinite(object@study@dropout[[2]]@median)){ |
|
|
101 |
dropout.txt <- paste(dropout.txt,"and",options@Exp ,"dropout:",object@study@dropout[[2]]@text,options@Time,"both arms") |
|
|
102 |
} |
|
|
103 |
|
|
|
104 |
if(dropout.txt!=""){ |
|
|
105 |
if(object@study@dropout.shape==1){ |
|
|
106 |
dropout.txt <- paste(dropout.txt," using exponential dropout rate.") |
|
|
107 |
} |
|
|
108 |
else{ |
|
|
109 |
dropout.txt <- paste(dropout.txt," using Weibull dropout with shape=",object@study@dropout.shape,".",sep="") |
|
|
110 |
} |
|
|
111 |
} |
|
|
112 |
|
|
|
113 |
} |
|
|
114 |
|
|
|
115 |
|
|
|
116 |
crithr.txt <- '' |
|
|
117 |
if( options@Tcrithr && !isSingleArm(study)) { |
|
|
118 |
if(isNullLag(study@lag.settings)){ |
|
|
119 |
crithr.txt <- paste0('critical HR value=',floor( object@critical.HR*100)/100,', ') |
|
|
120 |
} |
|
|
121 |
else{ |
|
|
122 |
crithr.txt <- paste0('For a study with no lag and this HR: critical HR value=',floor( object@critical.HR*100)/100,', ') |
|
|
123 |
} |
|
|
124 |
} |
|
|
125 |
|
|
|
126 |
if(isSingleArm(study)){ |
|
|
127 |
param.txt <- '' |
|
|
128 |
}else if( study@two.sided ) { |
|
|
129 |
param.txt <- paste0('alpha(2-sided)=', study@alpha*100,'%, power=', round(study@power*100,digits=0),'%,') |
|
|
130 |
} |
|
|
131 |
else{ |
|
|
132 |
param.txt <- paste0('alpha(1-sided)=', study@alpha*100,'%, power=', round(study@power*100,digits=0),'%,') |
|
|
133 |
} |
|
|
134 |
|
|
|
135 |
line1.txt <- paste0( recruit.txt, ratio.txt, acc.txt ) |
|
|
136 |
line3.txt <- paste0( hr.txt, crithr.txt, param.txt ) |
|
|
137 |
|
|
|
138 |
####### generate text about events required and when reached ###### |
|
|
139 |
if( nrow(object@critical.data)>0 ) { |
|
|
140 |
at.txt <- paste( 'expected at time', floor(object@critical.data[1,"time"]*10)/10, options@Time ) |
|
|
141 |
at.txt <- paste(at.txt,' (',options@Exp,'/',options@Control,': ', trunc( object@critical.data[1,"events2"] ),'/', |
|
|
142 |
trunc( object@critical.data[1,"events1"]),').',sep="") |
|
|
143 |
} |
|
|
144 |
else { |
|
|
145 |
at.txt <- paste( 'not reached by time ', study@study.duration,".",sep="") |
|
|
146 |
} |
|
|
147 |
|
|
|
148 |
if(isSingleArm(study)){ |
|
|
149 |
events1.txt <- '' |
|
|
150 |
} |
|
|
151 |
else{ |
|
|
152 |
elag.txt <- if(isNullLag(study@lag.settings)) '' else "and using the given lag settings: " |
|
|
153 |
events1.txt <- paste( ceiling( object@critical.events.req ),' events required ',elag.txt,at.txt,sep='') |
|
|
154 |
} |
|
|
155 |
|
|
|
156 |
|
|
|
157 |
summary1.txt <- paste(line1.txt, median.txt,dropout.txt) |
|
|
158 |
summary2.txt <- paste(line3.txt, events1.txt) |
|
|
159 |
summary3.txt <- GetPredictionText(object,options,study@power,isSingleArm(study)) |
|
|
160 |
|
|
|
161 |
return( AddLineBreaks( paste(summary1.txt, summary2.txt, summary3.txt ),text.width=options@text.width)) |
|
|
162 |
} |
|
|
163 |
|
|
|
164 |
|
|
|
165 |
# Generates the text for the Analysis results concerning the number of |
|
|
166 |
# events occurring at user chosen time.pred times |
|
|
167 |
# |
|
|
168 |
# @param results A results object |
|
|
169 |
# @param options A DisplayOptions object |
|
|
170 |
# @param study.power The power of the study |
|
|
171 |
# @param isSingleArm Logical, True if study is single arm |
|
|
172 |
# @return The text concerning the number of events occurring at user chosen time.pred times |
|
|
173 |
GetPredictionText <- function(results,options,study.power,isSingleArm){ |
|
|
174 |
p.df <- results@predict.data |
|
|
175 |
if(nrow(p.df)==0) return("") |
|
|
176 |
|
|
|
177 |
events2.txt <- "" |
|
|
178 |
|
|
|
179 |
if(nrow(p.df)>1){ |
|
|
180 |
l <- "(" |
|
|
181 |
r <- ")" |
|
|
182 |
} |
|
|
183 |
else{ |
|
|
184 |
l <- "" |
|
|
185 |
r <- "" |
|
|
186 |
} |
|
|
187 |
|
|
|
188 |
|
|
|
189 |
output_times <- paste(l,paste(round(p.df$time,digits=1),collapse=", "),r,sep="") |
|
|
190 |
|
|
|
191 |
pred_events <- floor( p.df[,"events1"] ) + floor(p.df[,"events2"] ) |
|
|
192 |
pred_events <- paste(l,paste(pred_events,collapse=", "),r,sep="") |
|
|
193 |
|
|
|
194 |
if("at.risk1" %in% colnames(p.df)){ |
|
|
195 |
atrisk.value <- round(options@atRiskConversion*(p.df[,"at.risk1"] +p.df[,"at.risk2"]),digits=2) |
|
|
196 |
atrisk.value <- paste(l,paste(atrisk.value,collapse=", "),r,sep="") |
|
|
197 |
} |
|
|
198 |
else{ |
|
|
199 |
atrisk.value <- NA |
|
|
200 |
} |
|
|
201 |
|
|
|
202 |
control_events <- paste(l,paste(trunc( p.df[,"events1"] ),collapse=", "),r,sep="") |
|
|
203 |
exp_events <- paste(l,paste(trunc( p.df[,"events2"] ),collapse=", "),r,sep="") |
|
|
204 |
|
|
|
205 |
events2.txt <- paste0("At ", output_times,' ',options@Time," the predicted number of events is ", |
|
|
206 |
pred_events) |
|
|
207 |
|
|
|
208 |
if(!isSingleArm){ |
|
|
209 |
events2.txt <- paste0(events2.txt,' [',options@Exp,'/',options@Control,': ',exp_events,'/',control_events,']') |
|
|
210 |
} |
|
|
211 |
|
|
|
212 |
if(options@ShowRec){ |
|
|
213 |
recs <- floor(p.df[,"recruit.tot"]) |
|
|
214 |
recs <- paste(l,paste(recs,collapse=", "),r,sep="") |
|
|
215 |
events2.txt <- paste0(events2.txt," and the expected number of subjects recruited is ", recs,sep="") |
|
|
216 |
} |
|
|
217 |
|
|
|
218 |
if(options@showatRisk && !is.na(atrisk.value)){ |
|
|
219 |
events2.txt <- paste0(events2.txt," with a total of ", atrisk.value ," patient ", options@atRiskTime, " at risk",sep="") |
|
|
220 |
} |
|
|
221 |
|
|
|
222 |
paste(events2.txt,".",sep="") |
|
|
223 |
|
|
|
224 |
} |
|
|
225 |
|