Description Usage Arguments Value Author(s) Examples

View source: R/event_prediction.R

This is a function to fit Weibull and log-normal curves to Survival data in life-table form using non-linear regression.

By default it fits both, then picks the best fit based on the lowest (un)weighted residual sum of squares.

Alternatively, just one shape may be fitted, by changing the 'type' argument to either "Weibull" or "Lognormal".
Weighted or unweighted fitting are possible. In general, weighted fitting using the number at risk as the weights seems to work best.

This function is primarily used by event_prediction function, but also useful for general KM curve fitting.

One useful aspect of this is for fitting the 'inverse KM', where drop-outs are events, while events and 'time-outs' are censored.
This allows for finding a suitable parameterisation for the censoring curve.

Primary advantage over likelihood-based methods is ability to use aggregated, rather than patient-level data.
Primary disadvantage is that the covariance matrix is unusable due to strong correlation between the input data points going into the regression.

1 2 3 4 5 6 7 8 9 10 11 |

`KMcurve` |
The dataframe object containing the survival data in lifetable form |

`Survival` |
The column name for the survival function (i.e. the probabilities). Default is "Survival" |

`Time` |
The column name for the times. Default is "Time" |

`type` |
Type of event curve to fit.Default is "Automatic", fitting both Weibull and Log-normal curves. Alternatively accepts "Weibull", "Lognormal" or "Exponential" to force the type. |

`weighting` |
Boolean for whether to use weighting. Default=TRUE as it greatly improves curve fitting. |

`Weights` |
Name of Weights column. Default="Weights". Optional if weighting=FALSE. Recommended to use number at risk or remaining. |

`Weight_power` |
Power to raise the weights to. Useful in large trials to give added weight to later points where numbers may still be high. Default=1 (Use weights as specified) |

`startbeta` |
Starting value for the Weibull beta (shape) parameter to be used in the non-linear regression. Default=1 (exponential). |

`startsigma` |
Starting value for the Lognormal sigma (sd) parameter to be used in the non-linear regression. Default=1. |

Returns a 3-item list providing information needed to define a Curve object:

"Item 1"The type of Curve object fitted.

"Item 2"A list of fitted parameters for the curve type.

"Item 3"A placeholder vector of NAs where the covariance-matrix parameters should be.

"Item 4"A data frame containing the goodness of fit metrics for each curve type.

James Bell

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | ```
recruit <- PieceR(matrix(c(rep(1,12),10,15,25,30,45,60,55,50,65,60,55,30),ncol=2),1)
example_data_short <- simulate_trials(active_ecurve=Weibull(50,0.8),
control_ecurve=Weibull(50,0.8), rcurve=recruit,assess=10,iterations=1,seed=12345,
detailed_output=TRUE)
library(survival)
temp1 <- summary(survfit(Surv(example_data_short[,"Time"],1-example_data_short[,"Censored"])~ 1,
error="greenwood"))
out1 <- cbind(temp1$time,temp1$n.risk,temp1$surv,temp1$std.err)
out1 <- rbind(c(0,out1[1,2],1,0),out1)
colnames(out1) <- c("Time","NAR","Survival","Std.Err")
x1 <- ceiling(max(out1[,"Time"]))
example_lifetable <- out1[findInterval(0:x1,out1[,"Time"]),]
example_lifetable[,"Time"] <- 0:x1
fit_KM(KMcurve=example_lifetable,Survival="Survival",Time="Time",Weights="NAR",type="automatic")
``` |

```
Note: assessment time is shorter than the length of the recruitment period:12. Any attempt to increase the assessment time at a later date will result in missing patients!
$Curvetype
[1] "Weibull"
$Parameters
Alpha Beta
50.5227781 0.7728011
$VCov
Alpha_Var Beta_Var Covariance
NA NA NA
$Fit
Distribution Metric Value
[1,] "Weibull" "Weighted Sum of Squares" "0.0145084438106793"
[2,] "Lognormal" "Weighted Sum of Squares" "0.0230572315319414"
```

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.