Skip to content

Instantly share code, notes, and snippets.

View Harshit1694's full-sized avatar

HARSHIT GUPTA Harshit1694

View GitHub Profile
pbinom(7, size=20, prob=0.25)
dbinom(7, size=20, prob=0.25)
#Steady state Matrix
steadyStates(disc_trans)
#Market Share after one month
Current_state<-c(0.55,0.45)
steps<-1
finalState<-Current_state*disc_trans^steps #using power operator
finalState
#Market Share after two month
Current_state<-c(0.55,0.45)
steps<-2
finalState<-Current_state*disc_trans^steps #using power operator
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
#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
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
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)
#Forecast of Arima Model
fts <- forecast(arimats, level = c(95))
autoplot(fts)
#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)