1
$\begingroup$

I have data as follows:

day_number          readings
1                       4,5,6
2                       4,7
3                       5,6,4,3
4                       3,5,6
5                       5,6,4,3,2
....

Multiple values of readings come from different subjects seen on the same day. No subject is repeated in the data. Hence 3 subjects were seen on day1, another 2 on day 2, further 4 on day 4, etc. These go on for about 4 years.

I want to determine if there is a seasonal effect on readings. How can I analyze this data? Do I take mean at each time only but then I will not be taking into account the variances on different days.

I checked at other sites but here they had same readings per unit time: Time series with multiple subjects and multiple variables in R and Time series with multiple subjects and multiple variables

$\endgroup$
1
  • $\begingroup$ One way is to create indicartor variables. You will have a constant number of binary "responses" this way. The representation is only a means to an end - the best way to handle this data ultimately depends on the type of analysis you plan to carry out. $\endgroup$
    – KishKash
    Commented Apr 19, 2015 at 18:59

1 Answer 1

1
$\begingroup$

I am not sure if time-series would be your best solution for analyzing these data, but before you can get ts format out of what you have here, you will need to use the splitstackshape package and clean up the data:

install.packages("splitstackshape")
library("splitstackshape")

data

day_number  readings
1          1     4,5,6
2          2       4,7
3          3   5,6,4,3
4          4     3,5,6
5          5 5,6,4,3,2

data_new <- cSplit(data, "readings", sep=",", "long")

Your dataset now looks like this:

data_new

    day_number readings
 1:          1        4
 2:          1        5
 3:          1        6
 4:          2        4
 5:          2        7
 6:          3        5
 7:          3        6
 8:          3        4
 9:          3        3
10:          4        3
11:          4        5
12:          4        6
13:          5        5
14:          5        6
15:          5        4
16:          5        3
17:          5        2

From here, you can add the subject ID by doing the following:

data_new$subject_id <- 1:nrow(data_new)

       day_number readings subject_id
 1:          1        4          1
 2:          1        5          2
 3:          1        6          3
 4:          2        4          4
 5:          2        7          5
 6:          3        5          6
 7:          3        6          7
 8:          3        4          8
 9:          3        3          9
10:          4        3         10
11:          4        5         11
12:          4        6         12
13:          5        5         13
14:          5        6         14
15:          5        4         15
16:          5        3         16
17:          5        2         17

I really want to recommend that you consider using panel data modeling for this, but I have not honestly thought it through (especially with the dataset being quite unbalanced). So, I can only recommend that you do some research on panel data model, as well as on the package plm in R.

I hope this is useful in some way.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.