setwd("C:/Users/giuli/Downloads/STATISTICA_PER_LA_RICERCA_GZ") #Caricamento della library readxl library(readxl) #Lettura del dataset df<-read_xlsx("CK.xlsx") #Generazione di CK dicotomizzato sul cut-off di 100 df$CK_100<-as.factor(ifelse(df$CREATINCHINASI>=100,1,0)) # Crea la matrice di confusione: conf_mat <- table(Patologia = df$PATOLOGIA, Ris_test = df$CK_100) conf_mat # Estrarre i valori VP <- conf_mat["infarto", "1"] FN <- conf_mat["infarto", "0"] FP <- conf_mat["angina", "1"] VN <- conf_mat["angina", "0"] Total <- sum(conf_mat) # Calcoli sens <- VP / (VP + FN) spec <- VN / (VN + FP) acc <- (VP + VN) / Total PPV <- VP / (VP + FP) NPV <- VN / (VN + FN) # Stampa i risultati results <- data.frame( Metric = c("Sensitivity", "Specificity", "Accuracy", "PPV", "NPV"), Value = c(sens, spec, acc, PPV, NPV) ) print(results) #################Cosa succede se uso cut-off di 80? #Generazione di CK dicotomizzato sul cut-off di 80 df$CK_80<-as.factor(ifelse(df$CREATINCHINASI>=80,1,0)) # Crea la matrice di confusione: conf_mat <- table(Patologia = df$PATOLOGIA, Ris_test = df$CK_80) conf_mat # Estrarre i valori VP <- conf_mat["infarto", "1"] FN <- conf_mat["infarto", "0"] FP <- conf_mat["angina", "1"] VN <- conf_mat["angina", "0"] Total <- sum(conf_mat) # Calcoli sens <- VP / (VP + FN) spec <- VN / (VN + FP) acc <- (VP + VN) / Total PPV <- VP / (VP + FP) NPV <- VN / (VN + FN) # Stampa i risultati results <- data.frame( Metric = c("Sensitivity", "Specificity", "Accuracy", "PPV", "NPV"), Value = c(sens, spec, acc, PPV, NPV) ) print(results)