Skip to content

Instantly share code, notes, and snippets.

@Gedevan-Aleksizde
Last active May 1, 2017 05:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gedevan-Aleksizde/e3a394011fc1e3e18d051c3fff95fbc5 to your computer and use it in GitHub Desktop.
Save Gedevan-Aleksizde/e3a394011fc1e3e18d051c3fff95fbc5 to your computer and use it in GitHub Desktop.
glmnet.mock <- function(formula=y~., family="gaussian", data, ...){
fam.link <- strsplit(family, "\\(|\\)")[[1]]
family <- fam.link[1]
if(length(fam.link) >=2) link <- fam.link[2]
else link <- "identity"
return(glmnet(x=model.matrix(formula, data),
y=get(link)(model.response(model.frame(formula, data))),
family = family,
...)
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment