R
R
R
barplot(tseries)
install.packages("forecast")
install.pacakages("ggplot2")
install.packages("fpp2")
AirPassengers
library(ggfortify)
ggplot2::autoplot(AirPassengers)
library(fpp2)
qcement
autoplot(qcement)
ggseasonplot(qcement)
ggseasonplot(qcement,polar=TRUE)
ggsubseriesplot(qcement)
gglagplot(qcement)
ggAcf(qcement)
Acf(qcement)
arrivals
autoplot(arrivals)
summary(arrivals)
ggAcf(arrivals)
Acf(arrivals)
mink
ggAcf(mink)
Acf(mink)
USAccDeaths
ggAcf(USAccDeaths)
Acf(USAccDeaths)
wn <- ts(rnorm(36))
autoplot(wn)
acf(wn)
summary(amount)
#moving average
economics
autoplot(savings.ts)
autoplot(savings.ts, series='Original') +
autolayer(ma(savings.ts,3), series='MA3')+
autolayer(ma(savings.ts,4), series='MA4')+
savings.ts
ses(goog)
autoplot(ses(goog,alpha=0.2,h=1))
autoplot(ses(goog,alpha=0.2,h=10))
uschange
autoplot(uschange)
autoplot(uschange[,c('Consumption','Income')])
autoplot(uschange[,c('Consumption','Income')]) +ylab('%change')
uschange%>%
as.data.frame()%>%
ggplot(aes(x=Income,y=Consumption))+
ylab('Consumption')+
xlab('Income')+
geom_point()
uschange%>%
as.data.frame()%>%
ggplot(aes(x=Income,y=Consumption))+
ylab('Consumption')+
xlab('Income')+
geom_point()+
geom_smooth()
uschange%>%
as.data.frame()%>%
ggplot(aes(x=Income,y=Consumption))+
ylab('Consumption')+
xlab('Income')+
geom_point()+
geom_smooth(method='lm', se=FALSE)
head(uschange)
tslm(Consumption ~ ., data=uschange)
#AUS BEER DATASET
ausbeer
autoplot(ausbeer)
seasonplot(ausbeer)
autoplot(beer1992)
summary(beer.model)
autoplot(beer1992, series='Data')+
autolayer(fitted(beer.model),series='Fitted')+
xlab('Year')+
ylab('Megaliters')
autoplot(beer1992, series='Data')+
autolayer(fitted(beer.model, n.head=10),series='Fitted')+
xlab('Year')+
ylab('Megaliters')
head(uschange)
#create a TSLM model to explain the variation in consumption based on all other predictors
> consumption.model <-
tslm(Consumption~Income+Production+Savings+Unemployment,data=uschang
e)
> consumption.model
Fitted(consumption.model)
Summary(consumption.model)
CV – cross validation
> ausbeer
beer1992 <- window(ausbeer,start = 1992)
autoplot(beer1992)
beer.model <- tslm(beer1992 ~ trend + season)
summary(beer.model)
autoplot(beer1992, series = "Data") + autolayer(fitted(beer.model), series = "Fitted")+
xlab("Year")+ ylab("Megaliters")
fitted(beer.model)
CV(beer.model
Creating a linear model for marathon dataset
mens400
#MENS400 dataset:
mens400
autoplot(mens400)
#to create a mode that explains the rate of changes in winning times
mens400.model
autoplot(mens400)+
autolayer(fitted(mens400.model))
forecast(mens400.model)
A10
Autoplot(a10)
Double differenece
Install.packages(“lubridate”)
Intall.packages(“arulesviz”)
Data(groceries)
Class(groceries)
head(groceires,5)
Inspect(fitec1)
To check which are highly correlated
inspect(head(Rule,5))
plot(Rule,method="graph",engine='htmlwidget')
plot(Rule,method="paracoord")
DECISION TREE
install.packages(“rattle”)
rattle()
install.packages(“ipred”)
Install.packages(“C50”)
install.packages("e1071")
library(e1071)
> library(ISLR)
> head(Default)
CLUSTERING
Install.packages(“tidyverse”)
Usa<-USArrests
Summary(usa)
usa<-scale(usa)
distances<-get_dist(usa)
fviz_dist(distances)
> kc
fviz_cluster(kc,data=usa)
> kc3 <- kmeans(usa,centers=3,nstart = 20)
> wss<-c(kc3$tot.withinss,kc4$tot.withinss,kc5$tot.withinss,kc6$tot.withinss)
> nclusters<-3:6
> plot(nclusters,wss,type='b')
https://cran.r-project.org/web/packages/cluster.datasets/cluster.datasets.pdf
> usa<-USArrests
> usa<-scale(USArrests)
> summary(hcl)
> plot(hcl,cex=0.6,hang=-1)
For divisive
Principal component:
library(dbscan)