I am running my code in a loop and it does not work but when I run it
outside the loop I get the values I want.

n <- 1000; # Sample size

fitglm <- function(sigma,tau){
    x <- rnorm(n,0,sigma)
    intercept <- 0
    beta <- 0
    ystar <- intercept+beta*x
    z <- rbinom(n,1,plogis(ystar))
    xerr <- x + rnorm(n,0,tau)
    model<-glm(z ~ xerr, family=binomial(logit))
    int<-coef(model)[1]
    slope<-coef(model)[2]
    pred<-predict(model)

    result<-ifelse(pred>.5,1,0)

    accuracy<-length(which(result==z))/length(z)
    accuracy

    rocpreds<-prediction(result,z)
    auc<-performance(rocpreds,"auc")@y.values
    sentiv<-performance(rocpreds,"sens")@y.values
    sentiv<-slot(fp,"y.values")[[1]]
    sentiv<-sentiv[2]
    sentiv
    specs<-performance(rocpreds,"spec")@y.values
    specs<-slot(fp2,"y.values")[[1]]
    specs<-specs[2]
    specs
    output<-c(int,slope,.5,accuracy,auc,sentiv,specs)

names(output)<-c("Intercept","Slope","CutPoint","Accuracy","AUC","Sentivity",Specificity")
    return(output)

}

y<-fitglm(.05,1)
y


The code runs without the sentiv and specs but when I remove the loop i can
get the sensitivity and spec. values ???

	[[alternative HTML version deleted]]

