2# epoh
谢谢您的建议,我把前面的定义部分也补充一下:
rm(list=ls())
e <- function(x){
e <- exp(sin(8*pi*x)+cos(pi*x))
}
ei <- integrate(e,0,1)$value
f <- function(x){
f <- e(x)/ei
}
#density
N <- 1000;
r1 <- runif(N,0,1);
r2 <- runif(N,0,1);
M <- ceiling(optimize(f,c(0,1),maximum=TRUE)$objective);
sample <- r1[f(r1)>M*r2]
n <- 50 #sample size
sample <- sample[1:n] #rejection sampling
c <- runif(n,0,1);
delta <- rep(1,n);
delta[c<=sample] <- 0; #indicator variate
t <- pmin(sample,c); #independent censoring
subt <- t[1:5]; #sunset of the sample
lambda <- 1; beta <-rep(1,2); d <- rep(1,2); c <- rep(1,length(subt)); #initial value
eta <- c(beta,d,c) #vector containing all the parameters
t是根据密度函数用舍选抽样随机模拟的一个数据集,subt是其一个子集,eta是参数估计的初始值,这里面为了方便调试都进行了一些简化。