This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pbinom(7, size=20, prob=0.25) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dbinom(7, size=20, prob=0.25) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Steady state Matrix | |
steadyStates(disc_trans) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
install.packages("markovchain") | |
install.packages("diagram") | |
library(markovchain) | |
library(diagram) | |
# Creating a transition matrix | |
trans_mat <- matrix(c(0.7,0.3,0.1,0.9),nrow = 2, byrow = TRUE) | |
trans_mat | |
# create the Discrete Time Markov Chain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Bayes Theorem | |
cancer <- sample(c('No','Yes'), size=1000, replace=TRUE, prob=c(0.99852,0.00148)) | |
test <- rep(NA, 1000) # creating a dummy variable | |
test[cancer=='No'] <- sample(c('Negative','Positive'), size=sum(cancer=='No'), replace=TRUE, prob=c(0.99,0.01)) | |
test[cancer=='Yes'] <- sample(c('Negative','Positive'), size=sum(cancer=='Yes'), replace=TRUE, prob=c(0.07, 0.93)) | |
P_cancer_and_pos<-0.00148*0.93 | |
P_no_cancer_and_pos<-0.99852*0.01 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
P_Accident_who_follow_Traffic_Rule<-50 | |
P_who_follow_Traffic_Rule=50+2000 | |
Conditional_Probability=(P_Accident_who_follow_Traffic_Rule/P_who_follow_Traffic_Rule) | |
Conditional_Probability |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
install.packages("lpSolve") | |
library(lpSolve) | |
#Setting the coefficients of decision variables | |
objective.in=c(25,20) | |
#Constraint Matrix | |
const.mat=matrix(c(20,12,5,5),nrow = 2,byrow = T) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Forecast of Arima Model | |
fts <- forecast(arimats, level = c(95)) | |
autoplot(fts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Fitting the model | |
#Linear model | |
autoplot(tsdata) + geom_smooth(method="lm")+ labs(x ="Date", y = "Passenger numbers (1000's)", title="Air Passengers data") | |
#ARIMA Model | |
arimats <- auto.arima(tsdata) | |
arimats | |
ggtsdiag(arimats) |