rows <- 200
columns <- 2
t_beta <- c(0.5, 2)
t_sigma <- 1
t_lambda <- 1
set.seed(8142031)
x1 <- rbinom(rows, 1, 0.5)
x2 <- runif(rows, 0, 1)
X <- cbind(x1,x2)
s <- t_sigma^2
a <- 1/s
t_ini1 <- exp(X %*% t_beta) * rweibull(rows, scale = s, shape = a)
cens.time <- rweibull(rows, 0.75, 20)
delta <- ifelse(t_ini1 > cens.time, 1, 0)
obst1 = t_ini1
obst1[delta==1] <- cens.time[delta==1]
example <- data.frame(obst1,delta,X)
lambda <- shape(Surv(log(obst1),delta) ~ x1 + x2 - 1, data=example)
lambda
# To obtain even better estimates we can change the interval and/or step options
shape(Surv(log(obst1),delta) ~ x1 + x2 - 1, data=example, interval=c(0.945,0.97), step=0.001)
Run the code above in your browser using DataLab