我正在努力绘制使用plm
包分析的重复测量实验所产生的预测概率。
我正在分析的实验数据是重复测量实验。要求人们在不同类型的产品之间做出8种选择。这些产品出现的顺序(product
,一个8级因子变量)是随机的。在每个时间点,一个人被分配折扣或没有折扣(二分法变量discount_i
)。
我的理论认为,持续的态度变量(iipm
,0-12)和折扣(discount_i
)之间存在相互作用,而不是产品。因此,我的模型如下:
fixed <- plm(chose ~ iipm*discount_i+factor(product), data=df, index=c("time", "id"), model="within", family='binomial')
我正在使用一个基本的固定效应模型来计算时间以及观察之间的依赖关系,但我说,我对时间的影响并不感兴趣。 我想要做的是生成预测概率的8个产品特定交互图,X轴上的连续变量(iipm
)和discount_i
的水平是两行预测值。
请帮忙!对我目前的技能水平来说有点棘手。
下面的示例数据(应该是平衡的,我希望!):
> dput(sample_data[1:128,])
structure(list(id = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 13L,
13L, 13L, 13L, 13L, 13L, 13L, 13L, 14L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 16L), .Label = c(" A1FC4ZLFOKK2B9", " A22HZJIW9LEIS0",
"A002160837SWJFPIAI7L7", "A09265903LS1OKAES4KAC", "A10B7OQ3GMIFD3",
"A10ELK3KP57KWE", "A11F2KD14NFQ0A", "A11HTX95941MJI", "A12SMSQ6D5227J",
"A12VWKFS6N0SV6", "A13HSR88OUNIVP ", "A14OFQMJ2Q6BTI", "A14OK6VJZDJ421 ",
"A14W00II6N5ADC", "A14W0AXTJ3R19V", "A15DIISD5XBWHK", "A15E4I3BZKHNUV",
"A1640357KEVPIW", "A1650FELH3UL2F", "A16KTSWXO8ZLMO", "A1835XBNR2UB4X",
"A18ACKRAVMM8D8", "A18TXM6GMU1411", "A19F9CLZ0XWBYR", "A1A25FXEVMBSOA",
"A1AJG4BGSRPC93", "A1AU8R78QWNKJD", "A1AYTEFEX5B89X", "A1BDBKDS7F7OMW",
"A1BQEX75BE1AYE", "A1BXEU20OCUGVZ", "A1CAMCK95M88CN", "A1CIIX0CB0GR7H",
"A1CTJ8UT7SF317", "A1ED68DLJ8YFWM", "A1EWHJ42DLEL37", "A1EWQ6YCM8CO0E",
"A1F8MOWCCVDIH2", "A1GK40XYRMZHP7", "A1HFYKYYG9MW8G", "A1HI6CVPXJ70L1",
"A1I2DD7WM94VC2", "A1I6551IZGYWM8", "A1ITBXITLY2952", "A1J4BNCH0HIQ98",
"A1JMINVUZ2AOZR", "A1JMUSGZ7RN22X", "A1JXS7PBKBEVHT", "A1KEC6S4OBBE2U",
"A1KJV3S1EK7LUT", "A1LMGLI5F2ZT4W", "A1M72TTFPE00AM", "A1NM7ZPZ3NH412",
"A1OKNQ2JEXW34Q", "A1OQIXAU1SEJ4P", "A1OV86I0FAFAM1", "A1PA4WGAPB8LUV",
"A1PLDF2A9RJD3J", "A1Q8L9UA8SAPIQ", "A1QK6O24KDVLJ1", "A1QR6I7UPY8XQJ",
"A1QTQISKEHWSKZ", "A1R4F6EPXA3VCL", "A1R8A1ZKR80MRA", "A1S5W9N861BFLD",
"A1SB15LP2XJVVT", "A1SG4CCCMLF8W2", "A1T5YMBH35PDBX ", "A1T78PV59MJ88L",
"A1TH8X83SGT5ZE", "A1U81IXEMNUMX2", "A1UE8XA52IFAIV", "A1UH396UOK0X9Z",
"A1WDSSOA9GW1T", "A1WUBD5BHESJVV", "A1XLGIFFGB01EU", "A1XSXTWJ4SDFXD",
"A1YS3RYTSEXSGH", "A1YSYI926BBOHW", "A1ZERM9X4BHQV2", "A1ZHF9MHTINO5S",
"A1ZN6M815BQV96", "A200LNG7PDSUGZ", "A209PPOU3RKN8E", "A20ASMCESA51U4",
"A20IA63WXHF683", "A2177MS5XTPHK4", "A21ULKCLHVAACL", "A21YQXPL0SNNR2",
"A220JLNQJ2WL33", "A22CF8BF9YQND7", "A22LZ62E0UC4VL", "A22R7DT2XQIKXV",
"A22XK2FSFIAAFG", "A23AWSZSAGLY8X", "A23HJNY3F7Z9CS", "A23JA6ICO4BPQ5",
"A243FYB6B3DG2S", "A244Q3FRPL4R3D", "A24LUXW1DB1QI5", "A257UIPAZR9NTN",
"A25ZADCJI3D5AF", "A269JSFR6BWAW3", "A27CDEZVU8HL0N", "A27IABVBUZ9X8Z",
"A27MJOV91GA8R3", "A28NJNZ3NRZ85T", "A28PG3NQXF9VAA", "A28QG7I54E4XAD",
"A2958CGPRRIV04", "A29VL3MZE7YPBZ", "A2APPZDU0VS9LN", "A2AR2PLDAHHB28",
"A2AU7FRKEQ0OHE", "A2AXGNA291U5BF", "A2BAFU5B5G2AVX", "A2BTJFHP7WQY23",
"A2CWLWWRIK3IX3", "A2D2XQP00IZFR1", "A2DTTNGUXTEGHQ", "A2EEUQ0YY2XIU",
"A2EHRNN23UBSJA", "A2EI075XZT9Y2S", "A2EM7RPFW3DU9N", "A2F2ASKIB0U2LM ",
"A2FLCDTES3YD5I", "A2FZMW0KCCVLXR", "A2G8UI423QZYJJ", "A2GHZI45J9CN9R",
"A2H18EYM79ZRCW", "A2H8GNSEVUJXYL", "A2HW7UTK78JAKG", "A2I7S2991CE4XO",
"A2I9PUZT19ZBO8", "A2IRXCL5YW5RAS", "A2J6T9ELNZ97JH", "A2J7PEUIO2WVUN",
"A2JVZUU107CL6Y", "A2KFOOEQWGN0GK", "A2NVUN3MHY8LMQ ", "A2OFN0A5CPLH57",
"A2OW2CIT4H7364", "A2PPTAURU5AAQB", "A2QB3M030UWH53", "A2QLSHXNCHBRN4",
"A2QZV6QX8WXJUN", "A2R10YXGQ9MTJ6", "A2R1CERP22ICFT", "A2R4B6OJPIW0HQ",
"A2RMOCDLA2JSO5", "A2S96ZZ70YFPSK", "A2SPN23MCH9RKP", "A2TG7EEQ2XG2IK",
"A2U81N228679L1", "A2UKT57LG0TWD1", "A2UO3QJZNC2VOE", "A2VDLRRPXV3N59",
"A2VZB11NR1QC0S", "A2WLGVXAVT2XTR", "A2WZDY9R2GHRXD", "A2XM6C78S9L8UG",
"A2XS49LRNX8PD4", "A2Y0SIZH81B265", "A2Y0ZGI29KQBTB", "A2YGVQGMU5AQYY",
"A2YTOX7SEDJ1TC", "A2YYQJ3JWA2KGD", "A2Z8F0B2YGRFEY", "A30MS11FPNF1DS",
"A316ZWBTQ7PGE7", "A31O3Y1D4EVLRP", "A321FJYVTX5WP9", "A321UTTHJSC5PO",
"A32VLTWRJ1EP5T", "A32ZPYIWFEUCDX", "A33B6YFHZCMDUC", "A33BFK8KFKJ3IA",
"A341G96EYJLBKF", "A347XXV5JH19PB", "A3485MZKNDDAMK", "A352QIC9QSCQEM",
"A35OGKV242IJ78", "A3696JXTRKL2FI", "A372KQ73N0RZLJ", "A37533SGF100SL",
"A37BWMULVPH2XJ", "A37I58C4258IPX", "A37NI374J4UNXD", "A37WXDYYT7RCZ0",
"A3862RIFFUV141", "A38TCB4NTM5093", "A38USYKE9P7Z9O", "A39PGXN2A70UN5",
"A39YE1VEL5T2XF", "A3ACR8IG31Q7K6", "A3AP1NCEBBR8S0", "A3APC5DH14Q0E2",
"A3AWWFCNLAYW90", "A3B6BODCYK2O7L", "A3B6DOMIUDYB3I", "A3BFRHKQ94MZBX",
"A3BM05OXSUCJII", "A3BUX2X4NAIB3K", "A3CCBRS9NU71R8", "A3CO5374TFUFEK",
"A3D7JEGMSYKCUJ", "A3DD0FNVTIY7GO", "A3DU2ZHN459R53", "A3E8SXH0BAYG85",
"A3EU5A0CGLUBRZ", "A3FDSQADGUY42E", "A3FG68U6LZ8EGN", "A3FWFXTCHEX9UM",
"A3G9MSZVWB7W42", "A3GPR8TTDAX01S", "A3HKOZ90IDUZ8Z", "A3HLCR4YCHJWBI",
"A3HQYWUW66HG1J", "A3IE6ATDKX6N1H", "A3J22SWYT5NPX6", "A3JZS32RQUWGJM",
"A3KWA2ORU9M9IF", "A3M5CBY1V1FCX2", "A3MWV912LNFD67", "A3NH3BCC6GHEWR",
"A3O1L0034OG341", "A3OWP3M7I9AQ44", "A3Q45OPFL3R49", "A3Q4T34SDWIHU9",
"A3QB0Z9AN62HFH", "A3QM71HR4ZP65N", "A3QSJY1FFN0N6V", "A3QY3I5O0STFGA",
"A3RTMAO8QC1Z97", "A3T7N659X3PGKV", "A3TBA7X9EF16W6", "A3TFAAGSW70079",
"A3TXO6RKFIDFUV", "A3UX6ETXQOCG65", "A3VIM82WAK5TIZ", "A3W1LG4JXLNCL",
"A50BRZM8LHWCD", "A5N8JGDID098C", "A669K8QT6PVVF", "A6IVYRP8FAIS",
"A7D1FSJZSM3MJ", "A7EUXC5Q4675O", "A7I3G380E29VE", "A8BFVGGZ06DEC",
"A8BLFGJE6RDQK", "A8FAG8ZFEM7FP", "A9JLQEN9J5WL3", "A9KJJHT79BXS8",
"AA7ZQGZUR6V5E", "AAVJV2EYBWESX", "AC5LU9TF9CTK9", "ACJJUQ96T22RC",
"ACNM6EM54CKRT", "ACPHZ1AG8XAQ0", "ACWYF9Z50PCA9", "ACZXP89TIXCUA",
"ADQKQCMH1ALS6", "AEQWOTF1QN1MK", "AFB9N61OMZXCX", "AFHAH1BIN51GI ",
"AG4LR5A7TCRH9", "AG7WQ3TB100SO", "AGF9EJ5F4E45D", "AGJ6958FU8A4N",
"AHMFDP04U8I02", "AI1JF1C8UK1CX", "AIC8ALJV5X9OY", "AJB0OAEIYGY87",
"AJETFLAXRDTKJ", "AJSTOFYJCC87B", "AM2V91APQ1DYH", "ANUXUJE8QRE0C",
"AO3XB5I5QNNUI", "AO4ZHD0B9KUNE", "AOF7TQQOL7IT8", "AOKQZBHA40IBW",
"AOLU7V2SEBS75", "AOT04CJ43L5V1", "AOVB3KCIIJLRJ", "APC3O2O8O9XPO",
"APGX2WZ59OWDN", "AQ36OBO2GRA00", "AQ7YZUJW31SEL", "AQEVAKQLI09EN",
"AQLG9XLOAUWUH", "AR95C0P53AFWJ", "ARVSVYBL46LC9", "AS3BSFKKBAN8J",
"AS8XVJ2TNN58J", "ASH55LLJVVBOZ", "ASXIEBMMWW1NE", "AT0COJ1G23ZB0",
"AT3HYOVRFTGNH", "ATHS9GUME1XCA", "ATJQG32KDCYMO", "AULC5HR1BBHMA",
"AUN8AE8UCO3MD", "AUO7XEZDY9496", "AUSCGO1H49UY2", "AV5PNRD316L5R",
"AVZ76FUE8VET9", "AWPAWDDLEEPTC", "AYG3MF094634L", "AYQWBIUVDPBXK",
"AYSX5GNO640MZ", "AYZ85PU887QY1", "AZ1RJVNOZFIWV", "AZA8EVH0RZAR9",
"AZCV8JQ2NEFN8", "AZOAW8JH5HJJK"), class = "factor"), product = c("Soap",
"Chocolate", "Shampoo", "Batteries", "Tees", "Cleaner", "Jelly",
"Coffee", "Soap", "Chocolate", "Shampoo", "Batteries", "Tees",
"Cleaner", "Jelly", "Coffee", "Soap", "Chocolate", "Shampoo",
"Batteries", "Tees", "Cleaner", "Jelly", "Coffee", "Soap", "Chocolate",
"Shampoo", "Batteries", "Tees", "Cleaner", "Jelly", "Coffee",
"Soap", "Chocolate", "Shampoo", "Batteries", "Tees", "Cleaner",
"Jelly", "Coffee", "Soap", "Chocolate", "Shampoo", "Batteries",
"Tees", "Cleaner", "Jelly", "Coffee", "Soap", "Chocolate", "Shampoo",
"Batteries", "Tees", "Cleaner", "Jelly", "Coffee", "Soap", "Chocolate",
"Shampoo", "Batteries", "Tees", "Cleaner", "Jelly", "Coffee",
"Soap", "Chocolate", "Shampoo", "Batteries", "Tees", "Cleaner",
"Jelly", "Coffee", "Soap", "Chocolate", "Shampoo", "Batteries",
"Tees", "Cleaner", "Jelly", "Coffee", "Soap", "Chocolate", "Shampoo",
"Batteries", "Tees", "Cleaner", "Jelly", "Coffee", "Soap", "Chocolate",
"Shampoo", "Batteries", "Tees", "Cleaner", "Jelly", "Coffee",
"Soap", "Chocolate", "Shampoo", "Batteries", "Tees", "Cleaner",
"Jelly", "Coffee", "Soap", "Chocolate", "Shampoo", "Batteries",
"Tees", "Cleaner", "Jelly", "Coffee", "Soap", "Chocolate", "Shampoo",
"Batteries", "Tees", "Cleaner", "Jelly", "Coffee", "Soap", "Chocolate",
"Shampoo", "Batteries", "Tees", "Cleaner", "Jelly", "Coffee"),
chose = c(1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1,
1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0,
1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1,
1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1,
1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1), discount_i = c(1,
1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1,
1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1,
0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0,
0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1,
0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0,
1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1,
1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0), iipm = c(9, 4, 9,
4, 4, 9, 4, 4, 12, 12, 12, 12, 12, 12, 12, 12, 0, 0, 0, 0,
0, 0, 0, 0, 10, 10, 10, 8, 10, 10, 6, 8, 4, 3, 4, 1, 3, 4,
0, 1, 8, 4, 8, 8, 4, 8, 3, 8, 7, 6, 7, 0, 6, 7, 4, 0, 9,
11, 9, 4, 11, 9, 2, 4, 8, 7, 8, 4, 7, 8, 4, 4, 4, 10, 4,
0, 10, 4, 7, 0, 6, 8, 6, 8, 8, 6, 2, 8, 7, 7, 7, 4, 7, 7,
5, 4, 1, 8, 1, 5, 8, 1, 5, 5, 11, 9, 11, 10, 9, 11, 7, 10,
11, 10, 11, 11, 10, 11, 9, 11, 5, 8, 5, 4, 8, 5, 7, 4), time = c(7,
1, 8, 4, 2, 6, 5, 3, 7, 8, 5, 3, 4, 2, 1, 6, 4, 3, 1, 2,
6, 8, 7, 5, 1, 4, 7, 6, 8, 3, 5, 2, 3, 6, 1, 5, 4, 8, 7,
2, 3, 8, 2, 6, 4, 7, 1, 5, 2, 1, 8, 7, 3, 5, 4, 6, 4, 2,
3, 7, 1, 8, 6, 5, 5, 2, 6, 7, 3, 4, 8, 1, 7, 1, 8, 5, 3,
6, 4, 2, 1, 5, 3, 4, 7, 2, 6, 8, 6, 3, 4, 2, 1, 5, 8, 7,
6, 4, 2, 3, 8, 5, 7, 1, 7, 1, 8, 3, 2, 5, 4, 6, 1, 6, 3,
7, 8, 2, 4, 5, 3, 8, 5, 6, 1, 7, 4, 2)), .Names = c("Q97",
"product", "chose", "discount_i", "iipm", "time"), row.names = c("108.soap",
"108.choc", "108.shampoo", "108.batt", "108.tee", "108.clean",
"108.jelly", "108.coffee", "220.soap", "220.choc", "220.shampoo",
"220.batt", "220.tee", "220.clean", "220.jelly", "220.coffee",
"241.soap", "241.choc", "241.shampoo", "241.batt", "241.tee",
"241.clean", "241.jelly", "241.coffee", "152.soap", "152.choc",
"152.shampoo", "152.batt", "152.tee", "152.clean", "152.jelly",
"152.coffee", "247.soap", "247.choc", "247.shampoo", "247.batt",
"247.tee", "247.clean", "247.jelly", "247.coffee", "205.soap",
"205.choc", "205.shampoo", "205.batt", "205.tee", "205.clean",
"205.jelly", "205.coffee", "173.soap", "173.choc", "173.shampoo",
"173.batt", "173.tee", "173.clean", "173.jelly", "173.coffee",
"132.soap", "132.choc", "132.shampoo", "132.batt", "132.tee",
"132.clean", "132.jelly", "132.coffee", "78.soap", "78.choc",
"78.shampoo", "78.batt", "78.tee", "78.clean", "78.jelly", "78.coffee",
"10.soap", "10.choc", "10.shampoo", "10.batt", "10.tee", "10.clean",
"10.jelly", "10.coffee", "137.soap", "137.choc", "137.shampoo",
"137.batt", "137.tee", "137.clean", "137.jelly", "137.coffee",
"114.soap", "114.choc", "114.shampoo", "114.batt", "114.tee",
"114.clean", "114.jelly", "114.coffee", "304.soap", "304.choc",
"304.shampoo", "304.batt", "304.tee", "304.clean", "304.jelly",
"304.coffee", "149.soap", "149.choc", "149.shampoo", "149.batt",
"149.tee", "149.clean", "149.jelly", "149.coffee", "21.soap",
"21.choc", "21.shampoo", "21.batt", "21.tee", "21.clean", "21.jelly",
"21.coffee", "107.soap", "107.choc", "107.shampoo", "107.batt",
"107.tee", "107.clean", "107.jelly", "107.coffee"), class = "data.frame")
答案 0 :(得分:0)
这可能接近你想要的。
interaction.plot(df$iipm, df$product, predict(fixed), col = 2:9, lty = 1)