[R] Sensitivity and Specificity
Michael Dewey
||@t@ @end|ng |rom dewey@myzen@co@uk
Mon Oct 24 17:45:47 CEST 2022
Rather hard to know without seeing what output you expected and what
error message you got if any but did you mean to summarise your variable
predict before doing anything with it?
Michael
On 24/10/2022 16:17, greg holly wrote:
> Hi all R-Help ,
>
> After partitioning my data to testing and training (please see below), I
> need to estimate the Sensitivity and Specificity. I failed. It would be
> appropriate to get your help.
>
> Best regards,
> Greg
>
>
> inTrain <- createDataPartition(y=data$case,
> p=0.7,
> list=FALSE)
> training <- data[ inTrain,]
> testing <- data[-inTrain,]
>
> attach(training)
> #model training and prediction
> data_training <- glm(case ~ age+BMI+Calcium+Albumin+meno_1, data =
> training, family = binomial(link="logit"))
>
> predict <- predict(data_training, data_predict = testing, type = "response")
>
> predict_testing <- ifelse(predict > 0.5,1,0)
>
> # Sensitivity and Specificity
>
> sensitivity<-(predict_testing[2,2]/(predict_testing[2,2]+predict_testing[2,1]))*100
> sensitivity
>
> specificity<-(predict_testing[1,1]/(predict_testing[1,1]+predict_testing[1,2]))*100
> specificity
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>
--
Michael
http://www.dewey.myzen.co.uk/home.html
More information about the R-help
mailing list