Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ridge function to preserve factor levels #118

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 8 additions & 5 deletions R/ridge.R
@@ -1,10 +1,13 @@
# $Id: ridge.S 11166 2008-11-24 22:10:34Z therneau $
ridge <- function(..., theta, df=nvar/2, eps=.1, scale=TRUE) {
x <- cbind(...)
nvar <- ncol(x)
xname <- as.character(parse(text=substitute(cbind(...))))[-1]
vars <- apply(x, 2, function(z) var(z[!is.na(z)]))
class(x) <- 'coxph.penalty'

xvars <- cbind(data.frame( list(...) ))
names(xvars) <- as.character(parse(text=substitute(cbind(...))))[-1]
x <- model.matrix(~.,model.frame(~., data=xvars, na.action=na.pass))[,-1]
nvar <- ncol(x)
xname <- colnames(x)
vars <- apply(x, 2, function(z) var(z[!is.na(z)]))
class(x) <- 'coxph.penalty'

if (!missing(theta) && !missing(df))
stop("Only one of df or theta can be specified")
Expand Down