You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Cox for fixedLassoInf -- "Error in term1[o] <- ff(a[o]) * exp(-(a[o]^2 - z[o]^2)/2) : NAs are not allowed in subscripted assignments" throws despite no NA's in data
#58
Open
violet-nova opened this issue
Nov 15, 2023
· 0 comments
I have verified there is no missing data. The glmnet function runs fine. beta_hat creates a vector of values for every predictor. But when I run fixedLassoInf I get the error. I have tried tweaking arguments like gridrange, tol.beta, tol.kkt and it does not go away.
For this dataset, n = 398, p = 51 (after dummifying factors).
I believe I've faithfully followed the steps recommended for Cox in example documentation. Below is the traceback, and then the code I've been using that creates it.
1 -- fixedLassoInf(x = xsurv, y = coxdf$censor_time,
beta = beta_hat, lambda = coxLasso$lambda.min,
status = status, family = "cox")
My code:
` Make a df that contains: predictors, censor time, and outcome (0 or 1 numeric)
coxdf<- df %>%dplyr::select(any_of(preds), censor_time,
outcome)
[Make X matrix]
xsurv <- coxdf %>%dplyr::select(any_of(preds)) %>%
makeX(na.impute = TRUE) %>% scale(TRUE, FALSE) ## Centering x
[Determine Optimal Lambda from CV]
coxLassocv <- cv.glmnet(x = xsurv,
y = Surv(coxdf$censor_time,
as.numeric(coxdf$outcome)-1
),
family = "cox",
) ## runs without issue
[Originally, I tried going straight from cv.glmnet. When that failed, I built a separate object from glmnet() but it did not fix the issue:]
coxglm <- glmnet(x = xsurv,
y = Surv(coxdf$censor_time,
as.numeric(coxdf$outcome)-1
),
lambda = coxLassocv$lambda.min,
family = "cox"
) ## also runs without issue
[Generate beta_hat as recommended in documentation, this seemingly runs without issue: ]
beta_hat = as.numeric(coef(coxglm,
x=xsurv, y=Surv(coxdf$censor_time,
as.numeric(coxdf$outcome)-1
),
s=coxLassocv$lambda.min/398, ## n = 398 for this dataset.
exact=TRUE
) # the beta values from lasso
) ## Generates a vector of values for all predictors, as expected
status = as.numeric(coxdf$outcome)-1 ## I tried assigning a variable to this rather than calling it directly, it again changed nothing
[The moment of truth, this is where I get the error message:]
out = fixedLassoInf(x=xsurv,
y = coxdf$censor_time,
beta = beta_hat, lambda = coxLassocv$lambda.min,
status= status, family="cox"
) ## At this step, I keep getting: "Error in term1[o] <- ff(a[o]) * exp(-(a[o]^2 - z[o]^2)/2) : NAs are not allowed in subscripted assignments"`
The text was updated successfully, but these errors were encountered:
I have verified there is no missing data. The glmnet function runs fine. beta_hat creates a vector of values for every predictor. But when I run fixedLassoInf I get the error. I have tried tweaking arguments like gridrange, tol.beta, tol.kkt and it does not go away.
For this dataset, n = 398, p = 51 (after dummifying factors).
I believe I've faithfully followed the steps recommended for Cox in example documentation. Below is the traceback, and then the code I've been using that creates it.
Traceback:
limits.info$vup, bits)
griddepth)
griddepth = griddepth, flip = flip, bits = bits)
-1))
tol.beta = tol.beta, tol.kkt = tol.kkt, gridrange = gridrange,
bits = bits, verbose = verbose, this.call = this.call)
beta = beta_hat, lambda = coxLasso$lambda.min,
status = status, family = "cox")
My code:
` Make a df that contains: predictors, censor time, and outcome (0 or 1 numeric)
coxdf<- df %>%dplyr::select(any_of(preds), censor_time,
outcome)
[Make X matrix]
xsurv <- coxdf %>%dplyr::select(any_of(preds)) %>%
makeX(na.impute = TRUE) %>% scale(TRUE, FALSE) ## Centering x
[Determine Optimal Lambda from CV]
coxLassocv <- cv.glmnet(x = xsurv,
y = Surv(coxdf$censor_time,
as.numeric(coxdf$outcome)-1
),
family = "cox",
) ## runs without issue
[Originally, I tried going straight from cv.glmnet. When that failed, I built a separate object from glmnet() but it did not fix the issue:]
coxglm <- glmnet(x = xsurv,
y = Surv(coxdf$censor_time,
as.numeric(coxdf$outcome)-1
),
lambda = coxLassocv$lambda.min,
family = "cox"
) ## also runs without issue
[Generate beta_hat as recommended in documentation, this seemingly runs without issue: ]
beta_hat = as.numeric(coef(coxglm,
x=xsurv, y=Surv(coxdf$censor_time,
as.numeric(coxdf$outcome)-1
),
s=coxLassocv$lambda.min/398, ## n = 398 for this dataset.
exact=TRUE
) # the beta values from lasso
) ## Generates a vector of values for all predictors, as expected
status = as.numeric(coxdf$outcome)-1 ## I tried assigning a variable to this rather than calling it directly, it again changed nothing
[The moment of truth, this is where I get the error message:]
out = fixedLassoInf(x=xsurv,
y = coxdf$censor_time,
beta = beta_hat, lambda = coxLassocv$lambda.min,
status= status, family="cox"
) ## At this step, I keep getting: "Error in term1[o] <- ff(a[o]) * exp(-(a[o]^2 - z[o]^2)/2) : NAs are not allowed in subscripted assignments"`
The text was updated successfully, but these errors were encountered: