We need to calculate the sample size for our proposal. The appropriate model to apply is the hazard model (discret), with a fixed effect of time, fixed and same time intervals for all subjects.
Our study focuses on patients with neurological diseases, specifically investigating factors related to time-to-dementia. Due to the costs associated with neurological testing, we will assess all patients in the prospective cohort on a monthly basis, up to 18 months, with assessments every three months (T0, T3, T6, T9, T12, T18). Dementia will be assessed at each visit. The study involves a single event with the same interval for all subjects. In this study there are two covariate: age (x1) and assessment result which is a binary time dependent covariate (x2) (with the same interval as event). In each visit we check the status of assesment result.
Now my questions are:
Question 1. I found the following simulation code to simulate a discrete Hazard model (link=logit). How can I determine the correct functions for the baseline hazard and the effect of variables (steps 6 and 7)? How can I add the random variability you would see in practice? How can model the time varying covariate?
Question 2. It seems that there are similarities between a discrete time proportional hazard model (with fixed intervals and fixed time effect) and grouped proportional hazard data. Do you think the sample size formula proposed in this publication can be used in our study?
- How should we present the data for a discrete time model with a time dependent covariate? For example, if we want to present the record for the second subject (please find the picture) who experienced the event at T6 which presentation is the right ones? Please show me the well structure format for presenting the records of ID=2 (as an example).
time of X1=1 (level of interest in covariate) (filled circle)
Id=2
time event covariate
T0 0 0
T3 0 0
T6 1 1
or
ID=2
time event covariate
T0 0 0
T3 0 0
T6 1 0
Here is the Simulation code (logit function) for the question 1.
### 1. Build some useful functions
# create the logit function, and its inverse (over values of x # from 0–1), the logistic function
logistic <- function(x) { return(1/(1+exp(-1*x))) }
logit <- function(x) { return(log(x/(1-x))) }
### 2. Specify N,the total number of individuals (units) at-risk at T=0
N <- 1000
### 3. Specify T,the maximum value of t in your simulated study.
T <- 20
### 4. Create a data frame called Data starting with the ID variable
ID <- 1:N
Data <- data.frame(ID)
# Create conditioning variables (e.g., two dichotomous vars here, but
# these could be whatever number and kind), and bind these to your
# data set
var1 <- c(rep(0,(N/2)),rep(1,N/2))
var2 <- c(rep(0,(N/4)),rep(1,(N/2)),rep(0,(N/4)))
Data <- cbind(Data,var1,var2)
### 5. Format Data as a person-period structure
expand <- function(x,t) {
data <- x[rep(1:length(x[,1]), each = t), ]
rownames(data) <- NULL
return(data)
}
Data <- expand(Data, T)
Data$period <- rep(1:T,N)
for (t in 1:T) {
varname <- paste("t",t,sep="")
Data[,varname] <- as.integer(0 + Data$period == t)
}
### 6. Prepare effect of time on discrete-time hazard function
# Based on your above model assumptions about how ht relates to time:
## Constant baseline hazard:
conslogit <- logit(0.1) # logit(.1) = -2.1972246 # for a nominal hazard of 0.1
## Baseline hazard as a linear function of time
linearlogit <- logit(logistic(0) + 0.05) # for a linear effect of time on hazard of 0.05 per 1-unit increase in t
### 7. Prepare effects of conditioning variables on ht
var1logit <- logit(logistic(0) + 0.06) # for a nominal effect of var1 of 0.06 increase in hazard:
var2logit <- logit(logistic(0) + 0.04) # for a nominal hazard effect of var2 of 0.04:
8. Simulate your discrete-time survival data
# Example for baseline fully discrete effect of time:
for (t in 1:T) {
Data$hlogit[Data$period==t] <- logistic(discretelogit[t])
}
# Example for conditional logit hazard model with constant effect of time:
# (The [Data$period==t] on the conditioning variables are probably only
# necessary if your conditioning variables are *time varying*: if the values of var1 or var2 were to change over time *within individuals*
Here are the results of a similar study that we want to consider as input for calculating the sample size.
-- assesment result: HR=4
-- Age : HR = 1
-- Event vs X2
X2=1 X2=0
Event=1 : Dementia n=7 n=10
Event=0 : Censor n=4 n=6
Note: X2=1 is the level of interest