[R] Missing data problem and ROC curves
David Winsemius
dwinsemius at comcast.net
Mon Jul 1 20:56:33 CEST 2013
On Jul 1, 2013, at 10:57 AM, tfj24 wrote:
> Hello all,
>
> Trying to get this piece of code to work on my data set. It is from
> http://www.itc.nl/personal/rossiter.
>
> logit.roc <- function(model, steps=100)
> {
> field.name <- attr(attr(terms(formula(model)), "factors"),
> "dimnames")[[1]][1]
> eval(parse(text=paste("tmp <- ", ifelse(class(model$data) == "data.frame",
> "model$data$", ""), field.name, sep="")))
> r <- data.frame(pts = seq(0, 1-(1/steps), by=1/steps), sens = 0, spec=0);
> for (i in 0:steps)
> {
> thresh <- i/steps;
> r$sens[i] <- sum((fitted(model) >= thresh) & tmp)/sum(tmp);
> r$spec[i] <- sum((fitted(model) < thresh) & !tmp)/sum(!tmp)
> }
> return(r)}
>
> where model is the output of a glm.
>
> The problem is the "sum((fitted(model) >= thresh) & tmp)" bit. The lengths
> of fitted(model) and tmp are not equal because some of the cases were
> deleted from the model due to missing data! fitted(model) is a set of named
> numbers while tmp is a set of integers.
>
> My question is:
> - How do I determine which cases were deleted from the model and then delete
> the associated cases from tmp?
>
?glm
model$na.action
--
David.
> I hope this makes sense and would really appreciate any help that people may
> have.
>
> Thanks,
> Tim
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Missing-data-problem-and-ROC-curves-tp4670661.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
David Winsemius
Alameda, CA, USA
More information about the R-help
mailing list