First time user of brms: After running a model with brms (see the model specs below)
brmsmod1 <- brm( sales ~ tvgrps_80+radiogrps_40+displaygrps_30+(tvgrps_80 | dma_id), data = salesdat, family = gaussian(),
*warmup = 500, iter = 2000, chains = 4, * control = list(adapt_delta = 0.97), cores=8, seed=123)
I’m able to extract random coefficients for TV grps at a DMA level using the tvdmalevel <- ranef(brmsmod1) # separate coefficient for every one of the 220 DMAs.
I exported the data frame “tvdmalevel” to a csv file using *write.csv" command but the output file did not have the DMA_ID for 220 dmas
What am I doing wrong? Does brms have a method which will allow me to extract the ID column also to be part of the randomized coefficients output?
returns a list of 3D arrays (one per grouping factor) (according to the document). The first dimension is the dma_id. I think you could assign dma_id to the csv file yourself.
Thank you so much @Zhanglong and my apologies for the delay in getting back to you. I came down with covid and it has only now I’m back on my feet. If you see my syntax, I used
tvdmalevel <- ranef(brmsmod1)
and the resulting data frame did not have the dma_id. Am I doing something wrong or missing something in the data extracted? I will go back and check my output once again or rerun it.
Hi Rahul, how about using row.names(tvdmalevel)?
For me, it gives me the group names.
Or in the process of exporting it to the csv file, use write.csv(tvdmalevel,"output.csv",row.names = TRUE).
Cheers.