r - How to handle "sporadic" multiple measures? -


i find myself analyzing data don't know how handle. accept suggestion, keyword help. ideally, looking hints run bayesian hierarchical model on jags (i working on r , rjags).

so imagine having e.g. 10 individuals report perceptions on 5 items. difficulty due fact individuals, have 2 or 3 perceptions 1 (or more) item, in other cases may have nas. structure of data inherently unbalanced. here example of data structure (id identifier , kn item being measured):

    [id] [k1] [k2] [k3] [k4] [k5] [k6] [1]    1   ??  -1    2    3    -3    4 [2]    2   na  -2    1    2    -4    5 [3]    3   0   na    na   3    -2    3 [4]    4   na  -2    2    na   na    5 [5]    5   2   -1    3    4    -5    4 [6]    6   1   na    1    1    -1    3 

the solution came out duplicate rows individuals multiple measurements, , "fill in" row items other 1 measured multiple times available measure those. simple example, let individual 1 have 2 available measures on item k1 (e.g. 1 , 2):

    [id] [k1] [k2] [k3] [k4] [k5] [k6] [1]    1   1   -1    2    3    -3    4 [2]    1   2   -1    2    3    -3    4 [3]    2  na   -2    1    2    -4    5 [4]    3   0   na    na   3    -2    3 [5]    4  na  -2    2    na    na    5 [6]    5   2   -1    3    4    -5    4 [7]    6   1   na    1    1    -1    3 

id individual identifier, , id==1 has 2 different measures k1. cannot take average, need way systematically include additional information. then, run hierarchical model in jags using nested indexing come 1 coefficient each individual, instead of 1 coefficient each row. wonder alternative might use "selector", matrix of 0s , value 1 indicating item being measured. possible implement in jags? don't find examples of similar data structures anywhere. resemble kind of unbalanced repeated-measure data structure, measure contemporaneous.

just make long table id, measure_id , value instead of wide table na's:

n.subjects <- 10 new.df <- data.frame(        id = rep(old.df$id, 6),                      measure_id = rep(1:6, each=n.subjects)                          values = c(old.df$k1,                                      old.df$k2,                                      old.df$k3,                                      old.df$k4,                                      old.df$k5,                                     old.df$k6))  df <- df[!is.na(df$value)]  # remove measurements na's 

then can modify jags code fit new format.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -