wilcox.test(hrp$TGHDLrate~hrp$type) wilcox.test(hrp$TGGLUrate~hrp$type) wilcox.test(hrp$TnI~hrp$type) wilcox.test(hrp$myoglobin~hrp$type) wilcox.test(hrp$CKMB~hrp$type) wilcox.test(hrp$CK~hrp$type) wilcox.test(hrp$cTnT~hrp$type) wilcox.test(hrp$serumamylase~hrp$type) wilcox.test(hrp$PH~hrp$type) wilcox.test(hrp$PCO2~hrp$type) wilcox.test(hrp$PO2~hrp$type) wilcox.test(hrp$SO2~hrp$type) wilcox.test(hrp$AB~hrp$type) wilcox.test(hrp$SB~hrp$type) wilcox.test(hrp$CO2~hrp$type) wilcox.test(hrp$SBE~hrp$type) wilcox.test(hrp$ABE~hrp$type) wilcox.test(hrp$lacticacid~hrp$type) wilcox.test(hrp$ionizedcalcium~hrp$type) wilcox.test(hrp$bloodglucose~hrp$type) wilcox.test(hrp$glycated.hemoglobin~hrp$type) mytable <- xtabs(~UGLU+type,data = hrp) mytable chisq.test(mytable) fisher.test(mytable) mytable <- xtabs(~urineketone+type,data = hrp) mytable chisq.test(mytable) mytable <- xtabs(~urineprotein+type,data = hrp) mytable chisq.test(mytable) fisher.test(mytable) wilcox.test(hrp$NLR~hrp$type) wilcox.test(hrp$PLR~hrp$type) wilcox.test(hrp$MLR~hrp$type) wilcox.test(hrp$RPR~hrp$type) wilcox.test(hrp$CLR~hrp$type) wilcox.test(hrp$CAR~hrp$type) is.data.frame(hrp) install.packages("glmnet") library(glmnet) hrpcolnames <- colnames(hrp) hrpcolnames str(hrpcolnames) hrpx <- hrpcolnames[15,18,33,35,39:42,44,47,49,54,58,59,61,62,63,66,67,69,71,72,74:76,78,81,83,84,96,97,99,101,102,109,112,114,115,118:125,129,137:139,141,142] hrpx <- hrpcolnames[15,18,33,35,39,40,41,42,44,47,49,54,58,59,61,62,63,66,67,69,71,72,74,75,76,78,81,83,84,96,97,99,101,102,109,112,114,115,118,119,120,121,122,123,124,125,129,137,138,139,141,142] names(hrp) hrpx <- c("diabetes","replase","RBC","hct","RDW","WBC","neutrophilicgranulocyte.percentage", "Lymphocytepercentage","Percentage.of.eosinophils","Lymphocyte","eosinophils","PCT","CRP","PCT2","PT","PTA","INR","TT","Ddimer","Na","Ca","PO4","Mg","HCO3","BUN","UricAcid","cystatinC","AST","LDH","GGT","totalcholesterol","TG","LDL","ApolipoproteinB","ApolipoproteinA1Brate","CKMB","serumamylase","PH","PCO2","AB","SB","CO2","SBE","ABE","lacticacid","ionizedcalcium","bloodglucose","urineprotein","NLR","PLR","MLR","CLR","CAR") hrp.lasso <- glmnet(x=hrpx,y=hrp$type,alpha = 1,family = "binomial",nlambda = 1000) hrpX <- as.matrix(hrp[15,18,33,35,39,40,41,42,44,47,49,54,58,59,61,62,63,66,67,69,71,72,74,75,76,78,81,83,84,96,97,99,101,102,109,112,114,115,118,119,120,121,122,123,124,125,129,137,138,139,141,142]) hrpX <- as.matrix(hrp[,c(15,18,33,35,39,40,41,42,44,47,49,54,58,59,61,62,63,66,67,69,71,72,74,75,76,78,81,83,84,96,97,99,101,102,109,112,114,115,118,119,120,121,122,123,124,125,129,137,138,139,141,142)]) hrpY <- as.matrix(hrp[,136]) hrp.lasso <- glmnet(x=hrpX,y=hrpY,alpha = 1,family = "binomial",nlambda = 1000) ?makeX hrpcomplete <- na.omit(hrp) summary(hrpcomplete) str(hrpcomplete) hrpX1 <- makeX(hrp[,c(15,18,33,35,39,40,41,42,44,47,49,54,58,59,61,62,63,66,67,69,71,72,74,75,76,78,81,83,84,96,97,99,101,102,109,112,114,115,118,119,120,121,122,123,124,125,129,137,138,139,141,142)],na.impute = TRUE) hrp.lasso <- glmnet(x=hrpX1,y=hrpY,alpha = 1,family = "binomial",nlambda = 1000) plot(hrp.lasso) plot(hrp.lasso,xvar = "lambda") print(hrp.lasso) hrp.lasso.coef <- predict(hrp.lasso,s=0.053,type = "coefficients") hrp.lasso.coef hrplasso.y <- predict(hrp.lasso,newx = hrpX1,type = "response",s=0.053) plot(hrplasso.y,hrpY) mytable <- xtabs(~hrplasso.y+hrpY) mytable hrplasso.y hrplogisticfit <- glm(type~Ddimer+Ca+LDH+totalcholesterol+serumamylase+SB+CO2+bloodglucose+urineprotein+CAR,data=hrp,family = binomial()) summary(hrplogisticfit) hrpY str(hrpY) hrpX1Y <- cbind(hrpX1,hrpY) head(hrpX1Y) str(hrpX1Y) hrp2 <- hrp[,c("Ddimer","Ca","LDH","totalcholesterol","serumamylase","SB","CO2","bloodglucose","urineprotein","CAR","type")] str(hrp2) hrp2[is.na(hrp2$Ddimer),hrp2$Ddimer]=median(hrp2$Ddimer,na.rm = TRUE) hrp2$Ddimer[is.na(hrp2$Ddimer)] <- median(hrp2$Ddimer,na.rm = TRUE) hrp2$Ca[is.na(hrp2$Ca)] <- median(hrp2$Ca,na.rm = TRUE) hrp2$LDH[is.na(hrp2$LDH)] <- median(hrp2$LDH,na.rm = TRUE) hrp2$totalcholesterol[is.na(hrp2$totalcholesterol)] <- median(hrp2$totalcholesterol,na.rm = TRUE) hrp2$serumamylase[is.na(hrp2$serumamylase)] <- median(hrp2$serumamylase,na.rm = TRUE) hrp2$SB[is.na(hrp2$SB)] <- median(hrp2$SB,na.rm = TRUE) hrp2$CO2[is.na(hrp2$CO2)] <- median(hrp2$CO2,na.rm = TRUE) hrp2$bloodglucose[is.na(hrp2$bloodglucose)] <- median(hrp2$bloodglucose,na.rm = TRUE) hrp2$urineprotein[is.na(hrp2$bloodglucose)] <- median(hrp2$urineprotein,na.rm = TRUE) hrp2$CAR[is.na(hrp2$CAR)] <- median(hrp2$CAR,na.rm = TRUE) fix(hrp2) summary(hrp2$urineprotein) hrp2$urineprotein[is.na(hrp2$bloodglucose)] <- 0 hrplogisticfit <- glm(type~Ddimer+Ca+LDH+totalcholesterol+serumamylase+SB+CO2+bloodglucose+urineprotein+CAR,data=hrp2,family = binomial()) summary(hrplogisticfit) library(rms) library(foreign) hrplogisticfit2 <- lrm(type~Ddimer+Ca+LDH+totalcholesterol+serumamylase+SB+CO2+bloodglucose+urineprotein+CAR,data=hrp2,x= TRUE,y= TRUE) summary(hrplogisticfit2) hrplogisticfit2 install.packages("ROCR") hrp2$predvalue <- predict(hrplogisticfit2) library(ROCR) pred <- prediction(hrp2$predvalue,hrp2$type) summary(hrp2$urineprotein) fix(hrp2) summary(hrp2$urineprotein) hrp2$urineprotein[is.na(hrp2$urineprotein)] <- 0 summary(hrp2$urineprotein) hrplogisticfit3 <- lrm(type~Ddimer+Ca+LDH+totalcholesterol+serumamylase+SB+CO2+bloodglucose+urineprotein+CAR,data=hrp2,x= TRUE,y= TRUE) hrplogisticfit3 hrp2$predvalue <- predict(hrplogisticfit3) pred <- prediction(hrp2$predvalue,hrp2$type) perf <- performance(pred,"tpr","fpr") plot(perf) auc <- performance(pred,"auc") auc hrpauc <- performance(pred,"auc") hrpauc hrpauc{y.values} summary(hrpX1) summary(hrpx) q() hrplogisticfit4 <- lrm(type~Ddimer+Ca+totalcholesterol+serumamylase,data=hrp2,x= TRUE,y= TRUE) library(rms) hrplogisticfit4 <- lrm(type~Ddimer+Ca+totalcholesterol+serumamylase,data=hrp2,x= TRUE,y= TRUE) hrplogisticfit4 hrplogisticfit5 <- lrm(type~Ddimer+Ca+totalcholesterol,data=hrp2,x= TRUE,y= TRUE) hrplogisticfit5 library(glmnet) set.seed(123) hrp.cv.lasso <- cv.glmnet(x=hrpX1,y=hrpY,alpha=1,family="binomal",nfolds = 10) hrp.cv.lasso <- cv.glmnet(x=hrpX1,y=hrpY,alpha=1,family="binomial",nfolds = 10) hrp.cv.lasso$lambda.1se coef(hrp.cv.lasso,s="lambda.1se") hrplogisticfit6 <- lrm(type~Ddimer+Ca+totalcholesterol+SB+CO2+CAR,data=hrp2,x= TRUE,y= TRUE) hrplogisticfit6 install.packages("caret") install.packages("MASS") library(MASS) library(rms) hrplogautofit <- lrm(type~Ddimer+Ca+totalcholesterol+SB+CO2+CAR,data = hrp2,x=TRUE,y=TRUE) stepAIC(hrplogautofit,direction = "both") hrplogautofit <- glm(type~Ddimer+Ca+totalcholesterol+SB+CO2+CAR,data = hrp2,family = binomial) stepAIC(hrplogautofit,direction = "both") hrplogisticfit7 <- lrm(type~Ddimer+Ca+totalcholesterol+SB,data=hrp2,x= TRUE,y= TRUE) hrplogisticfit7 anova(hrplogisticfit5,hrplogisticfit6,hrplogisticfit7,test = "Chisq") anova(hrplogisticfit5,hrplogisticfit6,test = "Chisq") anova(hrplogisticfit5,hrplogisticfit6,test = "Chisq") ?cv.glmnet ??cv.glmnet summary(hrp$age) sd(hrp$age) summary(hrp) plot(hrp.cv.lasso) plot(hrp.cv.lasso,xvar = "lambda") print(hrp.cv.lasso) plot(hrp.cv.lasso,xvar = "lambda") plot(hrp.cv.lasso$glmnet.fit,xvar = "lambda") library(glmnet) plot(hrp.cv.lasso$glmnet.fit,xvar = "lambda") plot(hrp.cv.lasso) hrplogisticfit5 library(rms) hrplogisticfit5 hrpcalibrate <- calibrate(hrplogisticfit5,method = "boot",B=1000) plot(hrpcalibrate) install.packages("ResourceSelection") library(ResourceSelection) hrplogfit5hltest <- hoslem.test(hrplogisticfit5$y,fitted(hrplogisticfit5),g=10) hrplogisticfit5$y class(hrplogisticfit5$y) hrplogfit5yint <- as.integer(hrplogisticfit5$y) hrplogfit5hltest <- hoslem.test(hrplogfit5yint,fitted(hrplogisticfit5),g=10) hrplogfit5hltest <- hoslem.test(hrplogfit5yint,as.integer(fitted(hrplogisticfit5)),g=10) hrplogfit5yhatint <- as.integer(fitted(hrplogisticfit5)) hrplogfit5yhatint hrplogfit5yhatnum <- as.numeric(fitted(hrplogisticfit5)) hrplogfit5hltest <- hoslem.test(hrplogfit5yint,hrplogfit5yhatnum,g=10) hrplogfit5hltest <- hoslem.test(hrplogfit5yint,hrplogfit5yhatnum) hrplogfit5yhatnum fitted(hrplogisticfit5) hrplogfit5hltest <- hoslem.test(hrplogfit5yint,as.numeric(fitted(hrplogisticfit5))) hrplogfit5hltest <- hoslem.test(hrplogfit5yint,as.numeric(fitted(hrplogisticfit5)),g=4) wilcox.test(hrp$PLR~hrp$type) plot(hrp.cv.lasso) library(glmnet) plot(hrp.cv.lasso) View(hrpX1) plot(hrp.cv.lasso$glmnet.fit,xvar="lambda") coef(hrp.cv.lasso,s="lambda.1se") install.packages("epiDisplay") plot(perf) hrpauc hrp2$predvalue <- predict(hrplogisticfit5) pred <- prediction(hrp2$predvalue,hrp2$type) perf <- performance(pred,"tpr","fpr") plot(perf) abline(0,1) mytable <- xtabs(~sex+type,data = hrp) mytable chisq.test(mytable) mytable <- xtabs(~diabetes+type,data = hrp) mytable chisq.test(mytable) mytable <- xtabs(~replase+type,data = hrp) mytable chisq.test(mytable) aggregate(hrp["hct","PTA"]by=list(type=hrp$type),mean) aggregate(hrp["hct","PTA"],by=list(type=hrp$type),mean) aggregate(na.omit(hrp["hct","PTA"]),by=list(type=hrp$type),mean) ?mean ?aggregate aggregate(hrp["hct","PTA"],by=list(type=hrp$type),mean,na.omit=TRUE) by(hrp["hct","PTA"],hrp$type,mean,na.omit=TRUE) install.packages("doBy") library(doBy) summaryBy(hct+PTA~type,data=hrp,FUN=mean()) summaryBy(hct+PTA~type,data=hrp,FUN=mean) summaryBy(hct+PTA~type,data=hrp,FUN=mean,na.omit=TRUE) sumfun <- function(x){c(mean=mean(x, na.rm=TRUE), sd=sd(x, na.rm=TRUE))} summaryBy(hct+PTA~type,data=hrp,FUN=sumfun) t.test(hrp$hct~hrp$type) t.test(hrp$PTA~hrp$type) wilcox.test(hrp$RBC~hrp$type) library(doBy) summaryBy(RBC~type,data=hrp,FUN=fivenum) summaryBy(RDW~type,data=hrp,FUN=fivenum) wilcox.test(hrp$RDW~hrp$type) summaryBy(WBC~type,data=hrp,FUN=fivenum) wilcox.test(hrp$WBC~hrp$type) summaryBy(neutrophilicgranulocyte percentage~type,data=hrp,FUN=fivenum) summaryBy(hrp$neutrophilicgranulocyte.percentage~type,data=hrp,FUN=fivenum) summaryBy(neutrophilicgranulocyte.percentage~type,data=hrp,FUN=fivenum) wilcox.test(hrp$neutrophilicgranulocyte.percentage~hrp$type) summaryBy(Lymphocytepercentage~type,data=hrp,FUN=fivenum) wilcox.test(hrp$Lymphocytepercentage~hrp$type) summaryBy(Percentage.of.eosinophils~type,data=hrp,FUN=fivenum) wilcox.test(hrp$Percentage.of.eosinophils~hrp$type) summaryBy(Lymphocyte~type,data=hrp,FUN=fivenum) wilcox.test(hrp$Lymphocyte~hrp$type) summaryBy(eosinophils~type,data=hrp,FUN=fivenum) wilcox.test(hrp$eosinophils~hrp$type) summaryBy(PCT~type,data=hrp,FUN=fivenum) wilcox.test(hrp$PCT~hrp$type) summaryBy(CRP~type,data=hrp,FUN=fivenum) wilcox.test(hrp$CRP~hrp$type) summaryBy(PCT2~type,data=hrp,FUN=fivenum) wilcox.test(hrp$PCT2~hrp$type) library(doBy) summaryBy(PT~type,data=hrp,FUN=fivenum) wilcox.test(hrp$PT~hrp$type) summaryBy(INR~type,data=hrp,FUN=fivenum) wilcox.test(hrp$INR~hrp$type) summaryBy(TT~type,data=hrp,FUN=fivenum) wilcox.test(hrp$TT~hrp$type) summaryBy(Ddimer~type,data=hrp,FUN=fivenum) wilcox.test(hrp$Ddimer~hrp$type) summaryBy(Na~type,data=hrp,FUN=fivenum) wilcox.test(hrp$Na~hrp$type) summaryBy(Ca~type,data=hrp,FUN=fivenum) wilcox.test(hrp$Ca~hrp$type) summaryBy(PO4~type,data=hrp,FUN=fivenum) wilcox.test(hrp$PO4~hrp$type) summaryBy(HCO3~type,data=hrp,FUN=fivenum) wilcox.test(hrp$HCO3~hrp$type) summaryBy(hrp$BUN~type,data=hrp,FUN=fivenum) summaryBy(BUN~type,data=hrp,FUN=fivenum) wilcox.test(hrp$BUN~hrp$type) summaryBy(UricAcid~type,data=hrp,FUN=fivenum) wilcox.test(hrp$UricAcid~hrp$type) summaryBy(cystatinC~type,data=hrp,FUN=fivenum) wilcox.test(hrp$cystatinC~hrp$type) wilcox.test(hrp$Scr~hrp$type) library(doBy) summaryBy(AST~type,data=hrp,FUN=fivenum) wilcox.test(hrp$AST~hrp$type) summaryBy(LDH~type,data=hrp,FUN=fivenum) wilcox.test(hrp$LDH~hrp$type) summaryBy(hrp$GGT~type,data=hrp,FUN=fivenum) summaryBy(GGT~type,data=hrp,FUN=fivenum) wilcox.test(hrp$GGT~hrp$type) wilcox.test(hrp$cholinesterase~hrp$type) wilcox.test(hrp$totalcholesterol~hrp$type) wilcox.test(hrp$TG~hrp$type) wilcox.test(hrp$LDL~hrp$type) wilcox.test(hrp$ApolipoproteinB~hrp$type) wilcox.test(hrp$ApolipoproteinA1Brate~hrp$type) wilcox.test(hrp$CKMB~hrp$type) wilcox.test(hrp$serumamylase~hrp$type) wilcox.test(hrp$PH~hrp$type) wilcox.test(hrp$PCO2~hrp$type) wilcox.test(hrp$AB~hrp$type) wilcox.test(hrp$SB~hrp$type) wilcox.test(hrp$CO2~hrp$type) wilcox.test(hrp$SBE~hrp$type) wilcox.test(hrp$ABE~hrp$type) wilcox.test(hrp$lacticacid~hrp$type) wilcox.test(hrp$ionizedcalcium~hrp$type) wilcox.test(hrp$bloodglucose~hrp$type) mytable <- xtabs(~urineprotein+type,data = hrp) mytable chisq.test(mytable) fisher.test(mytable) wilcox.test(hrp$NLR~hrp$type) wilcox.test(hrp$PLR~hrp$type) wilcox.test(hrp$MLR~hrp$type) wilcox.test(hrp$CLR~hrp$type) wilcox.test(hrp$CAR~hrp$type) summaryBy(totalcholesterol~type,data=hrp,FUN=fivenum) summaryBy(TG~type,data=hrp,FUN=fivenum) summaryBy(LDL~type,data=hrp,FUN=fivenum) summaryBy(ApolipoproteinB~type,data=hrp,FUN=fivenum) summaryBy(ApolipoproteinA1Brate~type,data=hrp,FUN=fivenum) summaryBy(CKMB~type,data=hrp,FUN=fivenum) summaryBy(serumamylase~type,data=hrp,FUN=fivenum) summaryBy(PH~type,data=hrp,FUN=fivenum) summaryBy(PCO2~type,data=hrp,FUN=fivenum) summaryBy(AB~type,data=hrp,FUN=fivenum) summaryBy(SB~type,data=hrp,FUN=fivenum) summaryBy(hrp$CO2~type,data=hrp,FUN=fivenum) summaryBy(CO2~type,data=hrp,FUN=fivenum) summaryBy(SBE~type,data=hrp,FUN=fivenum) summaryBy(ABE~type,data=hrp,FUN=fivenum) summaryBy(lacticacid~type,data=hrp,FUN=fivenum) summaryBy(ionizedcalcium~type,data=hrp,FUN=fivenum) summaryBy(bloodglucose~type,data=hrp,FUN=fivenum) summaryBy(NLR~type,data=hrp,FUN=fivenum) summaryBy(PLR~type,data=hrp,FUN=fivenum) summaryBy(MLR~type,data=hrp,FUN=fivenum) summaryBy(CLR~type,data=hrp,FUN=fivenum) summaryBy(CAR~type,data=hrp,FUN=fivenum) library(rms) hrpfitcoef <- coef(hrplogisticfit5) se <- c(1.5088,0.0003,0.6803,0.0326) hrpfit5coefci <- cbind(hrpfitcoef-1.96*se,hrpfitcoef+1.96*se) hrpfit5OR <-exp(cbind("OR"=hrpfitcoef,"LL"=hrpfit5coefci[,1],"UL"=hrpfit5coefci[,2]) hrpfit5OR <-exp(cbind("OR"=hrpfitcoef,"LL"=hrpfit5coefci[,1],"UL"=hrpfit5coefci[,2]) hrpfit5OR <-exp(cbind("OR"=hrpfitcoef,"LL"=hrpfit5coefci[,1],"UL"=hrpfit5coefci[,2])) hrpfit5OR library(dplyr) library(pROC) hrproc <- roc(predvalue~type,data=hrp2) hrp2$predvalue hrproc <- roc(hrp2$type,hrp2$predvalue) auc(hrproc) ci(auc(hrproc)) library(ResourceSelection) hrplogfit5hltest <- hoslem.test(hrplogisticfit5$y,fitted(hrplogisticfit5),g=10) hrplogisticfit5$y hrplogfit5hltest <- hoslem.test(hrplogfit5yint,fitted(hrplogisticfit5),g=10) hrplogfit5yint <- as.integer(hrplogisticfit5$y) hrplogfit5hltest <- hoslem.test(hrplogfit5yint,fitted(hrplogisticfit5),g=10) hrplogfit5hltest <- hoslem.test(hrplogfit5yint,hrplogfit5yhatnum,g=10) hrplogfit5hltest <- hoslem.test(hrplogfit5yint,as.numeric(fitted(hrplogisticfit5))) hrplogfit5hltest <- hoslem.test(hrplogfit5yint,as.numeric(fitted(hrplogisticfit5)),g=4) hoslem.test(hrplogisticfit5$y,fitted(hrplogisticfit5)) hoslem.test(hrplogisticfit5$y,as.numeric(fitted(hrplogisticfit5))) hoslem.test(hrplogisticfit$y,fitted(hrplogisticfit),g=10) hrpglmfit5 <- glm(type~Ddimer+Ca+totalcholesterol,data=hrp2,family = binomial()) library(pROC) hrp2$glmpredvalue <- predict(hrpglmfit5) hrpglmroc <- roc(hrp2$type,hrp2$glmpredvalue) auc(hrpglmroc) hrpfit5OR hoslem.test(hrpglmfit5$y,fitted(hrpglmfit5),g=10)