So predict is a one-dimensional vector of predictions but you are
treating it as a two-dimensional matrix (presumably you think those are
the totals).
Michael
On 24/10/2022 16:50, greg holly wrote:
Hi Michael,
I appreciate your writing. Here are what I have after;
> predict_testing <- ifelse(predict > 0.5,1,0)
>
> head(predict)
1 2 3 5 7 8
0.29006984 0.28370507 0.10761993 0.02204224 0.12873872 0.08127920
>
> # Sensitivity and Specificity
>
>
sensitivity<-(predict_testing[2,2]/(predict_testing[2,2]+predict_testing[2,1]))*100
Error in predict_testing[2, 2] : incorrect number of dimensions
> sensitivity
function (data, ...)
{
UseMethod("sensitivity")
}
<bytecode: 0x000002082a2f01d8>
<environment: namespace:caret>
>
>
specificity<-(predict_testing[1,1]/(predict_testing[1,1]+predict_testing[1,2]))*100
Error in predict_testing[1, 1] : incorrect number of dimensions
> specificity
function (data, ...)
{
UseMethod("specificity")
}
<bytecode: 0x000002082a2fa600>
<environment: namespace:caret>
On Mon, Oct 24, 2022 at 10:45 AM Michael Dewey <li...@dewey.myzen.co.uk
<mailto:li...@dewey.myzen.co.uk>> wrote:
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@r-project.org <mailto:R-help@r-project.org> mailing list
-- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
<https://stat.ethz.ch/mailman/listinfo/r-help>
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
<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
<http://www.dewey.myzen.co.uk/home.html>
<http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient>
Virus-free.www.avg.com
<http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
--
Michael
http://www.dewey.myzen.co.uk/home.html
______________________________________________
R-help@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.