Monday, August 2, 2021

Ordinal Logistic Regression (OLR) in Neural Network (NN) using R

 library(neuralnet)library("ISLR")#load datadata<- read.csv(file.choose())colnames(data)smp_size <- floor(0.75 * nrow(data))train_ind <- sample(seq_len(nrow(data)), size = smp_size)train <- mtcars[train_ind, ]test <- mtcars[-train_ind, ]#divide training and testing datamean_data...

Sunday, August 1, 2021

Logistic Regression with Confusion Matrix in R

 #Coded by Tawkir Ahmed library(ggplot2) #USed for plotting datalibrary(dplyr) #Used to extract columns in the datalibrary(rms) #Used to extract p-value from logistic modellibrary(aod)library(caret)# logistic modelrail <- read.csv(choose.files())   #trainingtest<- read.csv(choose.files()) ...

Tuesday, July 27, 2021

Scatter plot in R

# install.packages("ggplot2")# install.packages("ggExtra")library(ggplot2)library(ggExtra)dat<- read.csv(file.choose())colnames(dat)# Save the scatter plot in a variablep <- ggplot(dat, aes(x = Speed_2017_to_2019, y =  Volume_2017_to_2019)) +  geom_point(shape=5, color="gray")+ ...

Histogram in R

 # Load datap <- read.csv(file.choose())colnames(p)hist(p$Speed_during, xlab = "Speed in 2020", ylab = "Frequency",      main = "",breaks= 20, xlim= c(0, 120), w=20)hist(p$Volume_during, xlab = "Volume in 2020", ylab = "Frequency", main = "",     breaks= 20,...

Thursday, July 22, 2021

No Parametric Model in R

 require(foreign)  #import data filesrequire(ggplot2)  #plotrequire(MASS)     #for Modern Applied Statistics with Slibrary("mosaic") #Statistics and Mathematics Teaching Utilities# Load datap <- read.csv(file.choose())m<- fitModel(SPEEDING_CRASH  ~               exp(LENGTH             ...

Monday, July 12, 2021

MARS in R

 #MARSlibrary(earth)require(MASS)# fit modelfit <- earth(formula=SPEEDING_CRASH ~               log(AVG_AADT)+LANDUSE_MIX+PAVEMENT_CONDITION+ISLDWIDTH+               P_BOTH_SIDEWALK_ONLY+HIGH_FREQ_TRANSIT+SIGNAL_PER_MILE+               MEDIAN_WIDTH+DAILY_TRANSIT+PAVEMENT_CONDITION+LANE_WIDTH ...

Sunday, April 25, 2021

Multigroup Analysis for SEM

 #R 3.6 version is needed for MGA analysis #More than two option in a variable Mga is not possible#install.packages("devtools") #library(devtools)# install "plspm"#install_github("gastonstat/plspm")# load plspmlibrary(plspm)#require(plspm)dataset <- read.csv(file.choose())#make a modelCO=c(0,0,0,0,0)AT=c(1,0,0,0,0)SN=c(1,0,0,0,0)PBC=c(1,0,0,0,0)PMO=c(0,1,1,1,0)x=rbind(CO,AT,SN,PBC,PMO)colnames(x)=rownames(x)innerplot(x,...

Thursday, April 22, 2021

Principal Component Analysis (PCA)

#install.packages("magrittr")  # for piping %>%#install.packages("ade4")      # PCA computation#install.packages("factoextra")# PCA visualizationlibrary(psych)#library(fmsb)#PCA - principal component analysis#Covid19 data analysismydata<- read.csv(file.choose())summary(mydata)#Define_mydataiables#mydata<-...

Thursday, April 15, 2021

Descriptive statistics in R

 #Tawkir codehubdata<-read.csv(file.choose())  #to input datasummary(data) #to show all data variablesdescribe(data) #to show mean and median for numeric datahead(data)  #to show some column and variable names#Rename one column namecolnames(data)[colnames(data)=="lining"]<- "Living"#Rename...

Wednesday, April 14, 2021

Reliability test in R

 #Calculating_Cronbach's Alphacovid_concern<- alpha(data.frame(all[c("CO2", "CO3", "CO5", "CO7")]))attitude<- alpha(data.frame(all[c("SN3", "PBC1", "PBC2")]))social_norm<- alpha(data.frame(all[c("CO4", "AT7", "SN1", "SN2", "PMO1")]))perc_beh_control<- alpha(data.frame(all[c("AT2", "AT4", "AT5", "AT6")]))perc_mor_obligation<-alpha(data.frame(all[c("CO8", "AT1")...

Tuesday, April 13, 2021

Conditional statement and new variable creation in R

 # Load datap <- read.csv(file.choose())#create new data for trial#create new data for triallw9=ifelse(p$LANE_WIDTH<9, 1,0)lw10=ifelse(p$LANE_WIDTH>=10 & p$LANE_WIDTH<11, 1,0)lw11=ifelse(p$LANE_WIDTH>=11 & p$LANE_WIDTH<12, 1,0)lw12=ifelse(p$LANE_WIDTH>=12 & p$LANE_WIDTH<13, 1,0)lw13=ifelse(p$LANE_WIDTH>=13 & p$LANE_WIDTH<14, 1,0)lw14=ifelse(p$LANE_WIDTH>=14...

Wednesday, March 10, 2021

Multiple chart in R

 par(mfrow=c(3, 3))hist(as.numeric(data_cleaned$Cl.thickness))hist(as.numeric(data_cleaned$Cell.size))hist(as.numeric(data_cleaned$Cell.shape))hist(as.numeric(data_cleaned$Marg.adhesion))hist(as.numeric(data_cleaned$Epith.c.size))hist(as.numeric(data_cleaned$Bare.nuclei))hist(as.numeric(data_c...

Sunday, February 28, 2021

SEM in R

library(psych)all=read.csv(choose.files())#Calculating_Cronbach's Alphacovid_concern<- alpha(data.frame(all[c("CO2", "CO3", "CO5", "CO7")]))attitude<- alpha(data.frame(all[c("SN3", "PBC1", "PBC2")]))social_norm<- alpha(data.frame(all[c("CO4", "AT7", "SN1", "SN2", "PMO1")]))perc_beh_control<-...

Confusion Matrix for Any Model in R

 #Confusion matrix# trainingp<- predict(model, rail)tab<- table(p, rail$OPS)tab1-sum(diag(tab))/sum(tab)#testingp1<- predict(model, test)tab1<- table(p1, test$OPS)tab11-sum(diag(tab1))/sum(tab1)#endlibrary(e1071)#dataconfusionMatrix(rail$OPS, sample(rail$OPS))newPrior <- c(.05, .8,...

Tuesday, February 16, 2021

Sankey Plot

#Tawkir_ahmed_code#Sankey_plot library(networkD3)## create a dataframe with 10 nodesnodes = data.frame("name" = c("Node_0", "Node_1", "Node_2", "Node_3", "Node_4", "Node_5",                              "Node_6", "Node_7",...

Wednesday, January 20, 2021

Correlation Matrix

data= read.csv(file.choose())library(corrplot)library(RColorBrewer)library(psych)data<-cbind(X,Y)corMat = cor(data, method="spearman")cor.plot(corMat,numbers=TRUE,colors=TRUE,tl.col="black", tl.srt=45,         n=51,main=NULL,labels=NULL,         cex...