Step 1: Problem definition|| Drivers of month-over-month and year-over-year-monthly grwoth of SNAP Sales at Farmers’ Markets

AIM2: Research Question and objectives

Research Questions

What is the association/relationship between monthly statewide nutrition incentive dollar distribution and month-to-month growth of monthly SNAP distribution dollars from 2017 to 2021 at FMs participating in GusNIP in Ohio?

  1. What is driving growth of SNAP distribution at Farmers’ Market particiopating in GusNIP in Ohio?
  2. What is the association between monthly statewide nutrition incentive dollar distribution and monthly SNAP distribution dollars from 2017 to 2021 at FMs participating in GusNIP in Ohio?
  3. Are month sales for January of this year, greater than the month sales for January of the prior year?
  4. Are this years’ sales greater than the last year, and are these sales correlated to distribution of nutrition incentive dollars? month-to-month growth: compared to the priors’ year last month, are snap distribution increasing?

Objectives

NOTE: Work on Objectives (This have to be more specific)

  1. Describe monthly SNAP dollars distribution, nutrition incentive dollar distribution, and month-to-month growth of SNAP dollars distribution at participating FM by location (rural vs urban, network-membership), market size (number of vendors).

  2. Produce a correlation matrix between FM size (number of vendors) and Volume of SNAP sales.

  3. Model/Assess the correlation/association of the amount of monthly statewide nutrition incentive dollars and month-to-month growth of SNAP distribution dollars at FM from 2017 to 2021 adjusted by relevant FM and contextual characteristics

Outcome: month-to-month growth of SNAP dollars distributed at FMs

OUTCOME VARIABLE The key outcome in this study is month-to-month growth of mean monthly SNAP dollars distribution at farmers’ markets in Ohio, from 2017 to 2019. Monthly SNAP distributions is defined as the amount of SNAP dollars distributed in a month at farmers’ market included in the study. Month-to-Month growth of monthly SNAP dollars distribution is calculated as follows:

These are the definitions and formulas used to review 4 different approaches:

  1. Month-to-month growth of SNAP Sales (%). This is a comparison of how much more snap dollars were distributed compared to the prior month. The formula here is M2Mgrowth = ((Snap.Sales of current month/Snap.slaes of prior month) - 1)%100.

  2. Yearly-Month-to-month growth of SNAP Sales (%). This is a comparison of how much more snap dollars were distributed compared to the same month a year prior. The formula here is YM2Mgrowth = ((Snap.Sales of current month/Snap.slaes of same month a year prior) - 1)%100.

  3. Month-to-month growth of mean SNAP Sales (%). This is a comparison of how much more snap dollars were distributed compared to the prior month. The formula here is M2Mmgrowth = ((Snap.Sales of current month/Snap.slaes of prior month) - 1)%100.

  4. Yearly-Month-to-month growth of mean SNAP Sales (%). This is a comparison of how much more snap dollars were distributed compared to the same month a year prior. The formula here is YM2Mmgrowth = ((Snap.Sales of current month/Snap.slaes of same month a year prior) - 1)%100.

R-code used in calculating the outcome variables.

I have reviewed 4 time series. m2m <- m2m %>% mutate( M2Mgrowth = (((SNAP.Sales) / lag(SNAP.Sales,1)) * 100), YM2Mgrowth = (((SNAP.Sales/lag(SNAP.Sales,12))-1)* 100), M2Mmgrowth = (((Mean_SNAP.Sales/lag(Mean_SNAP.Sales,12)) -1) * 100), YM2Mmgrowth = (((Mean_SNAP.Sales/lag(Mean_SNAP.Sales,1))-1) * 100) )

Note: Month-over-month to not be confused by the Compounding Monthly Growth Rate

