The data source for this problem set and project can be found at the following site with the USDA Economic Research Service and is more specifically apart of the Meat Statistics tables, Historical file. Here I am aiming at looking at a forecast in which we are attempting to predict what future dressed cattle weights could be. This will help us in a risk management setting by allowing us to see whether or not feed lots are holding onto cattle to fatten them long or if they're marketing them at their nearest convenience.
Complete a time series decomposition using the time series that you collect for your project.
Generate a “seasonally-adjusted” time series of your observed data. Make note of this variable since you will need to export it with your other data.
Use R to create a 3 year forecast of your chosen time series. Follow the steps we went through in lab. Create a new variable that indicates the new data you have created is a forecast.
Create a dataframe with the following variables: measure_date, price, trend, seasonal, residual, sa_price, forecast (indicator of forecasted data).
library(readr)
library(janitor)
library(dplyr)
library(forecast)
library(tidyquant)
R_Average_dressed_weights <- read_csv("R Average dressed weights.csv")
View(R_Average_dressed_weights)
getwd()
setwd("C:/Users/brand/OneDrive/Documents/Spring 2023/AREC 330/Problem Set 6")
dressed_weights_clean <- clean_names(R_Average_dressed_weights)
######################################################################################################
cattle_dressed_ts <- ts(dressed_weights_clean$cattle,frequency = 12,start=c(1985,1))
cattle_dressed_decomp <- decompose(cattle_dressed_ts)
plot(cattle_dressed_decomp)
seasonally_adjusted <- cattle_dressed_ts-cattle_dressed_decomp$seasonal
sa_df <- tibble(seasonally_adjusted=seasonally_adjusted) %>%
mutate(measure_date=seq(as_date("1985-01-01"), by="months", length.out=nrow(.)))
cattle_dressed_decomp_out <- cattle_dressed_decomp[1:4] %>%
as_tibble() %>%
rename(cattle=x) %>%
mutate(measure_date=dressed_weights_clean$date) %>%
mutate(measure_date=seq(as_date("1985-01-01"), by="months", length.out=nrow(.)))
cattle_dressed_trend <- cattle_dressed_decomp$trend
cattle_dressed_seasonal <- cattle_dressed_decomp$seasonal
cattle_dressed_residuals <- cattle_dressed_decomp$random
cattle_dressed_trend_forecast <- forecast(cattle_dressed_trend, h=42)
plot(cattle_dressed_trend_forecast)
cattle_dressed_seasonal_forecast <- forecast(cattle_dressed_seasonal, h=42)
plot(cattle_dressed_seasonal_forecast)
cattle_dressed_residuals_ts <- ts(cattle_dressed_residuals, frequency = 12,start = c(1985,1))
cattle_dressed_residuals_model <- arima(cattle_dressed_residuals_ts, order = c(0,0,1))
cattle_dressed_residuals_forecast <- forecast(cattle_dressed_residuals_model, h=42)$mean
plot(cattle_dressed_residuals_forecast)
cattle_dressed_forecast <- cattle_dressed_trend_forecast$mean+cattle_dressed_seasonal_forecast$mean+cattle_dressed_residuals_forecast
plot(cattle_dressed_forecast)
cattle_dressed_forecast_df <- tibble(cattle=cattle_dressed_forecast) %>%
mutate(measure_date=seq(as_date("2023-02-01"), by="months", length.out=nrow(.)))
cattle_dressed_forecast_df <- cattle_dressed_forecast_df %>%
filter(measure_date > max(cattle_dressed_decomp_out$measure_date)) %>%
mutate(forecast=T)
final_out_cattle_dressed <- bind_rows(cattle_dressed_decomp_out,cattle_dressed_forecast_df,sa_df)
write.csv(final_out_cattle_dressed,"cattle_dressed_weights_forecast.csv")
In Tableau, connect to the file you exported from R with your original price time series data, the forecast, and the (three) components of your decomposition. If needed for your analysis, filter your data on the Date field so that all worksheets in your workbook start at the date you want to begin your analysis.
Use observed prices to create a forecast in Tableau that uses an additive trend line and additive seasonality. Recall that you will need to filter these data on your indicator variable for whether the price values are forecasted or not (in lab we named this variable Forecast)
Create a new visualization that shows the forecasts you created in R. Combine this and the Tableau forecast into a data dashboard. Add a text box to your dashboard and explain any differences between the forecasted estimates and explain why you think the forecasts are different. Once you have created this dashboard you can hide your worksheets you used to create this dashboard by right clicking on them and selecting Hide. This will clean up your workbook.
4. Next create a new worksheet that shows each of the components of your forecast decomposition (the one you did in R). Add a discussion of each of these components as a caption in your worksheet – what are the overall trends in the data? Which seasons have higher or lower prices? How much variation is unexplained by the trend and seasonality components?
5. Finally, create a dashboard that shows seasonal trends in your data by month and by quarter. You can use any visualization(s) of your choosing in this dashboard. Add a text box that describes key take-aways from your analysis and that answers the following questions: Are there more apparent trends in your data when comparing across months or across quarters? Are there noteable differences in the annual trends within a given month or quarter? Do these trends align with the seasonal decomposition you found in your R analysis?
6. Once you have created your dashboard you can hide your worksheets you used to create the dashboards by right clicking on them and selecting Hide. This will clean up your workbook. The final workbook you publish should include your two data dashboards and your single worksheet with the R decomposition.
7. Format your visualizations by adding color, useful titles, appropriate marker labels, text annotations, etc. that help your audience understand your analysis.