Happy 2020 Stan Community!!
Problem set up
I have experimental data on three(3) different oils (LAC, SVP, MG) in which these oils are measured for a specific property of theirs (the response variable). This property is measured every second for 4500 seconds while the oil is coated on a metal ball (responses are time dependent).
In addition, this experiment was run in duplicates with the order in which the samples were run was randomized i.e, run 1 of sample 1 was equally likely to be followed by run 2 of sample 1 or run 1 of sample 3.
We have 4500 responses for each run of the sample, and 2 runs of each sample so in total.
Model specification
There’s clearly non-linearity so I’d like to model time as a non-linear effect, but I’m not sure how to model the sample/runs.
- Model runs as being nested within the sample? I.e, a random intercept for sample and random intercept for the unique sample_run combination
- Simply include a fixed effect for sample
Modeling choice 1
For brevity, I won’t be specifying priors, but focus on the model formula
nested_mod <- brm(
response ~ (1|sample/run) + s(time, bs = "cs))
Modeling choice 2
fixed_mod <- brm(
response ~ sample + s(time, bs = "cs))
Below is a random fraction of the data set
tibble::tribble(
~run, ~response, ~sample_fac, ~new_time,
"lac_1", 72.8442980643677, "lac", 13.678046390098,
"lac_1", 72.41406270519, "lac", 16.6501296541285,
"lac_1", 72.8452447618132, "lac", 29.6175944592435,
"lac_1", 68.540513907131, "lac", 7.7637882003658,
"lac_1", 71.8944808768374, "lac", 28.828116263878,
"lac_1", 71.9308825540751, "lac", 10.9361076503158,
"lac_1", 71.5376752310561, "lac", 29.1871714518968,
"lac_1", 69.9779038226358, "lac", 9.54013693347616,
"lac_1", 63.8421474913109, "lac", 1.03286014605356,
"lac_1", 71.7385392924506, "lac", 12.8925599294346,
"lac_1", 73.0084587777277, "lac", 19.8486050005634,
"lac_1", 64.4812000067977, "lac", 2.78784175255378,
"lac_1", 66.0082947375471, "lac", 4.99397939155852,
"lac_2", 64.5907341765694, "lac", 13.7044344759663,
"lac_2", 68.6342970533887, "lac", 24.0550853718189,
"lac_2", 67.7282015400432, "lac", 20.8624006841448,
"lac_2", 64.3935660677285, "lac", 17.7782761641895,
"lac_2", 63.064660646255, "lac", 19.220369340491,
"lac_2", 45.7941966608521, "lac", 0.517151577968647,
"lac_2", 69.9130225629351, "lac", 29.7351333742147,
"lac_2", 67.7026708945785, "lac", 21.9425217491691,
"lac_2", 69.5001879334048, "lac", 26.6210199553636,
"lac_2", 67.9561831547372, "lac", 21.4493644818315,
"lac_2", 70.2920241598646, "lac", 25.2476974761696,
"lac_2", 65.4506704373289, "lac", 14.7406316652079,
"lac_2", 59.9148155584788, "lac", 10.646390048659,
"mg_1", 260.503153387465, "mg", 29.3485134429766,
"mg_1", 256.990726479642, "mg", 22.8634543108756,
"mg_1", 231.523372460514, "mg", 9.85511561594923,
"mg_1", 258.810302560367, "mg", 26.887701640092,
"mg_1", 178.472230412952, "mg", 2.74191499426981,
"mg_1", 207.84821888721, "mg", 5.03972217645516,
"mg_1", 259.23150278601, "mg", 26.6622660061812,
"mg_1", 109.265224850238, "mg", 0.671548847761205,
"mg_1", 182.057836027649, "mg", 2.94406872913261,
"mg_1", 210.412089184462, "mg", 5.44547846862135,
"mg_1", 245.319770264699, "mg", 16.1546196541285,
"mg_1", 251.182405939783, "mg", 19.8020835881589,
"mg_1", 257.975048365293, "mg", 24.8633570977954,
"mg_2", 225.130085396146, "mg", 19.0380423209136,
"mg_2", 161.175762351683, "mg", 2.85453049423819,
"mg_2", 173.724839789085, "mg", 3.82363149155577,
"mg_2", 98.8292953783186, "mg", 0.785282881275688,
"mg_2", 222.676523674486, "mg", 15.9305291688507,
"mg_2", 222.833859459554, "mg", 15.8397324856342,
"mg_2", 221.325160692058, "mg", 15.5042274699518,
"mg_2", 230.524244029661, "mg", 25.5590971066122,
"mg_2", 235.771677980177, "mg", 29.8000343710155,
"mg_2", 211.679460636609, "mg", 10.8247678280314,
"mg_2", 219.361066418684, "mg", 14.1751858727512,
"mg_2", 220.909805561996, "mg", 14.4909348788643,
"mg_2", 174.943764085913, "mg", 3.89021373660949,
"svp_1", 230.242033419717, "svp", 14.1970042256827,
"svp_1", 67.4564310659396, "svp", 0.0900337974263472,
"svp_1", 239.085716326199, "svp", 19.981160609862,
"svp_1", 242.941970072719, "svp", 22.5472045039015,
"svp_1", 234.100667378645, "svp", 16.3810161444081,
"svp_1", 140.87585851739, "svp", 0.739684151597519,
"svp_1", 246.668871677588, "svp", 29.4163462124953,
"svp_1", 183.55987624315, "svp", 2.47351804875789,
"svp_1", 242.941726439951, "svp", 25.470823572362,
"svp_1", 231.781479217227, "svp", 14.7838310002072,
"svp_1", 248.871522769646, "svp", 29.6645006072896,
"svp_1", 245.935330400674, "svp", 25.9174953704888,
"svp_1", 242.81470616125, "svp", 22.9078243732175,
"svp_2", 257.69373518629, "svp", 20.5235447974847,
"svp_2", 246.193204057907, "svp", 14.6493610002072,
"svp_2", 207.263723482967, "svp", 2.24895021719572,
"svp_2", 232.308465434741, "svp", 7.89871767237497,
"svp_2", 261.3222156315, "svp", 22.3231398484641,
"svp_2", 209.263986590766, "svp", 2.36152060171304,
"svp_2", 264.906273073939, "svp", 24.7742095119757,
"svp_2", 245.940441513134, "svp", 13.7025537803275,
"svp_2", 261.904791006638, "svp", 23.2911638131337,
"svp_2", 232.010125007026, "svp", 7.58396809296397,
"svp_2", 236.332222354715, "svp", 9.20233885366184,
"svp_2", 238.382588724674, "svp", 9.94583395966043,
"svp_2", 225.677538975778, "svp", 5.37818322730896
)
Please also provide the following information in addition to your question:
- Operating System: Windows 10
- brms Version: 2.10.0