Unable to attach dataset with mixed modelling code

I have dataset and i want to use my data for the model averaging. I am new to R and I find it difficult to understand how to use my data. what would be the exact failure time for my dataset? i have used 2 for left, 3 for interval and 0 for right. the R code is given in this site (https://zenodo.org/record/3401471#.XcsNOlf7T4a)

My dataset contains following information

`
structure(list(ID = 112:133, Event1 = c(4, NA, 33, NA, 4400, 
NA, 1320, 425, 1320, 33, 2523, 124, 4400, 124, NA, 435, 435, 
1475, 33, 4400, 425, 0.03), Event2 = c(0.3, 4500, 3, 4500, 1320, 
4500, 425, 124, 425, 3, 1320, 33, 1320, 33, 4500, 133, 133, 1320, 
3, 1320, 124, 0), Event.outcome = c(1L, 0L, 1L, 0L, 1L, 0L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 
 censoring = c(3L, 0L, 3L, 0L, 3L, 0L, 3L, 3L, 3L, 3L, 3L, 
 3L, 3L, 3L, 0L, 3L, 3L, 3L, 3L, 3L, 3L, 2L)), class = "data.frame", row.names = c(NA, 
-22L))

library(rmutil)
library(stackedsurv)
library(rstan)
library(loo)
library(rstantools)
set.seed(123)

datasets <- list()
results  <- array(0,dim=c(5,3,200))
# randomly draw failure times from a mixture distribution######################
weib.shape = 1;  weib.scale  = 10
igauss.mean = 7; igauss.scale = 0.25
p1 = 0.7 #probability of being a weibull distribution
N = 10    #number of independent observations
########################################################
#create an simlated dataset 
#
#########################################################
cstudy  <- 1
for (ii in 1:N){
nobs    <- rpois(1,10) #numbe of observations in the study
truncf <- matrix(ii,ncol=3,nrow=nobs)
k <- 1
twshape  = rlnorm(1,weib.shape,0.25)
tigshape = rlnorm(1,igauss.mean,0.25)
cdoses <- sort(rlnorm(10,1,1.4)+0.75) #Random dosing for each

#simulate data                                     
for (jj in 1:nobs){

#two possible failure distributions 
if (runif(1) < p1){
fail <- rweibull(1,twshape  ,weib.scale)
}else{
fail <- rinvgauss(1,tigshape,igauss.scale)
}
###########################################
#determine the type of observed censoring
temp  = which(fail < cdoses)[1]
if (is.na(temp)){ #right censored
out.t = c(max(cdoses),NA)
}else if (temp == 1){ #left censored
out.t = c(min(cdoses),NA)
}else{ #interval censored
out.t = c(cdoses[temp-1],cdoses[temp])
}
###########################################
truncf[k,2:3] = out.t
k <- k + 1
}

if (ii == 1){
sim.data = truncf
}else{
sim.data = rbind(sim.data,truncf)
}
}
data2 = sim.data
ID = data2[,1]
TR = data2[,2:3]
#TR = TR/max(TR,na.rm=TRUE)*100
CENC.MAT = matrix(0,nrow=nrow(TR))

#Create the Censoring matrix for the data
#exact same formulation as 'survival'package
# 0 = right censored
# 1 = exact failure time 
# 2 = left censored
# 3 = interval censored
for (i in 1:nrow(TR)){
 if ( !is.na(TR[i,1]) && !is.na(TR[i,2]))
{
CENC.MAT[i] = 3
 }else{

 if ( !is.na(TR[i,1]) && is.na(TR[i,2]))
 {
CENC.MAT[i] = 2
TR[i,2] = -9999999999;
}else{
CENC.MAT[i] = 0
TR[i,1] = TR[i,2]
TR[i,2] = -9999999999;
}
}
}

`
I am trying to find out entry point where I can attach my dataset and perform the analysis. I would appreciate if someone could please help me in this regard.

In the code you posted, the simulated data are fed into the analysis code at this line

data2 = sim.data

You would want to replace sim.data with your data set. For that to work, your data must have the same structure as sim.data. I suggest you run all of the code before the line I quoted above and check that sim.data looks like your data.

Dear @FJCC, Thanks a lot for your quick reply. Data is similar, I am going to apply this and share the updates with you,

Dear @FJCC, In this code, he is creating a censoring matrix which I have already created in my dataset. But I do not know (a) what is the exact failure time with respect to my dataset?

I cannot say what represents the exact failure time in your data because I do not know what the columns in your data mean. I have also not analyzed the code you posted in detail. If you can explain your data, someone might be able to help you with the exact failure time.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.