'How to create beepvar or dayvar from time-varying VAR
For my Thesis, I am applying time-varying vector autoregression (TVVAR) on time-series objects. I am using a dataset from an open-source paper. As R-package I am using the MGM package which allows processing of mixed graphical models and tv-vars.
To my problem: I want to apply a TVVAR on a dataset which should predict behaviour. I want to predict two variables "I feel stressed" on "depressed/down". However, my R skills aren't that fully developed and to correctly implement all parameters of the TVVAR function I need to create two objects:
- Beepvar (which is like the number of observations on a day)
- Dayvar (the number of days)
I want to create these beepvar and dayvar objects within R, but I don't really know how to subset them from the dataset
Here is a picture of the datasets variables I want to subset.Dataset
multiple observations on one day (e.g. 2/6/2018 is beepvar) I want to create and object that repeats itself per day so to say on 2/6/2018 I have 6 beeps and on 2/7/2018 I have 8 beeps and 2/8/2018 I have only 3 because of NA's or so.
2nd: I also want to create a dayvar object which repeats the days to say, 2/6/2018, 2/7/2018 and so on
EDIT** here is a part of my dataset:
structure(list(`Survey Creation Date` = c("2/6/2018 14:33", "2/6/2018 16:20",
"2/6/2018 18:54", "2/6/2018 20:08", "2/6/2018 22:29", "2/7/2018 8:43",
"2/7/2018 10:52", "2/7/2018 12:21", "2/7/2018 14:56", "2/7/2018 16:20"
), `Survey Completion Date` = c("2/6/2018 14:56", "2/6/2018 16:22",
"2/6/2018 18:58", "2/6/2018 20:22", "2/6/2018 22:46", "2/7/2018 8:44",
"2/7/2018 11:23", "2/7/2018 12:26", "2/7/2018 14:58", "2/7/2018 16:21"
), `Since your last survey; how many alcoholic drinks have you had?` = c(0,
3, 0, 0, 0, 0, 0, 0, 0, 0), `I feel comfortable in my current location` = c(88,
81, 88, 89, 95, 94, 62, 82, 63, 80), `I feel stressed` = c(10,
12, 69, 34, 16, 6, 27, 35, 56, 28), `I feel down/depressed` = c(14,
18, 15, 18, 5, 2, 8, 4, 0, 11)), row.names = c(NA, -10L), class = c("tbl_df",
"tbl", "data.frame"))
This is my code in question:
tvvar_obj <- tvmvar(data = stress_data,
type = rep("g", 12),
level = rep(1, 12),
lambdaSel = "CV",
timepoints = #timepoint object I created,
estpoints = seq(0, 1, length = 20),
bandwidth = ### need bandwidth,
lags = 1,
beepvar = #NUMBER OF OBSERVATIONS ON A DAY,
dayvar = #DAYS OF OBSERVATION,
scale = TRUE,
pbar = TRUE)
How do I do this? I am very thankful for every help.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|