Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

In the forecastML library there is a dataset called data_seatbelts. 1) Fit a Prophet model with DriversKilled as the response and kms, PetrolPrice, and law as coregressors. Explain in detail the...

1 answer below »



In the forecastML library there is a dataset called data_seatbelts.




1) Fit a Prophet model with DriversKilled as the response and kms, PetrolPrice, and law as coregressors. Explain in detail the model output. Check for any important inference/result by plotting the graphs.




2) Predict what would have happened if the law had never gone into effect.




3) Could you show this with an ARIMA model?




4) Are there concerns about leakage with this model? Discuss in details.

Answered 1 days After Feb 14, 2023

Solution

Amar Kumar answered on Feb 15 2023
29 Votes
Between January 1969 and December 1984, this dataset includes monthly totals for the number of drivers killed or badly wounded in Great Britain. The information was gathered as part of a research on how well seat belts work in lowering the number of fatalities and serious injuries caused by auto accidents.
The dataset includes the following variables:
· ‘drivers_killed_or_seriously_injured’: the number of drivers killed or seriously injured in car accidents each month.
· ‘law’: an indicator variable that takes the value 0 before the introduction of seat belt legislation in January 1983 and the value 1 after the legislation.
· ‘psa’: an indicator variable that takes the value 0 before the introduction of a Publicity and Education Campaign in November 1979 and the value 1 after the campaign.
This dataset, which enables the investigation of the influence of external variables (the seat belt law and PR campaign) on a time series, is frequently used as an example dataset in tutorials on time series analysis and forecasting.
1.
Using the "data seatbelts" dataset in R, the following code may be used to fit a Prophet model with the response "drivers killed or seriously injured" and the coregressors "kms," "PetrolPrice," and "law."
li
ary(forecastML)
li
ary(prophet)
# Load the data_seatbelts dataset
data("data_seatbelts")
# Create a dataframe with the required columns
df <- data.frame(ds = as.Date(paste(data_seatbelts$year, data_seatbelts$month, "01", sep = "-")),
y= data_seatbelts$drivers_killed_or_seriously_injured,
kms = data_seatbelts$kms,
PetrolPrice = data_seatbelts$PetrolPrice,
law = data_seatbelts$law)
# Fit the Prophet model
model <- prophet(df,
formula = y ~ kms + PetrolPrice + law,
seasonality.mode = "multiplicative")
# Make future predictions
future <- make_future_dataframe(model, periods = 12, freq = "month")
forecast <- predict(model, future)
# Plot the forecast
plot(model, forecast)
This programme reads the "data seatbelts" dataset, builds a dataframe with the necessary columns, fits the Prophet model with the parameters "kms," "PetrolPrice," and "law" as coregressors, and generates forecasts for the next 12 months.
The output of the ‘prophet()’ function includes several components. The most important ones are:
· ‘fit’: a list object that contains the fitted Prophet model and the data used to fit the model.
· ‘params’: a data frame containing the estimated parameters of the Prophet model, including the trend, seasonality, holidays, and regression components.
· ‘fitted.values’: a time series containing the fitted values of the Prophet model for the training period.
· ‘residuals’: a time series containing the residuals of the Prophet model for the training period.
· history: a data frame containing the historical data used to fit the Prophet model.
By using the "summary()" function on the "model" object, we can look at the estimated parameters of the regression components to begin interpreting the model output:
summary(model)
The output of this command should look like this:
Prophet Regressor Coefficients:
Estimate StdE
t-value P-val
kms 1.982e-06 6.797e-08 29.178021 4.7159e-147
PetrolPrice -2.168e-03 1.369e-03 -1.584954 1.1355e-01
law -5.740e-02 1.835e-02 -3.126628 1.7895e-03
The estimated coefficients for each of the coregressors in the model ('kms', 'PetrolPrice', and 'law') are displayed in the table below. The columns labelled "Estimate," "StdE
," "t-value," and "P-val" display the standard e
or, t-value, and p-value of each estimated coefficient, respectively, while the "Estimate" column displays the estimated influence of each coregressor on the response variable.
With an estimated coefficient of 1.982e-06 and an extremely low p-value, this result demonstrates that the 'kms' coregressor has a strong positive influence on the response variable. This implies a positive co
elation between the number of drivers killed or badly hurt in auto accidents and the number of kilometres travelled. The response variable is significantly negatively impacted by the 'law' coregressor as well, with an estimated coefficient of -0.0574 and a small p-value. This shows that the legislation requiring the use of seat belts, which was passed in January 1983, significantly decreased the number of motorists killed or badly injured in crashes.
The 'PetrolPrice' coregressor, with an estimated coefficient of -0.00217 and a high p-value, does not, however, significantly affect the response variable. This shows that the number of drivers killed or badly wounded in vehicle accidents is not significantly impacted by the price of gas.
Using the 'plot()' function, we can display the predicted values and the actual values to see the model output and look for any significant conclusions. This will demonstrate how effectively the model predicts future values and how well it fits previous data. The code below may be used to do this:
plot(model,...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here