names(global_meat_production) <- make.names(names(global_meat_production))
### Summarize Data Set: global_meat_production
summary(global_meat_production)
production.df <- global_meat_production
production.ts <- ts(production.df, start=1961,end=2020, freq=12)
#global_meat_production
head(production.ts)
#production.ts
production.ts=as.data.frame( production.ts)
meat.ts <- ts( production.ts$Meat_total_.Production_.tonnes, start=1961, freq=12)
head(meat.ts)
summary(meat.ts)
plot(meat.ts, main='Meat Production Time Series', ylab='Meat Production')
acf(meat.ts)
ggmonthplot(meat.ts)
ggseasonplot(meat.ts)
ggsubseriesplot(meat.ts)
meatLog <- log(meat.ts)
plot(meatLog, main='Meat Production Time Series', ylab='Log of Meat Production')
acf(meatLog)
print(lambda <- BoxCox.lambda(meat.ts)) # find the optimal value for parameter lambda
plot.ts(BoxCox(meat.ts, lambda = lambda))
plot(meatLog, main='Meat Production Time Series', ylab='Log of Meat Production')
plot(BoxCox(meat.ts, lambda = lambda), main='Meat Production Time Series', ylab='BoxCox with lambda = -0.03151884')
acf(meatLog)
acf(BoxCox(meat.ts, lambda = lambda))
summary(fit <- lm(meatLog~time(meatLog)))
tsplot(meatLog, ylab="Meat Production", col=4, lwd=2)
tsplot(resid(fit), main="detrended")
acf(resid(fit))
summary(fit <- lm(meatLog ~ poly(time(meatLog), 2, raw=TRUE)))
tsplot(meatLog, ylab="Meat Production", col=4, lwd=2)
tsplot(resid(fit), main="detrended")
acf(resid(fit))
var(meatLog)
tsplot(meatLog ,main="Meat Production")
tsplot(diff(meatLog), main="first difference")
var(diff(meatLog))
acf(meatLog)
acf(resid(fit))
acf(diff(meatLog))
meatLog.stl <- stl(meatLog, "periodic")
plot(meatLog.stl) # original series
meatLog.sa <- seasadj(meatLog.stl)
plot(meatLog) # original series
plot(meatLog.sa) # seasonal adjusted
acf(meatLog.sa)
seasonplot( meatLog.sa, 12, col=rainbow(12), year.labels=TRUE, main="Seasonal plot: Meat production") # seasonal frequency set as 12 for monthly data.
meatLog.sa <- seasadj(meatLog.stl)
summary(fit <- lm( meatLog.sa ~ poly(time( meatLog.sa), 2, raw=TRUE)))
tsplot(meatLog.sa, ylab="Meat Production", col=4, lwd=2)
tsplot(resid(fit), main="Residuals")
acf(resid(fit))
remainder.ts <-meatLog.stl$time.series[,'remainder']
acf(remainder.ts)
pacf(remainder.ts)
meat.arima = arima(remainder.ts, order = c(1,0,0), include.mean=F)
meat.arima
acf(meat.arima$resid[-1])
pacf(meat.arima$resid[-1])
var(meatLog)
var(diff(meatLog))
nsdiffs(meatLog)
ndiffs(meatLog)
plot(diff(meatLog,12))
acf(diff(meatLog,12))
var(diff(meatLog,12))
plot(diff(diff(meatLog,12)))
acf(diff(diff(meatLog,12)))
var(diff(diff(meatLog,12)))
residuals <- meat.arima$resid[-1]
plot(residuals)
plot.ts(residuals)
acf(residuals)
Correlation Test: Meat_total_.Production_.tonnes, Year
with(global_meat_production, cor.test(Meat_total_.Production_.tonnes, Year,
alternative="two.sided", method="pearson"))
Correlation Test: Meat_total_.Production_.tonnes, Year
with(global_meat_production, cor.test(Meat_total_.Production_.tonnes, Year,
alternative="two.sided", method="pearson"))
Normality Test: ~Meat_total_.Production_.tonnes
normalityTest(~Meat_total_.Production_.tonnes, test="ad.test",
data=global_meat_production)
Single-Sample t-Test: Meat_total_.Production_.tonnes
with(global_meat_production, (t.test(Meat_total_.Production_.tonnes,
alternative='two.sided', mu=0.0, conf.level=.95)))
Histogram: Meat_total_.Production_.tonnes
with(global_meat_production, Hist(Meat_total_.Production_.tonnes,
scale="frequency", breaks="Sturges", col="darkgray"))
Boxplot: ~ Year
Boxplot( ~ Year, data=global_meat_production, id=list(method="y"))
Scatterplot: Meat_total_.Production_.tonnes~Year
scatterplot(Meat_total_.Production_.tonnes~Year, regLine=FALSE,
smooth=FALSE, boxplots=FALSE, data=global_meat_production)