Not to be confused with the Compounding Monthly Growth Rate Formula (CMGR) CMGR = (Final Month Value / Initial Month Value) ^ (1 / # 12 months) – 1

KEY TAKEAWAYS 1. Year-over-year (YOY) is a method of evaluating two or more measured events to compare the results at one period with those of a comparable period on an annualized basis. 2. YOY comparisons are a popular and effective way to evaluate the financial performance of a company.

Analysis Plan

The following is the analysis plan for this AIM. I’m using Rob J Hyndman and George Athanasopoulos’ approach to modeling time series. https://otexts.com/fpp3/index.html

  1. Define and compute outputs.
  2. Apply Inclusion and Excusion criteria to the dataset
  • Create table 1
  1. Exploratory Analysis
  • Create time-series plots
  • Time Series Patterns
  • Produce Scatterplots
  • Produce Autocorrelation plots
  1. Understanding the timeseries by decomposing the series
  • Calendar adjustment
  • Conduct STL decomposition to understsand Time series components
  • Moving Average
  1. Time Series Regression Model
  • Select Variables of interest
  • Produce a Kitchen Sink, and 2 more conservative models.
  1. Evaluating the regresion Model
  • ACF Plot of residuals
  • Histogram of residuals
  • Residual plot against residuals
  • Residual plot against fitted values
  • Review Outliers and influential observations
  1. ARIMA Model
  • Explore the data
  • Plot the data to identify unusual observations
  • If necessary use a box-cox transformation
  • Select Model order (ACF PACF)
  • Conduct Differencing
  • Plot the ACF and PACF and determine candidate models
  • Model
  • Evaluate the model by checking on residuals
  • Calculate Forecast

Arima Modeling Flowchart

This is an useful flowchart for ARIMA modeling and forecasting.

Databases and CODEBOOK

Sources of Data

The main data set used to address the research questions in this AIM are daily SNAP transaction reports from farmers’ markets utilizing the FMTracks platform. The FMTracks app was developed by Dr. Darcy Freedman and team, to track SNAP distribution, and nutrition incentive dollars distribution at participating FMs. FMtracks is the app used by Farmers’ Markets participating in the SNAP nutrition incentive program in Ohio. The raw data was re-downloaded from FMTracks by Roberto Martinez on Feb 01 of 2023.

Total number of rows: 14,488. This represents unique daily transactions for 148 unique Farmers’ Markets from year 2016 to year 2021. This dataset contains no missing data on SNAP transactions. (CHECK THESE NUMBERS)

FMTracks data was enriched by merging data at the census tract level from: 1. Geographic Identifiers (GEOIDs). The Census Bureau and other state and federal agencies are responsible for assigning geographic identifiers, or GEOIDs, to geographic entities to facilitate the organization, presentation, and exchange of geographic and statistical data. GEOIDs are numeric codes that uniquely identify all administrative/legal and statistical geographic areas for which the Census Bureau tabulates data. https://www.census.gov/programs-surveys/geography/guidance/geo-identifiers.html

  1. Census tract socioeconomic and sociodemographic information found in the American Community Survey.

  2. Rural-Urban Commuting Area Codes. The rural-urban commuting area (RUCA) codes classify U.S. census tracts using measures of population density, urbanization, and daily commuting. A second dataset applies 2010 RUCA classifications to ZIP code areas by transferring RUCA values from the census tracts that comprise them. The most recent RUCA codes are based on data from the 2010 decennial census and the 2006–10 American Community Survey. The classification contains two levels. Whole numbers (1–10) delineate metropolitan, micropolitan, small town, and rural commuting areas based on the size and direction of the primary (largest) commuting flows. These 10 codes are further subdivided based on secondary commuting flows, providing flexibility in combining levels to meet varying definitional needs and preferences. Descriptions of the codes are found within the data files, and also in the Documentation.

  3. The USDA Food Access Research Atlas. The FARA presents an overview of food access indicators for low-income and other census tracts using different measures of supermarket accessibility. It provides food access data for populations within census tracts, and Offers census-tract-level data on food access that can be downloaded for community planning or research purposes.

CODEBOOK

The dataset contain the following variables.

Variable Name Type. Variable Description
Month-to-month Grow SNAP Numerical
Market.Name Categorical
Weekly_Date Date
Paid Staff Numerical
Volunteers Numerical
F&VProducers/Vendors Numerical
FM_Size Categorical
Network Categorical
SNAP Sales Numerical
Incentives.Distributed Numerical
Urban Categorical
ADI Area Deprivation Ind Numerical (Score)
LILATracts_1And10 Categorical
Received_Food_stampsSNAP Numerical.
Number of FMs Numerical
. Transactions Numerical
New SNAP Customers. Numerical

Other Potential Variables (Check with Darcy) PM-SNAP Redeemed PM-F&V-only SNAP Incentives Redeemed Gross Sales for All Vendors Head Count ‘#.New.Federal.Benefit.Customers’

Loading Data & Data Wrangling

Loading Datasets

Loading FMTracks Data

Merging data all years of data into one dataset.

Loading the USDA Food Access Research Atlas & selecting variables of interest.

Loading GEOID information for FMs

Loading Ruca Codes

###Retrieving Census Tract information. Installing Census Bureau API key

## [1] "7a4d78cf8f33e385cfc1d3526fa3baff5924da94"

###Adding ADI with Sociome package When to Use 1-year, 3-year, or 5-year Estimates Choosing which dataset involves more than simply considering the population size in your area. You must think about the balance between currency and sample size/reliability/precision. For details, research implications, and examples, see “Understanding and Using ACS Single-Year and Multiyear Estimates,” in section 3 of the General Data Users Handbook.

Use 5-year Estimates Precision is more important than currency Analyzing very small populations Examining tracts and other smaller geographies because 1-year estimates are not available

Variable Formating & Data Wrangling

Variable Formating

Inclusion & Exclusion Criteria

The following are inclusion criteria for the study.

  1. Yearly SNAP sales is less than 100 U.S dollars. No sales, or very low SNAP sales in a year would indicate the market was not open during that year, although it remained in the system.
  2. At least two consecutive years of reporting. This is important to calculate year over year monthly growth. 3. Consider including only urban centers.

Applying Inclusion Criteria

The FMTracks dataset contains 148 Farmers’ Markets. These Farmers’ Markets reported distribution of SNAP Dollars and the nutrition incentive dollars at some point between 2017 and 2021. After applying the first inclusion/exclusion criteria the list is reduced to 119 Farmers’ Markets. In the end 71 FM are included in the sample.

Code Creating Filter: SNAP Sales = zero

Code || Creating Filter || Two consecutice years of Transactions

List of Farmers’ Markets not included in the study

##  [1] "BMM 2016 - Other"                                          
##  [2] "BMM 2016 - Thurs- Friendly Inn Settlement"                 
##  [3] "BMM 2016 Friday - Rockefeller Park Towers"                 
##  [4] "BMM 2016 Monday - Murtis Taylor"                           
##  [5] "BMM 2016 Tues/Wed - Care Alliance"                         
##  [6] "BMM 2016 Tues/Wed - Steeplechase Apt"                      
##  [7] "BMM 2016 Tuesday - Glenhaven Apt"                          
##  [8] "BMM 2016 Tuesday - University Tower Apt"                   
##  [9] "BMM 2016 Wednesday - Doan Classroom Apt"                   
## [10] "Canton Farmers' Market"                                    
## [11] "Cultivate Co-op Cafe"                                      
## [12] "Fibonacci's Mount Healthy Farmers' Market"                 
## [13] "Franklinton Farms Market"                                  
## [14] "Garrettsville Farmers' Market"                             
## [15] "Hamilton's Historic Farmers' Market"                       
## [16] "Hartman Heimstytte Family Farms"                           
## [17] "Homefull Mobile Grocery"                                   
## [18] "Howland Farmers Market"                                    
## [19] "Idora Neighborhood Farmers Market"                         
## [20] "Indian Lake Farmers Market"                                
## [21] "Lancaster Farmers Market"                                  
## [22] "League Park Market Place"                                  
## [23] "Market Night on Arlington"                                 
## [24] "Market on the Green (Whitehall)"                           
## [25] "Meigs County Farmers Market"                               
## [26] "Mission of Mary"                                           
## [27] "MyWhy West End Market"                                     
## [28] "Our Harvest Cooperative"                                   
## [29] "Piqua Community Farmers Market"                            
## [30] "Reading Farmers Market"                                    
## [31] "The Narrow Way Farm"                                       
## [32] "Thursday - Friendly Inn"                                   
## [33] "Tiffin Seneca Farmers' Market"                             
## [34] "Union County Farmers Market, Marysville"                   
## [35] "Warren Farmers Market"                                     
## [36] "Way Farms Waverly Market"                                  
## [37] "Westerville Farmers Market"                                
## [38] "Youngstown Farmers Market"                                 
## [39] "Ω Bridgeport Mobile Market"                                
## [40] "Ω Cleveland Botanical Garden Farm Stand Buckeye Woodland"  
## [41] "Ω Cleveland Botanical Garden Farm Stand Central"           
## [42] "Ω Cleveland Botanical Gardens Farm Stand Fairfax"          
## [43] "Ω Cleveland Botanical Gardens Farm Stand Midtown"          
## [44] "Ω Cleveland Botanical Gardens Farm Stand Slavic Village"   
## [45] "Ω Clintonville Farmers Market - Wednesday"                 
## [46] "Ω Clintonville Farmers' Market - Winter Drive Thru"        
## [47] "Ω College Hill Farmers Market"                             
## [48] "Ω Dublin Farmers' Market"                                  
## [49] "Ω DUMMY MARKET"                                            
## [50] "Ω Euclid Farmers Market"                                   
## [51] "Ω Findlay Farm Stand at Evanston"                          
## [52] "Ω Findlay Farm Stand at Price Hill"                        
## [53] "Ω Findlay Farm Stand at Walnut Hills"                      
## [54] "Ω Findlay Farmers Market – Sunday"                         
## [55] "Ω Gabriel's Place"                                         
## [56] "Ω Gateway 105 at NEON"                                     
## [57] "Ω Good Earth Farm Stand - Thursday"                        
## [58] "Ω Linden Farmers Market"                                   
## [59] "Ω Madisonville Garden Market"                              
## [60] "Ω Marion Ohio Market"                                      
## [61] "Ω Medina Farmers' Market - Tuesday"                        
## [62] "Ω Nationwide Children's Hospital"                          
## [63] "Ω Nelsonville Farmers Market"                              
## [64] "Ω North Union Farmers Market at Cleveland Clinic Beachwood"
## [65] "Ω North Union Farmers Market at Pinecrest"                 
## [66] "Ω North Union Farmers Market at Public Square"             
## [67] "Ω Oberlin Farmers Market"                                  
## [68] "Ω Ohio City Farm Stand"                                    
## [69] "Ω Ohio City Farm Stand - Friday"                           
## [70] "Ω Pearl Market - Tuesday - OLD, DO NOT USE"                
## [71] "Ω Richwood Farmers Market"                                 
## [72] "Ω St. Clair Farmers Market"                                
## [73] "Ω Stark Fresh Corridor Farmers Market"                     
## [74] "Ω Village Family Farms"                                    
## [75] "Ω Village Family Farms at Euclid Beach Villa"              
## [76] "Ω Wellington Farmers Market"                               
## [77] "Ω Yellowbird Foodshed"

Table 1 of FMs Not Included in the Study

## Warning in table1.formula(~SNAP.Sales + Transaction.Sales +
## SNAP.Incentives.Distributed + : Terms to the right of '|' in formula 'x' define
## table columns and are expected to be factors with meaningful labels.
2016
(N=43)
2017
(N=28)
2018
(N=16)
2019
(N=10)
2020
(N=16)
2021
(N=22)
SNAP.Sales
Mean (SD) 192 (284) 159 (256) 318 (494) 114 (126) 908 (1770) 2070 (2740)
Median [Min, Max] 87.0 [0, 1250] 69.4 [0, 978] 79.0 [4.50, 1740] 73.4 [13.5, 450] 417 [0, 7270] 1060 [0, 10600]
Transaction.Sales
Mean (SD) 688 (1180) 400 (574) 1040 (2780) 157 (131) 917 (1770) 2220 (3020)
Median [Min, Max] 293 [3.00, 5630] 155 [0, 2530] 79.0 [4.50, 11200] 120 [36.0, 450] 417 [0, 7270] 1060 [0, 10600]
SNAP.Incentives.Distributed
Mean (SD) 156 (270) 123 (179) 280 (425) 96.4 (108) 766 (1600) 1590 (2330)
Median [Min, Max] 72.0 [0, 1470] 63.9 [0, 740] 79.0 [4.50, 1380] 66.8 [13.5, 394] 317 [0, 6580] 941 [0, 9690]
newcustomers
Mean (SD) 9.49 (15.5) 8.00 (11.0) 24.5 (55.0) 3.70 (3.16) 24.4 (64.1) 34.9 (56.8)
Median [Min, Max] 6.00 [0, 76.0] 4.00 [0, 47.0] 6.00 [0, 222] 4.00 [0, 9.00] 4.50 [0, 262] 16.5 [0, 262]
vendors
Mean (SD) 92.6 (153) 98.8 (182) 88.9 (171) 113 (157) 244 (325) 301 (306)
Median [Min, Max] 18.0 [0, 800] 18.0 [0, 760] 10.0 [0, 609] 12.5 [5.00, 435] 102 [0, 1130] 250 [0, 1050]
snapvendors
Mean (SD) 71.8 (110) 75.9 (132) 51.9 (85.3) 68.1 (80.1) 173 (250) 200 (228)
Median [Min, Max] 18.0 [0, 460] 17.0 [0, 437] 10.0 [0, 273] 12.5 [5.00, 195] 87.0 [0, 840] 191 [0, 945]

Applying list of markets to data

Addign ADI

Variables

Initial Results

Table 1: Descriptive Statistics of Farmers’ Market offering SNAP Incentives, Ohio, 2016 to 2021

Results: Table 1

Creating a function to compute the p-value for continuous or categorical variables.

Table 1

2016
(N=37)
2017
(N=43)
2018
(N=52)
2019
(N=61)
2020
(N=58)
2021
(N=57)
GPM
Mean (SD) NA (NA) 40.5 (86.3) 37.3 (68.4) 41.9 (170) 261 (569) 59.8 (127)
Median [Min, Max] NA [NA, NA] 14.2 [-57.6, 387] 19.9 [-90.9, 257] -5.93 [-52.9, 1110] 112 [-99.6, 3950] 31.5 [-89.4, 719]
Missing 37 (100%) 6 (14.0%) 9 (17.3%) 9 (14.8%) 0 (0%) 0 (0%)
SNAP.Sales
Mean (SD) 3150 (4020) 3170 (4360) 3280 (4310) 3020 (3970) 6900 (9340) 8730 (10700)
Median [Min, Max] 1620 [199, 20000] 1480 [122, 20000] 1580 [115, 20200] 1190 [158, 20300] 3050 [15.0, 44200] 4120 [482, 49200]
Transaction.Sales
Mean (SD) 6700 (11500) 5590 (9310) 5610 (9170) 4720 (8880) 8460 (13000) 10800 (15400)
Median [Min, Max] 2330 [199, 56700] 1730 [155, 41400] 1590 [115, 41600] 1390 [158, 44900] 3170 [15.0, 75700] 4460 [538, 82300]
SNAP.Incentives.Distributed
Mean (SD) 2220 (3470) 2210 (3230) 2860 (3710) 2740 (3640) 5950 (8260) 7200 (9010)
Median [Min, Max] 1090 [134, 20000] 1090 [90.0, 18300] 1350 [0, 19100] 1060 [144, 19800] 2650 [15.0, 42400] 3270 [196, 45000]
newcustomers
Mean (SD) 60.9 (57.5) 73.2 (128) 60.2 (88.2) 60.1 (79.8) 91.3 (127) 110 (139)
Median [Min, Max] 41.0 [0, 198] 32.0 [0, 700] 34.0 [0, 462] 28.0 [2.00, 382] 43.0 [0, 651] 50.0 [3.00, 697]
vendors
Mean (SD) 1250 (1780) 1250 (1820) 1420 (2580) 1300 (2360) 1260 (2470) 1480 (3520)
Median [Min, Max] 570 [0, 9370] 552 [0, 9370] 540 [2.00, 14500] 525 [0, 13700] 564 [0, 17100] 625 [69.0, 25800]
snapvendors
Mean (SD) 839 (967) 842 (1080) 884 (1160) 817 (1090) 3590 (16600) 3740 (16100)
Median [Min, Max] 440 [0, 4620] 442 [0, 5280] 462 [2.00, 4840] 392 [0, 5050] 481 [0, 126000] 598 [69.0, 121000]
Urban
0 2 (5.4%) 3 (7.0%) 3 (5.8%) 3 (4.9%) 3 (5.2%) 3 (5.3%)
1 35 (94.6%) 40 (93.0%) 49 (94.2%) 58 (95.1%) 55 (94.8%) 54 (94.7%)
LILATracts_1And10
Mean (SD) 0.0811 (0.277) 0.0698 (0.258) 0.0769 (0.269) 0.0656 (0.250) 0.0690 (0.256) 0.0526 (0.225)
Median [Min, Max] 0 [0, 1.00] 0 [0, 1.00] 0 [0, 1.00] 0 [0, 1.00] 0 [0, 1.00] 0 [0, 1.00]
HUNVFlag
Mean (SD) 0.351 (0.484) 0.395 (0.495) 0.365 (0.486) 0.344 (0.479) 0.362 (0.485) 0.333 (0.476)
Median [Min, Max] 0 [0, 1.00] 0 [0, 1.00] 0 [0, 1.00] 0 [0, 1.00] 0 [0, 1.00] 0 [0, 1.00]
LowIncomeTracts
Mean (SD) 0.541 (0.505) 0.558 (0.502) 0.558 (0.502) 0.541 (0.502) 0.534 (0.503) 0.509 (0.504)
Median [Min, Max] 1.00 [0, 1.00] 1.00 [0, 1.00] 1.00 [0, 1.00] 1.00 [0, 1.00] 1.00 [0, 1.00] 1.00 [0, 1.00]
ADI
Mean (SD) 104 (26.1) 104 (26.0) 105 (24.5) 104 (24.5) 105 (24.5) 103 (24.5)
Median [Min, Max] 106 [56.5, 146] 106 [56.5, 146] 106 [56.5, 146] 106 [56.5, 146] 105 [56.5, 146] 104 [56.5, 146]
pstaff
0 8 (21.6%) 6 (14.0%) 12 (23.1%) 8 (13.1%) 9 (15.5%) 7 (12.3%)
1 29 (78.4%) 37 (86.0%) 40 (76.9%) 53 (86.9%) 49 (84.5%) 50 (87.7%)

Timeseries

Outcome: yearly month to month growth of SNAP Dollars

OUTCOME VARIABLE The key outcome in this study is month-to-month growth of mean monthly SNAP dollars distribution at farmers’ markets in Ohio, from 2017 to 2019. Monthly SNAP distributions is defined as the amount of SNAP dollars distributed in a month at farmers’ market included in the study. Month-to-Month growth of monthly SNAP dollars distribution is calculated as follows:

These are the definitions and formulas used to review 4 different approaches:

  1. Month-to-month growth of SNAP Sales (%). This is a comparison of how much more snap dollars were distributed compared to the prior month. The formula here is M2Mgrowth = ((Snap.Sales of current month/Snap.slaes of prior month) - 1)%100.

  2. Yearly-Month-to-month growth of SNAP Sales (%). This is a comparison of how much more snap dollars were distributed compared to the same month a year prior. The formula here is YM2Mgrowth = ((Snap.Sales of current month/Snap.slaes of same month a year prior) - 1)%100.

  3. Month-to-month growth of mean SNAP Sales (%). This is a comparison of how much more snap dollars were distributed compared to the prior month. The formula here is M2Mmgrowth = ((Snap.Sales of current month/Snap.slaes of prior month) - 1)%100.

  4. Yearly-Month-to-month growth of mean SNAP Sales (%). This is a comparison of how much more snap dollars were distributed compared to the same month a year prior. The formula here is YM2Mmgrowth = ((Snap.Sales of current month/Snap.slaes of same month a year prior) - 1)%100.

R-code used in calculating the outcome variables.

I have reviewed 4 time series. m2m <- m2m %>% mutate( M2Mgrowth = (((SNAP.Sales) / lag(SNAP.Sales,1)) * 100), YM2Mgrowth = (((SNAP.Sales/lag(SNAP.Sales,12))-1)* 100), M2Mmgrowth = (((Mean_SNAP.Sales/lag(Mean_SNAP.Sales,12)) -1) * 100), YM2Mmgrowth = (((Mean_SNAP.Sales/lag(Mean_SNAP.Sales,1))-1) * 100) )

Note: Month-over-month to not be confused by the Compounding Monthly Growth Rate

Not to be confused with the Compounding Monthly Growth Rate Formula (CMGR) CMGR = (Final Month Value / Initial Month Value) ^ (1 / # 12 months) – 1

Applying Filter to Data

Time Series Decomposition

Calendar Adjustment|| Calculate average sales per trading day in each month

Some of the variation seen in seasonal data may be due to simple calendar effects. In such cases, it is usually much easier to remove the variation before doing any further analysis.For example, if you are studying the total monthly sales in a retail store, there will be variation between the months simply because of the different numbers of trading days in each month, in addition to the seasonal variation across the year. It is easy to remove this variation by computing average sales per trading day in each month, rather than total sales in the month. Then we effectively remove the calendar variation.

Code that could be used to calculate the SNAP_sales_per_day

“averageSNAP_sales_per_day <- snap %>% #group_by(Market.Name, month) %>% #summarise(AverageSNAP_SalesPerDay = sum(SNAP.Sales) / n_distinct(Date))”

Initial Plots

## Warning: Removed 1 row containing missing values (`geom_line()`).
## Warning: Removed 1 rows containing missing values (`geom_point()`).

## Warning: Removed 12 rows containing missing values (`geom_line()`).
## Warning: Removed 12 rows containing missing values (`geom_point()`).

## Warning: Removed 12 rows containing missing values (`geom_line()`).
## Warning: Removed 12 rows containing missing values (`geom_point()`).

Time Series Components

Trend A trend exists when there is a long-term increase or decrease in the data. It does not have to be linear. Sometimes we will refer to a trend as “changing direction”, when it might go from an increasing trend to a decreasing trend. There is a trend in the antidiabetic drug sales data shown in Figure 2.2.

Seasonal A seasonal pattern occurs when a time series is affected by seasonal factors such as the time of the year or the day of the week. Seasonality is always of a fixed and known period. The monthly sales of antidiabetic drugs (Figure 2.2) shows seasonality which is induced partly by the change in the cost of the drugs at the end of the calendar year.

Cyclic A cycle occurs when the data exhibit rises and falls that are not of a fixed frequency. These fluctuations are usually due to economic conditions, and are often related to the “business cycle”. The duration of these fluctuations is usually at least 2 years.

Creating a Time Series Data using Tsibble

Time Series DataFrame

## # A dable: 72 x 7 [1M]
## # Key:     .model [1]
## # :        YGPM2 = trend + season_year + remainder
##    .model    Month  YGPM2  trend season_year remainder season_adjust
##    <chr>     <mth>  <dbl>  <dbl>       <dbl>     <dbl>         <dbl>
##  1 stl    2016 Jan   0    -10.5        -7.21    17.8            7.21
##  2 stl    2016 Feb  -5.28  -9.49        4.09     0.122         -9.37
##  3 stl    2016 Mar  -8.39  -8.45       21.3    -21.3          -29.7 
##  4 stl    2016 Apr -41.3   -7.40        8.90   -42.8          -50.2 
##  5 stl    2016 May  23.5   -6.56        7.31    22.7           16.2 
##  6 stl    2016 Jun  14.7   -5.71        6.12    14.3            8.58
##  7 stl    2016 Jul  16.4   -4.87       14.4      6.87           2.00
##  8 stl    2016 Aug  16.9   -3.89       12.9      7.93           4.05
##  9 stl    2016 Sep -15.1   -2.91      -13.8      1.65          -1.26
## 10 stl    2016 Oct  -5.61  -1.93      -14.0     10.3            8.38
## # ℹ 62 more rows

## # A dable: 60 x 7 [1M]
## # Key:     .model [1]
## # :        YGPM1 = trend + season_year + remainder
##    .model    Month  YGPM1  trend season_year remainder season_adjust
##    <chr>     <mth>  <dbl>  <dbl>       <dbl>     <dbl>         <dbl>
##  1 stl    2017 Jan -63.7  -45.6        -7.85   -10.2          -55.8 
##  2 stl    2017 Feb -54.4  -40.8       -12.9     -0.677        -41.5 
##  3 stl    2017 Mar -48.6  -36.0         3.01   -15.6          -51.7 
##  4 stl    2017 Apr   4.65 -31.2        27.2      8.65         -22.6 
##  5 stl    2017 May -11.4  -26.8        11.3      4.07         -22.7 
##  6 stl    2017 Jun -16.4  -22.3        14.6     -8.69         -31.0 
##  7 stl    2017 Jul  -6.12 -17.8        -4.70    16.4           -1.42
##  8 stl    2017 Aug -11.7  -13.6        -8.49    10.4           -3.16
##  9 stl    2017 Sep  -3.59  -9.35       -7.47    13.2            3.88
## 10 stl    2017 Oct  -9.60  -5.11       -2.35    -2.14          -7.25
## # ℹ 50 more rows

Modeling Modeling Month-over-month growth YGPM2

TimeSeries Decription

NOTE: This is not a Stationary Time Series. A stationary time series is one whose properties do not depend on the time at which the series is observed. Thus, time series with trends, or with seasonality, are not stationary — the trend and seasonality will affect the value of the time series at different times.

Autocorrelation

Autocorrelation analysis is an important step in the Exploratory Data Analysis of time series forecasting. The autocorrelation analysis helps detect patterns and check for randomness. It’s especially important when you intend to use an autoregressive–moving-average (ARMA) model for forecasting because it helps to determine its parameters. The analysis involves looking at the Autocorrelation Function (ACF) and Partial Autocorrelation Function (PACF) plots.

The lag plot is used to answer the following questions:

Distribution of Model: Distribution of model here means deciding what is the shape of data on the basis of the lag plot. Below are some examples of lag plot and their original plot: If the lag plot is linear, then the underlying structure is of the autoregressive model. If the lag plot is of elliptical shape, then the underlying structure represents a continuous periodic function such as sine, cosine, etc.

Outliers: Outliers are a set of data points that represent the extreme values in the distribution

Randomness in data: The lag plot is also useful for checking whether the given dataset is random or not. If there is randomness in the data then it will be reflected in the lag plot, if there is no pattern in the lag plot.

Seasonality: If there is seasonality in the plot then, it will give a periodic lag plot.

Autocorrelation: If the lag plot gives a linear plot, then it means the autocorrelation is present in the data, whether there is positive autocorrelation or negative that depends upon the slope of the line of the dataset. If more data is concentrated on the diagonal in lag plot, it means there is a strong autocorrelation.

## # A tsibble: 18 x 2 [1M]
##         lag     acf
##    <cf_lag>   <dbl>
##  1       1M  0.207 
##  2       2M -0.0180
##  3       3M -0.0798
##  4       4M -0.240 
##  5       5M -0.0786
##  6       6M -0.234 
##  7       7M -0.0514
##  8       8M -0.0494
##  9       9M -0.0579
## 10      10M  0.0129
## 11      11M  0.218 
## 12      12M  0.186 
## 13      13M  0.180 
## 14      14M  0.118 
## 15      15M -0.0965
## 16      16M -0.0770
## 17      17M -0.194 
## 18      18M -0.200

Strong autocorrelation in a lag plot typically manifests in the following ways:

Clear Linear Pattern: When there is strong autocorrelation, the points in the lag plot tend to align along a straight line, indicating a linear relationship between the current values and their lagged counterparts.

Tight Cluster: Points in a lag plot with strong autocorrelation tend to form a tight cluster around the regression line. This means that the relationship between the current values and lagged values is consistent and predictable.

Persistence of Patterns: If there are patterns in the original time series data, those patterns will be reflected in the lag plot when there is autocorrelation. For example, if there’s a repeating pattern every few time points, you’ll see a similar repeating pattern in the lag plot.

Slow Decay: In some cases of strong autocorrelation, the lag plot might show a slow decay in the pattern as the lag increases. This indicates that the effect of autocorrelation persists over several lagged values.

https://towardsdatascience.com/interpreting-acf-and-pacf-plots-for-time-series-forecasting-af0d6db4061c

The ACF plot can provide answers to the following questions: Is the observed time series white noise/random? Is an observation related to an adjacent observation, an observation twice-removed, and so on? Can the observed time series be modeled with an MA model? If yes, what is the order?

The dashed blue lines indicate whether the correlations are significantly different from zero (as explained in Section 2.9).

## Series: GPM 
## Model: TSLM 
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -69.08 -23.61  -8.07  18.31 105.45 
## 
## Coefficients:
##                               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                 112.240980  16.403696   6.842 7.43e-09 ***
## SNAP.Incentives.Distributed   0.001219   0.001187   1.027 0.309179    
## nsnaptx.x                    -0.140003   0.032937  -4.251 8.49e-05 ***
## newcustomers                  0.279735   0.067240   4.160 0.000115 ***
## snapvendors                   0.001590   0.001582   1.005 0.319562    
## dayopen.x                     0.150066   0.165381   0.907 0.368230    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 39.74 on 54 degrees of freedom
## Multiple R-squared: 0.3095,  Adjusted R-squared: 0.2456
## F-statistic: 4.841 on 5 and 54 DF, p-value: 0.00099332

#Modeling Modeling yearly Month-over-month growth YGPM2

#Modeling Modeling SNAP.Sales