q1_ts and plot it.a <- rnorm(80, mean = 10, sd = 5)
q1_ts <- ts(a, start = c(1950, 1), frequency = 12)
plot(q1_ts)
q1_ts data from question 1, compute 3-period and 5-period, 2-sided moving averages on your dataset. Save them as variables x3_MA and x5_MA then plot the original series with both 3-period (blue) and 5-period (red) moving average lines. Include an appropriate title to your plot.# not sure how to resolve this issue #
#a <- rnorm(80, mean = 10, sd = 5)
#q1_ts <- ts(a, start = c(1950, 1), frequency = 12)
#plot(q1_ts)
#require(stats)
#require(ggplot2)
#require(ggfortify)
#x3_MA <- stats::filter(q1_ts, rep(1/3, 3), sides = 2)
#x5_MA <- stats::filter(q1_ts, rep(1/5, 5), sides = 2)
#x3x5 <- cbind(x3_MA, x5_MA)
#q2_plot <- autoplot(q1_ts) + lines(x3_MA, col = "blue") + lines(x5_MA, col = "red")
#title("Time Series Plot with Moving Averages")
nottem dataset. Explain why and show any work.data(nottem) # Average Monthly Temperatures at Nottingham, 1920–1939
require(forecast)
## Loading required package: forecast
require(ggplot2)
## Loading required package: ggplot2
# look for underlying season or trend using moving average
ggseasonplot(nottem)
# seasonal change clearly correlates with average monthly temp & it is clearly constant over time - b/c of this we will use additive decomposition
cov function in R compute a sample or population covariance?# To calculate the covariance for sample data, we use a multiplier of (1/n-1). For population data, we use (1/N). The function cov() calculates sample covariance.
swiss data set. Calculate the correlation between Catholicism and Fertility. Calculate the correlation between Agriculture and Fertility. Describe what the two numbers tell you.data(swiss) # Swiss Fertility and Socioeconomic Indicators (1888) Data
require(stats)
c_f_corr <- cor(x= swiss$Catholic, y = swiss$Fertility, method = "pearson")
c_f_corr
## [1] 0.4636847
a_f_corr <- cor(x= swiss$Agriculture, y = swiss$Fertility, method = "pearson")
a_f_corr
## [1] 0.3530792
# Using the Pearson method to measure linear correlation, we see that Fertility is more strongly (positively) correlated with Catholicism (0.4636847) than with Agriculture (0.3530792).
rmarkdown::render(“~/Library/Mobile Documents/comappleCloudDocs/Term 4/Time Series”)