library(survival)
library(frailtypack)
#> Loading required package: boot
#>
#> Attaching package: 'boot'
#> The following object is masked from 'package:survival':
#>
#> aml
#> Loading required package: MASS
#> Loading required package: survC1
#> Loading required package: doBy
#>
#> Attaching package: 'frailtypack'
#> The following object is masked from 'package:survival':
#>
#> cluster
time<-c(33,42,45,0.02,0.47,3,31,58,28,14,58,0.03,59,10,58,47,21,3,3,10,12,13,45,35,26,0.33,0.05,0.83,1,2)
status<-c(0,0,0,1,1,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0)
age<-c(20,20,22,20,18,17,21,20,20,26,29,24,30,32,28,24,20,22,26,24,21,29,29,32,17,32,35,19,25,24)
No.childrn_under5<-c(3,3,2,2,1,1,0,1,1,1,2,2,1,4,0,0,2,2,0,1,1,2,2,3,3,1,1,1,2,0)
source<-c("Piped water","Piped water","Piped water","Piped water","Piped water","well water","well water","Piped water",
"Piped water","Bottled water","Other","Surfaced water", "Piped water","Piped water","Piped water","Piped water",
"Piped water","Piped water","Piped water","Other","Other","Other","Other","Bottled water","Bottled water","Bottled water"
,"well water","well water","well water","Piped water")
hhId<-c(1,1,1,2,2,2,2,3,3,3,4,4,5,5,6,6,6,6,7,7,7,8,8,9,9,10,10,10,11,11)
data<-data.frame(time,status,age,No.childrn_under5,source,hhId)
######### CONVRTING CHARACTOR VARIABLES TO FACTOR VARIABLES
data <- data.frame(data, stringsAsFactors=FALSE)
data<- as.data.frame(unclass(data))
#shared frailty model
shared_frailty<-frailtyPenal(Surv(time,status)~cluster(hhId)+No.childrn_under5+age+source,
n.knots = 10,data=data, kappa=1000, cross.validation = TRUE,hazard = "Splines")
#>
#> Be patient. The program is computing ...
#> Warning in frailtyPenal(Surv(time, status) ~ cluster(hhId) + No.childrn_under5 + : Problem in the loglikelihood computation. The program stopped abnormally. Please verify your dataset.
The program took 0.06 seconds