library(nlme) #functions needed ############################################################################################# #function to determine the number of times less than the change point #t is the time vector #d is the non-censoring indicator #tau is the change point X<-function(t,d,tau){ int<-(t0, t2b, NA) t4b<-na.omit(t3b) t5<-sort(t4b) #the second noncensored survival time low<-t5[2] #second to last non-cenosred survival time up<-t5[length(t5)-2] #number of noncensored observations nu<-sum(d1) alpha_0<-0.0095 alpha_1<--.09 alpha_2<-.485 alpha_3<-.004 alpha_4<-.5 alpha_5<-.6 tau_1<-3 tau_2<-9 tau_3<-15 tau_4<-20 init1<-c(tau_1) init2<-c(tau_1, tau_2) init3<-c(tau_1, tau_2, tau_3) init4<-c(tau_1, tau_2, tau_3, tau_4) l1<-optimize(lik1,interval=c(low,up),maximum=TRUE) l2<-optim(init2, lik2) l3<-optim(init3, lik3) l4<-optim(init4, lik4) #calculating the MLE's #MLE for model with no change points alpha1.0<-nu/sum(t) #MLE's for model with one change point tau1.1<-l1$maximum alpha1.1<-(sum((t=tau1.2))*d1))/sum(pmax((pmin(t,tau2.2)-tau1.2),0)) alpha3.2<-(sum((t>=tau2.2)*d1))/sum(pmax(t-tau2.2,0)) #MLE's for model with three change points tau1.3<-l3$par[1] tau2.3<-l3$par[2] tau3.3<-l3$par[3] alphahat1.3<-(sum((t=tau1.2))*d1))) sd.alpha3<-sqrt(alpha3.2^2/(nu-sum((t=cut.off1, print("reject null and continue to next hypothesis, model has at least one change point", ), print("fail to reject null, stop final model has no change points")) ifelse(w2>=cut.off2, print("reject null and continue to next hypothesis, model has at least two change points"),print("fail to reject null, stop final model has one change point")) ifelse(w3>=cut.off3, print("reject null and continue to next hypothesis, model has at least three change points"),print("fail to reject null, stop final model has two change points")) ifelse(w4>=cut.off4, print("reject null and continue to next hypothesis, model has at least four change points"),print("fail to reject null, stop final model has three change points"))