RPubs will retire in June 2027. Your existing documents will stay accessible through December 31, 2031
and Connect Cloud is the recommended home for new publishing. Read the blog post
gravatar

Nishanth_123

Nishanth

Recently Published

HTML
--- title: "Introduction to Time Series Analysis: Simulating and Visualizing Data" author: "Nishanth Seeniasakap Perumal" date: "`r Sys.Date()`" output: html_document: theme: cosmo highlight: tango toc: true toc_float: true code_folding: show --- ## Introduction This document provides an introduction to **time series analysis** using R. We will: 1. Simulate a time series using the `runif()` function. 2. Convert the data into a quarterly time series object. 3. Visualize the data using static and interactive plots. 4. Apply a **6-period rolling average** to smooth the time series. 5. Create an interactive **dygraph** for exploratory analysis. All code and outputs are included in this document. You can interact with the graphs directly in the browser! --- ## Simulating the Time Series We start by simulating a time series with 99 data points. The values are randomly generated between 10 and 45 using the `runif()` function. ```{r simulate, echo=TRUE, message=FALSE, warning=FALSE} # Set seed for reproducibility set.seed(123) # Simulate 99 random points between 10 and 45 mytsdata <- runif(n = 99, min = 10, max = 45) # Convert to a quarterly time series starting in 2000 myts <- ts(mytsdata, start = c(2000, 1), frequency = 4) # Display the first 10 values head(myts, 10)