Skip to content

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

@violet-nova

Description

@violet-nova

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:

  • 8 -- bryc.tnorm.surv(z, mm[oo], sd, a, b)
  • 7 -- tnorm.surv(limits.info$estimate, param, limits.info$sd, limits.info$vlo,
    limits.info$vup, bits)
  • 6 -- fun(grid)
  • 5 -- grid.search(param_grid, pivot, alpha/2, 1 - alpha/2, gridpts,
    griddepth)
  • 4 -- TG.interval.base(limits.info, alpha = alpha, gridrange = gridrange,
    griddepth = griddepth, flip = flip, bits = bits)
  • 3 -- TG.interval(bbar, A1, b1, vj, MM, alpha, flip = (sign_bhat[jj] ==
    -1))
  • 2 -- fixedCoxLassoInf(x, y, status, beta, lambda, alpha = alpha, type = "partial",
    tol.beta = tol.beta, tol.kkt = tol.kkt, gridrange = gridrange,
    bits = bits, verbose = verbose, this.call = this.call)
  • 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"`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions