# library(testthat) # test_that("fit_Tang", { # ## (5) MLE ------------------------------------------------- # ### Script: two-phase log-likelihood specification adapted from Tang et al. (2015) # ### Get the script here https://github.com/sarahlotspeich/logreg2ph/blob/master/simulations/Tang_twophase_loglik_binaryX.R # source("simulations/Tang_twophase_loglik_binaryX.R") # fit_Tang <- nlm(f = Tang_twophase_loglik, # p = rep(0, 12), # hessian = TRUE, # Val = "V", # Y_unval = "Ystar", # Y="Y", # X_unval = "Xbstar", # X = "Xb", # Z = "Xa", # data = sdat) # # beta_mle <- fit_Tang$estimate[10] # # se_mle <- sqrt(diag(solve(fit_Tang$hessian)))[10] # expect_equal(fit_Tang[["minimum"]], 1538.674) # expect_equal(fit_Tang[["estimate"]], c(-2.51139957917592,5.63410757693054,0.512469544497858,-0.772856730710287,-0.346395116715136,-0.927226152878251,1.97612340433891,0.267507899274363,-0.591360803886471,-0.225679612143369,0.139971425201719,0.0645043160218184)) # expect_equal(fit_Tang[["gradient"]], c(0.000102849621161547,0.00014358894042768,0.000310137693304568,0.000376758180209435,0.000689169610268436,-0.000912450559553689,-0.000429520711391775,-0.00141608325066045,8.77662387210875e-05,-0.000122327037388459,-0.000451564119430258,-0.00122145138448104)) # expect_equal(as.vector(fit_Tang[["hessian"]]), c(24.2001078730825,8.00788821560201,12.7155090012566,11.737188287929,5.38807398696749,0.293971424979967,0.140523344447254,0.0708268999004251,37.5704757970356,18.2061967279514,9.36929609450035,-0.646423359283726,8.00788821560201,5.81068424554231,4.01268132130135,4.8452913568957,2.53373541321883,0.0342950763281074,-0.00710281597673675,0.021667482325913,11.2564447267078,6.23681670209054,4.12814975197913,-0.0760036682145396,12.7155090012566,4.01268132130135,10.3937281892309,8.62121396494521,2.76468199444996,0.462955540570067,0.226669113699914,0.0788986653788189,19.9637042896982,11.4415342977761,4.78969468531537,-1.01640580396642,11.737188287929,4.8452913568957,8.62121396494521,11.737188287955,3.04246441373901,0.157206159201485,-0.0853288399593179,0.0407681000069805,18.4113559953443,13.2846707856545,5.10251538799024,-0.345767148246551,5.38807398696749,2.53373541321883,2.76468199444996,3.04246441373901,5.38807398697946,0.0708268999005824,0.0336551856635659,0.0708496372681267,9.36931883188869,4.64876848127563,9.36929609452115,-0.158161128638325,0.293971424979967,0.0342950763281074,0.462955540570067,0.157206159201485,0.0708268999005824,166.105473908865,80.5010179584373,42.5395455749916,0.775094122218605,1.38209088618199,0.274371814157409,67.4341890771812,0.140523344447254,-0.00710281597673675,0.226669113699914,-0.0853288399593179,0.0336551856635659,80.5010179584373,51.3161261809153,18.4937028658484,0.0966277775051715,0.354593337360607,0.108766656436817,33.5631142804229,0.0708268999004251,0.021667482325913,0.0788986653788189,0.0407681000069805,0.0708496372681267,42.5395455749916,18.4937028658484,42.539522837624,0.274394551524953,0.297472979582446,0.274394551524953,17.6827597897514,37.5704757970356,11.2564447267078,19.9637042896982,18.4113559953443,9.36931883188869,0.775094122218605,0.0966277775051715,0.274394551524953,180.403594640705,90.2989086171345,48.9830881633787,-1.70819021150251,18.2061967279514,6.23681670209054,11.4415342977761,13.2846707856545,4.64876848127563,1.38209088618199,0.354593337360607,0.297472979582446,90.2989086171345,65.1784375804853,24.6077206611571,-3.03734850604112,9.36929609450035,4.12814975197913,4.78969468531537,5.10251538799024,9.36929609452115,0.274371814157409,0.108766656436817,0.274394551524953,48.9830881633787,24.6077206611571,48.9830654260112,-0.61277205531956,-0.646423359283726,-0.0760036682145396,-1.01640580396642,-0.345767148246551,-0.158161128638325,67.4341890771812,33.5631142804229,17.6827597897514,-1.70819021150251,-3.03734850604112,-0.61277205531956,101.40204267372) ) # expect_equal(fit_Tang[["code"]], 1) # expect_equal(fit_Tang[["iterations"]], 60) # })