My name is Nick. I am trying to call pmatrix.simfs and pmatrix.fs from inside a self-made function. Up untill one week ago, it was working without any issues. After reinstalling the flexsurv package, these 2 functions started giving an error when called from inside my function.
The error I get seems to be from inside pmatrix.simfs
Below I give a simple exapmle that leads to that error:
library("flexsurv")
library("mstate")
data(bosms3)
bosms3$group=c(rbinom(nrow(bosms3),1,0.7))
bosms3$sex=c(rbinom(nrow(bosms3),1,0.5))
tmat <- rbind(c(NA, 1, 2), c(NA, NA, 3), c(NA, NA, NA)) #Provide transition matrix
## List of models
crfpm.list<-vector(3,mode="list")
for (i in 1:3) {
crfpm.list[[i]]<-flexsurvreg(Surv(years,status)~group+sex,subset=(trans==i),
dist="weibull",data=bosms3)
}
### Covariate patterns i am interested in
wh1 <- which(bosms3$group == 1 & bosms3$sex == 1)
pat1 <- bosms3[rep(wh1[1], 3), 9:10]
attr(pat1, "trans") <- tmat
wh2 <- which(bosms3$group == 1 & bosms3$sex == 0)
pat2 <- bosms3[rep(wh2[1], 3), 9:10]
attr(pat2, "trans") <- tmat
fu <- function(model , mat,vartime,ci.json, cl.json, B.json, tcovs, Mjson,covariates_list ) {
nstates=ncol(mat)
for (g in 1:length(covariates_list)) {
pm=list()
for (k in 1:length(vartime)) {
pm[[k]]= pmatrix.simfs(x=model, trans=mat, t = vartime[k],
newdata =covariates_list[[g]], ci = ci.json,
tcovs = tcovs, B = B.json, cl = cl.json, M = Mjson)
}
}
}
fu(model=crfpm.list , mat=tmat,vartime=1,ci.json=TRUE,
cl.json=0.95, B.json=100, tcovs=NULL,
Mjson=100,covariates_list=list(pat1,pat2) )
Hello,
My name is Nick. I am trying to call pmatrix.simfs and pmatrix.fs from inside a self-made function. Up untill one week ago, it was working without any issues. After reinstalling the flexsurv package, these 2 functions started giving an error when called from inside my function.
The error I get seems to be from inside pmatrix.simfs![Issue_pmatrix_error](https://user-images.githubusercontent.com/48327071/81740981-18cc3080-949e-11ea-86b9-cbaf612f1677.PNG)
Below I give a simple exapmle that leads to that error:
I would really appreciate your help!