drizopoulos / JM

Joint Models for Longitudinal & Survival Data under Maximum Likelihood
34 stars 7 forks source link

Error in exp(coefs[1]) : non-numeric argument to mathematical function- fail to run CompRisk #32

Closed yiexu closed 2 years ago

yiexu commented 2 years ago

I try to run sample codes from http://jmr.r-forge.r-project.org/Chapter5.html

Section 5.5.1

pbc2.idCR <- crLong(pbc2.id, statusVar = "status", censLevel = "alive", nameStrata = "CR") lmeFit.pbc <- lme(log(serBilir) ~ drug (year + I(year^2)), random = ~ year + I(year^2) | id, data = pbc2) coxFit4.pbc <- coxph(Surv(years, status2) ~ (drug + age) CR + strata(CR),data = pbc2.idCR, x = TRUE) jointFit11.pbc <- jointModel(lmeFit.pbc, coxFit4.pbc, timeVar = "year", method = "spline-PH-aGH", CompRisk = TRUE, interFact = list(value = ~ CR, data = pbc2.idCR))

lme and coxph ran fine but jointModel produced an error as following 'Error in exp(coefs[1]) : non-numeric argument to mathematical function'

environment: macOS Big Sur (version 11.3.1) R version 4.1.2 (2021-11-01) -- "Bird Hippie" Platform: x86_64-apple-darwin17.0 (64-bit) image

Could you please help

Thanks!

drizopoulos commented 2 years ago

Try installing the version from GitHub.

—— Professor of Biostatistics Erasmus Medical Center Rotterdam The Netherlands


