Skip to content

Specify foldid in fitSmoothHazard.fit #155

Description

@karinakwan

I'm interested in specifying folds for my data which can be done in cv.glmnet with no issue by passing a vector containing integers from 1 to number of folds to foldid. However, I receive the error seen below when passing the foldid argument to fitSmoothHazard.fit.

library(casebase)
#> See example usage at http://sahirbhatnagar.com/casebase/

data(support)
# Change time to years
support$d.time <- support$d.time/365.25
# Split into test and train
train_index <- sample(nrow(support), 0.95*nrow(support))
test_index <- setdiff(1:nrow(support), train_index)
train <- support[train_index,]
test <- support[test_index,]

# Create matrices for inputs
x <- model.matrix(death ~ . - d.time - aps - sps, 
                  data = train)[, -c(1)] # Remove intercept
y <- data.matrix(subset(train, select = c(d.time, death)))

# Divide into 10 folds 
foldids <- sample(1:10, size = nrow(y), replace = TRUE)

# Regularized logistic regression to estimate hazard
fitSmoothHazard.fit(x, y, family = "glmnet", time = "d.time", event = "death",
                    formula_time = ~ log(d.time),  alpha = 1, ratio = 10, 
                    standardize = TRUE, penalty.factor = c(0, rep(1, ncol(x))),
                    foldid = foldids)
#> Warning in stop(err, call. = FALSE): additional arguments ignored in stop()
#> Error in tapply(weights, foldid, sum): arguments must have same length

Created on 2022-05-20 by the reprex package (v2.0.1)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions