[f2e496]: / R / summaryText.R

Download this file

226 lines (178 with data), 7.9 kB

  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
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#File which outputs the summary text for the
#predict from parameters part of the package
#In future refactoring away this summary text
#(maybe replacing with a table of output) will
#improve maintainability?
##' @include common.R
NULL
# Creates the text to be output when calling
# summary of an AnalysisResults object
#
# @param object An AnalysisResults object
# @param options DisplayOptions
# @return The summary text
getFromParameterText <-function(object,options){
study <- object@study
daysinyear <- standarddaysinyear()
####### generate summary text about assumptions ######
#### Start date ######
startd <- as.Date( options@StartDate, format="%d/%m/%Y")
date2 <- as.Date(startd+(0:length(t))*daysinyear/12, format="%d/%m/%Y")
date <- format(date2, format="%d/%m/%Y")
date3 <- format(date2, format="%b %Y")
recruit.txt <- ''
if( options@Trecruit ) {
recruit.txt <- paste0( study@N,' patients recruited, ')
if(!is.infinite(study@followup)){
recruit.txt <- paste0(recruit.txt,"and are followed for ",study@followup," ",options@Time,", ")
}
}
ratio.txt <- ''
if( options@Tratio && !isSingleArm(study) ) {
ratio.txt <- paste0('ratio nE/nC=',study@r,', ')
}
acc.txt <- ''
if( options@Tacc) {
if( study@k==1 ) {
acc.txt <- paste0( study@acc.period,' ', options@Time,' accrual (uniform accrual, k=', study@k, ').' )
}
else{
acc.txt <- paste0( study@acc.period, ' ', options@Time, ' accrual (non-uniform accrual, k=', study@k, ').' )
}
}
median.txt <- ''
hr.txt <- ''
if(!isNullLag(study@lag.settings) ){
if( options@Tmedian) {
median.txt <- paste0('Lag time: T=', study@lag.settings@Lag.T, " ", options@Time, ', ', options@Control,
' for [0,T] ', study@lag.settings@ctrlSpec@text,
" ", options@Time,' and for [T,S] ', options@Control," " ,
study@ctrlSpec@text, " ", options@Time, "." )
}
if( options@Thr && !isSingleArm(study) ) {
hr.txt <- paste0('HR([0,T])=', study@lag.settings@L.HazardRatio, ' and HR([T,S])=',
study@HR, ', which gives an average HR=',round( object@av.hr, digits=2 ),'. ')
}
}
else{
if( options@Tmedian) {
median.txt <- paste0( options@Control," ", study@ctrlSpec@text," ", options@Time,' (lambda=',round( object@sfns[[1]]@lambda, digits=2 ),'). ')
if(!isSingleArm(study))
median.txt <- paste0(median.txt, options@Exp,' ', study@ctrlSpec@experimentaltext(study@HR,study@shape),
" ",options@Time,' (lambda=', round( object@sfns[[2]]@lambda, digits=2 ),').')
}
if( options@Thr && !isSingleArm(study)) {
hr.txt <- paste0('HR(', options@Exp, ':', options@Control, ')=', round( study@HR, digits=2 ),', ')
}
}
if(options@Tmedian){
if(object@study@shape!=1)
median.txt <- paste(median.txt," Weibull survival function shape=",object@study@shape,".",sep="")
else{
median.txt <- paste(median.txt," Exponential survival function.",sep="")
}
}
dropout.txt <- ""
if(options@Dropout){
if(!is.infinite(object@study@dropout[[1]]@median)){
dropout.txt <- paste(options@Control,"dropout:",object@study@dropout[[1]]@text,options@Time)
}
if(!isSingleArm(study) && !is.infinite(object@study@dropout[[2]]@median)){
dropout.txt <- paste(dropout.txt,"and",options@Exp ,"dropout:",object@study@dropout[[2]]@text,options@Time,"both arms")
}
if(dropout.txt!=""){
if(object@study@dropout.shape==1){
dropout.txt <- paste(dropout.txt," using exponential dropout rate.")
}
else{
dropout.txt <- paste(dropout.txt," using Weibull dropout with shape=",object@study@dropout.shape,".",sep="")
}
}
}
crithr.txt <- ''
if( options@Tcrithr && !isSingleArm(study)) {
if(isNullLag(study@lag.settings)){
crithr.txt <- paste0('critical HR value=',floor( object@critical.HR*100)/100,', ')
}
else{
crithr.txt <- paste0('For a study with no lag and this HR: critical HR value=',floor( object@critical.HR*100)/100,', ')
}
}
if(isSingleArm(study)){
param.txt <- ''
}else if( study@two.sided ) {
param.txt <- paste0('alpha(2-sided)=', study@alpha*100,'%, power=', round(study@power*100,digits=0),'%,')
}
else{
param.txt <- paste0('alpha(1-sided)=', study@alpha*100,'%, power=', round(study@power*100,digits=0),'%,')
}
line1.txt <- paste0( recruit.txt, ratio.txt, acc.txt )
line3.txt <- paste0( hr.txt, crithr.txt, param.txt )
####### generate text about events required and when reached ######
if( nrow(object@critical.data)>0 ) {
at.txt <- paste( 'expected at time', floor(object@critical.data[1,"time"]*10)/10, options@Time )
at.txt <- paste(at.txt,' (',options@Exp,'/',options@Control,': ', trunc( object@critical.data[1,"events2"] ),'/',
trunc( object@critical.data[1,"events1"]),').',sep="")
}
else {
at.txt <- paste( 'not reached by time ', study@study.duration,".",sep="")
}
if(isSingleArm(study)){
events1.txt <- ''
}
else{
elag.txt <- if(isNullLag(study@lag.settings)) '' else "and using the given lag settings: "
events1.txt <- paste( ceiling( object@critical.events.req ),' events required ',elag.txt,at.txt,sep='')
}
summary1.txt <- paste(line1.txt, median.txt,dropout.txt)
summary2.txt <- paste(line3.txt, events1.txt)
summary3.txt <- GetPredictionText(object,options,study@power,isSingleArm(study))
return( AddLineBreaks( paste(summary1.txt, summary2.txt, summary3.txt ),text.width=options@text.width))
}
# Generates the text for the Analysis results concerning the number of
# events occurring at user chosen time.pred times
#
# @param results A results object
# @param options A DisplayOptions object
# @param study.power The power of the study
# @param isSingleArm Logical, True if study is single arm
# @return The text concerning the number of events occurring at user chosen time.pred times
GetPredictionText <- function(results,options,study.power,isSingleArm){
p.df <- results@predict.data
if(nrow(p.df)==0) return("")
events2.txt <- ""
if(nrow(p.df)>1){
l <- "("
r <- ")"
}
else{
l <- ""
r <- ""
}
output_times <- paste(l,paste(round(p.df$time,digits=1),collapse=", "),r,sep="")
pred_events <- floor( p.df[,"events1"] ) + floor(p.df[,"events2"] )
pred_events <- paste(l,paste(pred_events,collapse=", "),r,sep="")
if("at.risk1" %in% colnames(p.df)){
atrisk.value <- round(options@atRiskConversion*(p.df[,"at.risk1"] +p.df[,"at.risk2"]),digits=2)
atrisk.value <- paste(l,paste(atrisk.value,collapse=", "),r,sep="")
}
else{
atrisk.value <- NA
}
control_events <- paste(l,paste(trunc( p.df[,"events1"] ),collapse=", "),r,sep="")
exp_events <- paste(l,paste(trunc( p.df[,"events2"] ),collapse=", "),r,sep="")
events2.txt <- paste0("At ", output_times,' ',options@Time," the predicted number of events is ",
pred_events)
if(!isSingleArm){
events2.txt <- paste0(events2.txt,' [',options@Exp,'/',options@Control,': ',exp_events,'/',control_events,']')
}
if(options@ShowRec){
recs <- floor(p.df[,"recruit.tot"])
recs <- paste(l,paste(recs,collapse=", "),r,sep="")
events2.txt <- paste0(events2.txt," and the expected number of subjects recruited is ", recs,sep="")
}
if(options@showatRisk && !is.na(atrisk.value)){
events2.txt <- paste0(events2.txt," with a total of ", atrisk.value ," patient ", options@atRiskTime, " at risk",sep="")
}
paste(events2.txt,".",sep="")
}