Από: yiexu @.> Στάλθηκε: Wednesday, January 19, 2022 5:39:40 AM Προς: drizopoulos/JM @.> Κοιν.: Subscribed @.***> Θέμα: [drizopoulos/JM] Error in exp(coefs[1]) : non-numeric argument to mathematical function- fail to run CompRisk (Issue #32)

Waarschuwing: Deze e-mail is afkomstig van buiten de organisatie. Klik niet op links en open geen bijlagen, tenzij u de afzender herkent en weet dat de inhoud veilig is. Caution: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

I try to run sample codes from http://jmr.r-forge.r-project.org/Chapter5.htmlhttps://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fjmr.r-forge.r-project.org%2FChapter5.html&data=04%7C01%7Cd.rizopoulos%40erasmusmc.nl%7C8e9e6f2a556d4782ed0408d9db05b573%7C526638ba6af34b0fa532a1a511f4ac80%7C0%7C0%7C637781639842573259%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=Hxf54nYUiwKsyO8csrLTZDt3HTYFfMbWJVLYGx4bIOU%3D&reserved=0

Section 5.5.1

pbc2.idCR <- crLong(pbc2.id, statusVar = "status", censLevel = "alive", nameStrata = "CR") lmeFit.pbc <- lme(log(serBilir) ~ drug (year + I(year^2)), random = ~ year + I(year^2) | id, data = pbc2) coxFit4.pbc <- coxph(Surv(years, status2) ~ (drug + age) CR + strata(CR),data = pbc2.idCR, x = TRUE) jointFit11.pbc <- jointModel(lmeFit.pbc, coxFit4.pbc, timeVar = "year", method = "spline-PH-aGH", CompRisk = TRUE, interFact = list(value = ~ CR, data = pbc2.idCR))

lme and coxph ran fine but jointModel produced an error as following 'Error in exp(coefs[1]) : non-numeric argument to mathematical function'

environment: macOS Big Sur (version 11.3.1) R version 4.1.2 (2021-11-01) -- "Bird Hippie" Platform: x86_64-apple-darwin17.0 (64-bit) [image]https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F20018394%2F150064230-b97f7dc8-1b0c-43d6-aa82-084a28437c87.png&data=04%7C01%7Cd.rizopoulos%40erasmusmc.nl%7C8e9e6f2a556d4782ed0408d9db05b573%7C526638ba6af34b0fa532a1a511f4ac80%7C0%7C0%7C637781639842573259%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=W8kY4dcMbEFtaOPzyNn6UnCbo7MODTlDe0Ql48%2B45Ag%3D&reserved=0

Could you please help

Thanks!

— Reply to this email directly, view it on GitHubhttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fdrizopoulos%2FJM%2Fissues%2F32&data=04%7C01%7Cd.rizopoulos%40erasmusmc.nl%7C8e9e6f2a556d4782ed0408d9db05b573%7C526638ba6af34b0fa532a1a511f4ac80%7C0%7C0%7C637781639842583233%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=VioL8GL05rB73VEci45tjjOtE1j9mrQh1IfYGJzImEo%3D&reserved=0, or unsubscribehttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FADE7TTZ64SVEMPO4XII3QXLUWY6AZANCNFSM5MI4W4EA&data=04%7C01%7Cd.rizopoulos%40erasmusmc.nl%7C8e9e6f2a556d4782ed0408d9db05b573%7C526638ba6af34b0fa532a1a511f4ac80%7C0%7C0%7C637781639842593189%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=I42fRS%2F9yNg66OX762%2FVbhxTW%2BmhSp%2FzthypqqvGjtQ%3D&reserved=0. You are receiving this because you are subscribed to this thread.Message ID: @.***>

yiexu commented 2 years ago

I installed JM from github by following codes. Unfortunately, the problem remained. I restarted R and got no luck. image image

Please help. Thanks!

drizopoulos commented 2 years ago

Try JMbayes2

—— Professor of Biostatistics Erasmus Medical Center Rotterdam The Netherlands


Από: yiexu @.> Στάλθηκε: Wednesday, January 19, 2022 6:46:39 PM Προς: drizopoulos/JM @.> Κοιν.: Dimitris Rizopoulos @.>; Comment @.> Θέμα: Re: [drizopoulos/JM] Error in exp(coefs[1]) : non-numeric argument to mathematical function- fail to run CompRisk (Issue #32)

Waarschuwing: Deze e-mail is afkomstig van buiten de organisatie. Klik niet op links en open geen bijlagen, tenzij u de afzender herkent en weet dat de inhoud veilig is. Caution: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

I installed JM from github by following codes. Unfortunately, the problem remained. I restarted R and got no luck. [image]https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F20018394%2F150185668-1bece2e7-f066-4200-8a56-e771b4c02022.png&data=04%7C01%7Cd.rizopoulos%40erasmusmc.nl%7C4f6d7842a56b409767c308d9db73a624%7C526638ba6af34b0fa532a1a511f4ac80%7C0%7C0%7C637782112036009750%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=8a9kUsMlmDvgAW0CDklssgL%2BI%2BVYIemS9R62X89oHOk%3D&reserved=0 [image]https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F20018394%2F150185690-88b3ec4f-3beb-4f09-ba75-66b97fd29e00.png&data=04%7C01%7Cd.rizopoulos%40erasmusmc.nl%7C4f6d7842a56b409767c308d9db73a624%7C526638ba6af34b0fa532a1a511f4ac80%7C0%7C0%7C637782112036009750%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=9Ua53Z%2F7zaj2lI91V33qmoApRQzyVMTCstNgptFMgMc%3D&reserved=0

Please help. Thanks!

— Reply to this email directly, view it on GitHubhttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fdrizopoulos%2FJM%2Fissues%2F32%23issuecomment-1016712588&data=04%7C01%7Cd.rizopoulos%40erasmusmc.nl%7C4f6d7842a56b409767c308d9db73a624%7C526638ba6af34b0fa532a1a511f4ac80%7C0%7C0%7C637782112036009750%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=H2t1DFEW3VxVbvUGiMaRHbci%2F6DLlBbdgwtHTAmp%2Frk%3D&reserved=0, or unsubscribehttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FADE7TT6XUJAHNBBCPPZ5Y43UW32H7ANCNFSM5MI4W4EA&data=04%7C01%7Cd.rizopoulos%40erasmusmc.nl%7C4f6d7842a56b409767c308d9db73a624%7C526638ba6af34b0fa532a1a511f4ac80%7C0%7C0%7C637782112036009750%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=susBCx6xZ9x0w0MXnE2K27PQe4mtWdiglHWyqFnUXUo%3D&reserved=0. You are receiving this because you commented.Message ID: @.***>

yiexu commented 2 years ago

Problem solved. It works fine with R version 4.0.2. Thanks for the great package!

cytnjmu commented 2 years ago

I think it is something related to how you extract the coefficients of the survreg object. Previously, if you fit a model like this "init.fit <- survreg(Surv(Time, d) ~ ., data = SpD.i)" you can use init.fit$coefs get the coeffcients, but now you have to use init.fit$coefficients to get the coefficients. If you revise this in the initial.surv function, the problem will be solved

if (method == "spline-PH-GH" || method == "spline-PH-Laplace") { if (is.null(extra$strata)) { dat <- data.frame(Time = Time, d = d, as.data.frame(WW)) rn <- tapply(row.names(dat), idT, tail, 1) ind <- row.names(dat) %in% rn dat <- dat[ind, ] init.fit <- survreg(Surv(Time, d) ~ ., data = dat) coefs <- init.fit$coef xi <- 1 / init.fit$scale phi <- exp(coefs[1]) logh <- -log(phi xi dat$Time^(xi - 1)) out$gammas.bs <- as.vector(lm.fit(extra$W2[ind, ], logh)$coefficients) } else { dat <- data.frame(Time = Time, d = d) dat <- cbind(dat, as.data.frame(WW)) strata <- extra$strata split.dat <- split(dat, strata) gg <- NULL for (i in seq_along(split.dat)) { ii <- strata == levels(strata)[i] SpD.i <- split.dat[[i]] idT.i <- idT[ii] W2.i <- extra$W2[ii, ] rn <- tapply(row.names(SpD.i), idT.i, tail, 1) ind <- row.names(SpD.i) %in% rn SpD.i <- SpD.i[ind, ] init.fit <- survreg(Surv(Time, d) ~ ., data = SpD.i) coefs <- init.fit$coefficients # change coefs to coefficients xi <- 1 / init.fit$scale phi <- exp(coefs[1]) logh <- -log(phi xi SpD.i$Time^(xi - 1)) gg <- c(gg, as.vector(lm.fit(W2.i[ind, ], logh)$coefficients)) } out$gammas.bs <- gg[!is.na(gg)] } out } }