Plotting 3-way interaction of factor variables using `lme4` - r

I'm looking for an elaboration on the amazing answer already provided about creating an interaction plot with a continuous and categorical variable using the predict function of the (development version) of the lme4 package.
I have run a model with an interaction between three categorical variables: discount_i (0/1), rank_i (0/1), and msg ("No norm","Provincial",and "Norm") including subject random effects (id). My outcome variable (choice) is dichotomous. Specifically, my command is:
m1 <- glmer(choice ~ msg*discount_i*rank_i + (1|id), data=df, family="binomial")
I then create a prediction frame:
predframe <- with(df,expand.grid(rank_i=levels(rank_i),msg=levels(msg),discount_i=levels(discount_i)))
And use the predict function (EDITED):
predframe$pred.logit <- predict(m1,newdata=predframe,REform=NA)
However, this is the point where I part ways with #mnel's instructions. How would I go about graphing the three way interaction between factor variables, rather than a two way interaction between a factor variable and a continuous variable?
Sample data below:
> dput(df[1:700,2:6])
structure(list(time = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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1L, 1L, 1L, 2L, 1L, 2L, 2L, 2L,
1L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 1L, 1L,
1L, 2L, 1L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 2L, 2L, 2L, 1L,
1L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 2L, 1L,
1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 2L,
2L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 2L, 2L, 1L, 2L,
1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 1L, 2L, 2L, 2L, 1L, 2L,
1L, 2L, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 2L, 2L, 1L, 1L, 2L, 1L,
2L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 1L, 1L, 1L, 1L,
2L, 1L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L,
1L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 2L, 2L, 2L, 2L,
1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 1L,
2L, 2L, 1L, 2L, 2L, 2L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L,
1L), .Label = c("0", "1"), class = "factor")), .Names = c("time",
"choice", "msg", "discount_i", "rank_i"), row.names = c("1.1",
"2.1", "3.1", "4.1", "5.1", "6.1", "7.1", "8.1", "9.1", "10.1",
"11.1", "12.1", "13.1", "14.1", "15.1", "16.1", "17.1", "18.1",
"19.1", "20.1", "21.1", "22.1", "23.1", "24.1", "25.1", "26.1",
"27.1", "28.1", "29.1", "30.1", "31.1", "32.1", "33.1", "34.1",
"35.1", "36.1", "37.1", "38.1", "39.1", "40.1", "41.1", "42.1",
"43.1", "44.1", "45.1", "46.1", "47.1", "48.1", "49.1", "50.1",
"51.1", "52.1", "53.1", "54.1", "55.1", "56.1", "57.1", "58.1",
"59.1", "60.1", "61.1", "62.1", "63.1", "64.1", "65.1", "66.1",
"67.1", "68.1", "69.1", "70.1", "71.1", "72.1", "73.1", "74.1",
"75.1", "76.1", "77.1", "78.1", "79.1", "80.1", "81.1", "82.1",
"83.1", "84.1", "85.1", "86.1", "87.1", "88.1", "89.1", "90.1",
"91.1", "92.1", "93.1", "94.1", "95.1", "96.1", "97.1", "98.1",
"99.1", "100.1", "101.1", "102.1", "103.1", "104.1", "105.1",
"106.1", "107.1", "108.1", "109.1", "110.1", "111.1", "112.1",
"113.1", "114.1", "115.1", "116.1", "117.1", "118.1", "119.1",
"120.1", "121.1", "122.1", "123.1", "124.1", "125.1", "126.1",
"127.1", "128.1", "129.1", "130.1", "131.1", "132.1", "133.1",
"134.1", "135.1", "136.1", "137.1", "138.1", "139.1", "140.1",
"141.1", "142.1", "143.1", "144.1", "145.1", "146.1", "147.1",
"148.1", "149.1", "150.1", "151.1", "152.1", "153.1", "154.1",
"155.1", "156.1", "157.1", "158.1", "159.1", "160.1", "161.1",
"162.1", "163.1", "164.1", "165.1", "166.1", "167.1", "168.1",
"169.1", "170.1", "171.1", "172.1", "173.1", "174.1", "175.1",
"176.1", "177.1", "178.1", "179.1", "180.1", "181.1", "182.1",
"183.1", "184.1", "185.1", "186.1", "187.1", "188.1", "189.1",
"190.1", "191.1", "192.1", "193.1", "194.1", "195.1", "196.1",
"197.1", "198.1", "199.1", "200.1", "201.1", "202.1", "203.1",
"204.1", "205.1", "206.1", "207.1", "208.1", "209.1", "210.1",
"211.1", "212.1", "213.1", "214.1", "215.1", "216.1", "217.1",
"218.1", "219.1", "220.1", "221.1", "222.1", "223.1", "224.1",
"225.1", "226.1", "227.1", "228.1", "229.1", "230.1", "231.1",
"232.1", "233.1", "234.1", "235.1", "236.1", "237.1", "238.1",
"239.1", "240.1", "241.1", "242.1", "243.1", "244.1", "245.1",
"246.1", "247.1", "248.1", "249.1", "250.1", "251.1", "252.1",
"253.1", "254.1", "255.1", "256.1", "257.1", "258.1", "259.1",
"260.1", "261.1", "262.1", "263.1", "264.1", "265.1", "266.1",
"267.1", "268.1", "269.1", "270.1", "271.1", "272.1", "273.1",
"274.1", "275.1", "276.1", "277.1", "278.1", "279.1", "280.1",
"281.1", "282.1", "283.1", "284.1", "285.1", "286.1", "287.1",
"288.1", "289.1", "290.1", "291.1", "292.1", "293.1", "294.1",
"295.1", "296.1", "297.1", "298.1", "299.1", "300.1", "301.1",
"302.1", "303.1", "304.1", "305.1", "306.1", "307.1", "308.1",
"309.1", "310.1", "311.1", "312.1", "313.1", "314.1", "315.1",
"316.1", "317.1", "318.1", "319.1", "320.1", "321.1", "322.1",
"323.1", "324.1", "325.1", "326.1", "327.1", "328.1", "329.1",
"330.1", "331.1", "332.1", "333.1", "334.1", "335.1", "336.1",
"337.1", "338.1", "339.1", "340.1", "341.1", "342.1", "343.1",
"344.1", "345.1", "346.1", "347.1", "348.1", "349.1", "350.1",
"351.1", "352.1", "353.1", "354.1", "355.1", "356.1", "357.1",
"358.1", "359.1", "360.1", "361.1", "362.1", "363.1", "364.1",
"365.1", "366.1", "367.1", "368.1", "369.1", "370.1", "371.1",
"372.1", "373.1", "374.1", "375.1", "376.1", "377.1", "378.1",
"379.1", "380.1", "381.1", "382.1", "383.1", "384.1", "385.1",
"386.1", "387.1", "388.1", "389.1", "390.1", "391.1", "392.1",
"393.1", "394.1", "395.1", "396.1", "397.1", "398.1", "399.1",
"400.1", "401.1", "402.1", "403.1", "404.1", "405.1", "406.1",
"407.1", "408.1", "409.1", "410.1", "411.1", "412.1", "413.1",
"414.1", "415.1", "416.1", "417.1", "418.1", "419.1", "420.1",
"421.1", "422.1", "423.1", "424.1", "425.1", "426.1", "427.1",
"428.1", "429.1", "430.1", "431.1", "432.1", "433.1", "434.1",
"435.1", "436.1", "437.1", "438.1", "439.1", "440.1", "441.1",
"442.1", "443.1", "444.1", "445.1", "446.1", "447.1", "448.1",
"449.1", "450.1", "451.1", "452.1", "453.1", "454.1", "455.1",
"456.1", "457.1", "458.1", "459.1", "460.1", "461.1", "462.1",
"463.1", "464.1", "465.1", "466.1", "467.1", "468.1", "469.1",
"470.1", "471.1", "472.1", "473.1", "474.1", "475.1", "476.1",
"477.1", "478.1", "479.1", "480.1", "481.1", "482.1", "483.1",
"484.1", "485.1", "486.1", "487.1", "488.1", "489.1", "490.1",
"491.1", "492.1", "493.1", "494.1", "495.1", "496.1", "497.1",
"498.1", "499.1", "500.1", "501.1", "502.1", "503.1", "504.1",
"505.1", "506.1", "507.1", "508.1", "509.1", "510.1", "511.1",
"512.1", "513.1", "514.1", "515.1", "516.1", "517.1", "518.1",
"519.1", "520.1", "521.1", "522.1", "523.1", "524.1", "525.1",
"526.1", "527.1", "528.1", "529.1", "530.1", "531.1", "532.1",
"533.1", "534.1", "535.1", "536.1", "537.1", "538.1", "539.1",
"540.1", "541.1", "542.1", "543.1", "544.1", "545.1", "546.1",
"547.1", "548.1", "549.1", "550.1", "551.1", "552.1", "553.1",
"554.1", "555.1", "556.1", "557.1", "558.1", "559.1", "560.1",
"561.1", "562.1", "563.1", "564.1", "565.1", "566.1", "567.1",
"568.1", "569.1", "570.1", "571.1", "572.1", "573.1", "574.1",
"575.1", "576.1", "577.1", "578.1", "579.1", "580.1", "581.1",
"582.1", "583.1", "584.1", "585.1", "586.1", "587.1", "588.1",
"589.1", "590.1", "591.1", "592.1", "593.1", "594.1", "595.1",
"596.1", "597.1", "598.1", "599.1", "600.1", "601.1", "602.1",
"603.1", "604.1", "605.1", "606.1", "607.1", "608.1", "609.1",
"610.1", "611.1", "612.1", "613.1", "614.1", "615.1", "616.1",
"617.1", "618.1", "619.1", "620.1", "621.1", "622.1", "623.1",
"624.1", "625.1", "626.1", "627.1", "628.1", "629.1", "630.1",
"631.1", "632.1", "633.1", "634.1", "635.1", "636.1", "637.1",
"638.1", "639.1", "640.1", "641.1", "642.1", "643.1", "644.1",
"645.1", "646.1", "647.1", "648.1", "649.1", "650.1", "651.1",
"652.1", "653.1", "654.1", "655.1", "656.1", "657.1", "658.1",
"659.1", "660.1", "661.1", "662.1", "663.1", "664.1", "665.1",
"666.1", "667.1", "668.1", "669.1", "670.1", "671.1", "672.1",
"673.1", "674.1", "675.1", "676.1", "677.1", "678.1", "679.1",
"680.1", "681.1", "682.1", "683.1", "684.1", "685.1", "686.1",
"687.1", "688.1", "689.1", "690.1", "691.1", "692.1", "693.1",
"694.1", "695.1", "696.1", "697.1", "698.1", "699.1", "700.1"
), class = "data.frame")

Caveat: Have not added the ylab="" to the second overlaid plot call and you probably want to use a non-default ylab for the first one, too. Since the details of this analysis are still opaque to me, I am not standing behind its validity. (Just turning the crank on the machinery.) And there would need to be some further work on the legend. Furthermore, teh ylims were different so would probably want to set them to min and max for c(newpred0, newpred1).
newpred0 <- predict(m1, newdata = predframe[predframe$discount_i=="0", ] ,
REform = NA)
interaction.plot(droplevels(predframe[predframe$discount_i=="0", ])$rank_i,
droplevels(predframe[predframe$discount_i=="0", ])$msg,
newpred0)
newpred1 <- predict(m1, newdata = predframe[predframe$discount_i=="1", ] ,
REform = NA)
par(new=TRUE); # This is the way to overlay base graphics on top of each other
interaction.plot(droplevels(predframe[predframe$discount_i=="1", ])$rank_i,
droplevels(predframe[predframe$discount_i=="1", ])$msg, newpred1,
col="red")

Related

How do I check what R used as reference level for my dichotomous outcome in a GEE analysis (using geepack)?

I've got clustered patient data of 700 patients (clustered into two groups for two different hospitals). I'm trying to figure out if a certain cardiovacsular risk factor exposure (factor with 3 levels: fall, stable [reference], and rise) is related to my binary outcome_pres (numeric with 0's for no outcome and 1's for yes outcome), adjusted for age and sex. To do this I've used a GEE model using the geepack package in R:
library(tidyverse)
library(magrittr)
library(geepack)
data <- structure(list(id = c(23, 30, 92, 122, 132, 141, 157, 158, 167,
175, 200, 230, 237, 257, 283, 297, 336, 339, 357, 376, 379, 421,
425, 431, 436, 437, 443, 449, 458, 505, 518, 521, 546, 547, 573,
613, 618, 644, 655, 672, 697, 730, 750, 755, 780, 786, 798, 853,
862, 874, 882, 916, 945, 948, 979, 982, 1002, 1003, 1006, 1022,
1059, 1069, 1092, 1095, 1116, 1127, 1133, 1162, 1178, 1188, 1201,
1210, 1239, 1242, 1258, 1280, 1281, 1297, 1307, 1318, 1331, 1353,
1369, 1383, 1407, 1463, 1473, 1477, 1485, 1519, 1555, 1567, 1573,
1611, 1636, 1659, 1686, 1700, 1712, 1744, 1766, 1767, 1771, 1778,
1797, 1806, 1810, 1821, 1822, 1875, 1879, 1890, 1903, 1917, 1964,
2007, 2010, 2018, 2028, 2067, 2071, 2077, 2078, 2086, 2090, 2103,
2128, 2148, 2185, 2223, 2239, 2257, 2267, 2283, 2300, 2304, 2332,
2395, 2399, 2407, 2427, 2431, 2434, 2440, 2445, 2449, 2480, 2515,
2533, 2536, 2546, 2552, 2635, 2660, 2697, 2705, 2724, 2725, 2728,
2748, 2778, 2794, 2798, 2830, 2843, 2895, 2902, 2907, 2915, 2924,
2929, 2952, 2955, 2963, 2982, 3016, 3018, 3036, 3065, 3083, 3087,
3177, 3178, 3186, 3196, 3199, 3230, 3272, 3278, 3292, 3302, 3304,
3311, 3312, 3351, 3378, 3399, 3401, 3403, 3445, 3447, 3449, 3457,
3472, 3477, 3486, 3490, 3515, 3516, 3519, 3521, 17001, 64001,
128001, 136001, 177001, 177002, 240001, 240001, 248002, 352001,
370002, 410001, 426001, 443002, 443002, 466002, 466002, 469002,
470001, 489002, 520002, 542001, 595001, 615001, 651001, 651002,
657001, 658002, 665001, 665001, 687002, 698002, 745001, 754001,
800002, 804001, 811002, 818001, 881001, 881001, 920001, 927001,
927001, 943001, 974001, 1015002, 1037001, 1081001, 1081002, 1133001,
1136001, 1141001, 1157001, 1175002, 1206001, 1247001, 1247002,
1283001, 1290002, 1296001, 1307001, 1344002, 1346001, 1346001,
1379001, 1419002, 1427001, 1438001, 1592002, 1652002, 1711001,
1754001, 1763001, 1811001, 1833001, 1878002, 1892001, 1915001,
1915002, 1921001, 1949002, 1961001, 1995001, 2014001, 2022002,
2102001, 2102002, 2138002, 2141001, 2141002, 2193002, 2240001,
2281001, 2281002, 2432001, 2493001, 2517001, 2558001, 2558002,
2588001, 2588001, 2590001, 2601001, 2620002, 2653001, 2678001,
2714001, 2721001, 2721002, 2721002, 2731001, 2777001, 2806001,
2813001, 2862001, 2862002, 2872001, 2872002, 2902001, 2959001,
2967001, 3026002, 3026002, 3037001, 3063002, 3094002, 3126002,
3139001, 3196001, 3233001, 3252001, 3282002, 3290002, 3314001,
3334001, 3334001, 3377002, 3420001, 3427001, 3458001, 3532002,
3558001, 3653001, 3663002, 3675002, 3678002, 3692001, 3757002,
3764002, 3764002, 3774001, 3780001, 3823002, 3823002, 3836001,
3862001, 3916001, 3953001, 4032001, 4042001, 4063001, 4077001,
4084001, 4094002, 4118002, 4140002, 4140002, 4149001, 4168004,
4171001, 4241002, 4254001, 4257002, 4269001, 4270001, 4291001,
4298001, 4302002, 4302002, 4325001, 4325001, 4343002, 4353001,
4353001, 4377001, 4422002, 4447002, 4563002, 4568002, 4578001,
4578002, 4601001, 4620002, 4641002, 4673002, 4687001, 4687002,
4695002, 4695002, 4700002, 4707001, 4707001, 4768002, 4802001,
4821001, 4833001, 4839001, 4839001, 4848001, 4854002, 4893002,
4895002, 4918001, 4969001, 4972001, 4985001, 4985001, 4985002,
4991001, 5045001, 5072002, 5181001, 5234002, 5240001, 5361001,
5361002, 5388002, 5400001, 5467002, 5469001, 5528001, 5588001,
5593001, 5643002, 5676001, 5683002, 5690001, 5708002, 5710002,
5722002, 5722002, 5725002, 5770001, 5826001, 5866001, 5869001,
5982002, 5993001, 6039002, 6054002, 6095001, 6095002, 6121003,
6195002, 6258002, 6260002, 6391001, 6391002, 6414001, 6489002,
6552002, 6555002, 6573001, 6578002, 6582002, 6583002, 6583002,
6588001, 6588002, 6625001, 6625002, 6642001, 6660001, 6806002,
6887002, 6888001, 6893002, 6916001, 6916001, 6953002, 6960001,
6960001, 6991002, 7010001, 7010002, 7021001, 7037001, 7037001,
7038001, 7038002, 7089001, 7121001, 7141001, 7150002, 7173002,
7192001, 7220001, 7301002, 7318002, 7339002, 7344002, 7421001,
7436002, 7522002, 7606002, 7653002, 7681001, 7686001, 7759002,
7781001, 7805001, 7816001, 7837002, 7846001, 7856001, 7856002,
7884002, 7934001, 7971002, 7984001, 7995001, 8016002, 8052001,
8064002, 8064003, 8076001, 8109001, 8125001, 8143001, 8144001,
8194001, 8194002, 8218001, 8247001, 8333001, 8360001, 8401001,
8480001, 8545002, 8556001, 8556002, 8596002, 8599001, 8638001,
8751002, 8943002, 9042001, 9075001, 9112002, 9195001, 9404001,
9437001, 9452002, 9456001, 9528001, 9528002, 9535001, 9556001,
9591001), group = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 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2L,
1L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 2L,
1L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 2L,
1L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 2L, 1L,
1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L,
2L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 1L, 2L,
1L, 2L, 1L, 1L, 2L, 1L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 2L,
2L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 2L, 1L, 1L, 2L,
1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L,
2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 1L, 1L,
2L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L,
1L, 1L), .Label = c("1", "2", "3"), class = "factor"), age = c(61.6700889801506,
63.3182751540041, 66.611909650924, 64.435318275154, 63.6796714579055,
64.6351813826146, 60.6351813826146, 63.9780971937029, 70.4394250513347,
63.7700205338809, 62.8583162217659, 64.5859000684463, 70.9733059548255,
63.7125256673511, 63.8466803559206, 91.1813826146475, 86.0342231348392,
75.9069130732375, 63.4496919917864, 63.8056125941136, 67.2388774811773,
64.104038329911, 65.284052019165, 64.4188911704312, 82.2203969883641,
65.0814510609172, 71.4277891854894, 62.2395619438741, 77.7385352498289,
61.5030800821355, 82.3244353182751, 69.5687885010267, 78.0752908966461,
65.3826146475017, 62.9267624914442, 63.6988364134155, 63.2553045859001,
62.1409993155373, 64.6351813826146, 63.1512662559891, 66.3764544832307,
71.5947980835044, 63.2826830937714, 65.9657768651608, 63.6194387405886,
63.4414784394251, 61.5359342915811, 78.031485284052, 63.2772073921971,
64.0219028062971, 79.1950718685832, 61.5468856947296, 65.0403832991102,
59.0006844626968, 88.766598220397, 59.9151266255989, 61.8151950718686,
63.4880219028063, 61.5058179329227, 69.5058179329227, 64.6297056810404,
60.2327173169062, 64.7830253251198, 63.1129363449692, 82.3545516769336,
71.7618069815195, 62.9733059548255, 67.5208761122519, 61.3388090349076,
60.7063655030801, 67.3264887063655, 64.9801505817933, 62.9075975359343,
63.3675564681725, 61.9986310746064, 64.2327173169062, 73.5468856947296,
73.9219712525667, 61.9219712525667, 64.5722108145106, 61.2922655715264,
72.4900752908966, 60.3778234086242, 60.8569472963723, 64.2135523613963,
62.362765229295, 60.4298425735797, 64.1834360027378, 63.8412046543463,
62.9240246406571, 61.5797399041752, 63.8357289527721, 63.1950718685832,
66.8720054757016, 62.5242984257358, 73.5687885010267, 64.2245037645448,
63.8576317590691, 63.8494182067077, 61.2621492128679, 73.927446954141,
64.4490075290897, 61.741273100616, 62.6803559206023, 61.5112936344969,
64.3011635865845, 61.2539356605065, 63.4962354551677, 72.2026009582478,
61.4620123203285, 67.917864476386, 70.7871321013005, 66.2313483915127,
61.9055441478439, 62.5653661875428, 79.7262149212868, 61.1143052703628,
61.9192334017796, 63.0554414784394, 72.3586584531143, 63.4140999315537,
61.9247091033539, 71.3620807665982, 65.1553730321697, 64.6461327857632,
61.9000684462697, 63.5619438740589, 73.6317590691307, 61.5195071868583,
62.9514031485284, 64.3066392881588, 61.3278576317591, 68.9418206707734,
62.7652292950034, 83.7289527720739, 62.9295003422313, 61.596167008898,
64.8925393566051, 68.6187542778919, 61.0102669404517, 67.2580424366872,
63.2251882272416, 61.1416837782341, 63.5181382614647, 63.0444900752909,
61.4236824093087, 75.6194387405886, 63.6878850102669, 63.937029431896,
63.2936344969199, 63.8877481177276, 86.984257357974, 77.6673511293635,
62.0752908966461, 75.668720054757, 63.5482546201232, 61.8617385352498,
79.0581793292266, 81.3333333333333, 73.3415468856947, 63.8658453114305,
64.7693360711841, 62.7843942505133, 81.0759753593429, 63.460643394935,
61.3963039014374, 61.6262833675565, 84.4271047227926, 61.2073921971253,
63.4661190965092, 62.8829568788501, 74.9787816563997, 64.662559890486,
64.5338809034908, 62.1054072553046, 63.6878850102669, 66.4832306639288,
64.6899383983573, 80.7529089664613, 61.7960301163587, 64.3832991101985,
63.4442162902122, 63.9342915811088, 63.1978097193703, 72.662559890486,
69.1225188227242, 63.2908966461328, 60.1943874058864, 61.3853524982888,
61.1498973305955, 61.3689253935661, 61.1800136892539, 61.596167008898,
60.7200547570157, 60.3148528405202, 60.6981519507187, 60.4681724845996,
61.1581108829569, 60.662559890486, 61.0212183436003, 60.5776865160849,
60.8323066392882, 61.0075290896646, 60.7775496235455, 61.1745379876797,
59.9780971937029, 60.4626967830253, 60.6297056810404, 61.5852156057495,
60.7830253251198, 61.7029431895962, 69.2375085557837, 71.4414784394251,
67.4770704996578, 67.4305270362765, 61.0075290896646, 59.4743326488706,
67.8275154004107, 72.9062286105407, 65.7604380561259, 57.7330595482546,
63.7618069815195, 66.1300479123888, 69.242984257358, 71.8302532511978,
76.7720739219713, 57.201916495551, 62.1629021218344, 67.2142368240931,
59.4907597535934, 58.0752908966461, 75.8658453114305, 74.5927446954141,
63.0006844626968, 67.9972621492129, 60.2135523613963, 59.7015742642026,
65.1909650924025, 61.4565366187543, 60.2874743326489, 65.4401095140315,
56.8131416837782, 72.5612594113621, 66.6201232032854, 66.0561259411362,
68.4818617385352, 67.315537303217, 70.3600273785079, 68.3832991101985,
57.9000684462697, 62.90212183436, 70.7405886379192, 72.7063655030801,
77.5058179329227, 64.2217659137577, 57.2731006160164, 67.5509924709103,
68.4407939767283, 60.3449691991786, 60.0246406570842, 62.6721423682409,
60.9637234770705, 69.9931553730322, 69.6481861738535, 57.9438740588638,
61.2046543463381, 58.154688569473, 58.0752908966461, 71.0992470910335,
65.0212183436003, 56.6762491444216, 65.4592744695414, 65.7494866529774,
68.0164271047228, 72.788501026694, 70.7077344284736, 63.5564681724846,
66.7843942505133, 63.0444900752909, 65.845311430527, 69.07871321013,
63.3976728268309, 59.1375770020534, 67.356605065024, 67.0937713894593,
60.9719370294319, 74.90212183436, 66.0807665982204, 68.8514715947981,
68.4462696783025, 66.2422997946612, 61.9247091033539, 58.3545516769336,
65.0485968514716, 66.1081451060917, 68.870636550308, 64.1396303901437,
58.1218343600274, 64.5420944558522, 67.1622176591376, 66.6283367556468,
73.7467488021903, 64.4873374401095, 69.45106091718, 63.7289527720739,
87.8439425051335, 66.984257357974, 61.6427104722793, 63.7453798767967,
59.5592060232717, 58.8254620123203, 63.5482546201232, 73.7522245037646,
57.6563997262149, 70.2642026009582, 66.6365503080082, 71.2388774811773,
69.347022587269, 60.1642710472279, 59.9397672826831, 64.4462696783025,
67.3620807665982, 65.3278576317591, 64.8213552361396, 69.6618754277892,
69.5249828884326, 61.3607118412047, 68.5694729637235, 62.8172484599589,
58.113620807666, 67.2854209445585, 68.3039014373717, 63.4579055441478,
68.539356605065, 66.5735797399042, 64.5256673511294, 66.1902806297057,
63.356605065024, 71.7316906228611, 67.3867214236824, 65.5715263518138,
77.2156057494867, 72.2984257357974, 64.4407939767283, 74.0150581793292,
73.2731006160164, 77.7166324435318, 61.3169062286105, 66.7898699520876,
69.1772758384668, 71.3675564681725, 64.104038329911, 68.1286789869952,
71.0362765229295, 60.643394934976, 68.6899383983573, 66.9924709103354,
65.2785763175907, 58.3134839151266, 64.2956878850103, 69.2676249144422,
70.4531143052704, 66.1218343600274, 60.7693360711841, 65.6399726214921,
67.605749486653, 67.1567419575633, 67.6632443531827, 66.4832306639288,
63.7590691307324, 65.6810403832991, 74.5653661875428, 65.7275838466804,
67.3538672142368, 67.7700205338809, 65.1745379876797, 61.8370978781656,
66.6036960985626, 59.0280629705681, 65.7987679671458, 61.0020533880903,
59.8658453114305, 68.2847364818617, 67.2005475701574, 68.1697467488022,
66.0862422997947, 61.9356605065024, 68.1314168377823, 65.0540725530459,
69.45106091718, 70.2313483915127, 75.1594798083504, 81.1444216290212,
60.4188911704312, 65.2457221081451, 67.8412046543463, 69.9082819986311,
61.9438740588638, 88.2108145106092, 69.574264202601, 70.3737166324435,
67.7344284736482, 66.2368240930869, 65.1225188227242, 61.7357973990418,
81.6317590691307, 63.1567419575633, 61.8726899383984, 57.3223819301848,
62.3463381245722, 70.1273100616016, 63.6358658453114, 69.4620123203285,
70.113620807666, 67.7234770704997, 66.7515400410678, 72.8870636550308,
69.2101300479124, 74.0068446269678, 72.7310061601643, 66.0041067761807,
62.7707049965777, 63.5783709787817, 67.501711156742, 66.4339493497604,
67.1375770020534, 64.5941136208077, 69.4674880219028, 66.466803559206,
80.7501711156742, 62.2258726899384, 61.3141683778234, 66.4503764544832,
66.1409993155373, 73.0458590006845, 67.7180013689254, 65.7166324435318,
68.2518822724162, 70.2094455852156, 70.2532511978097, 65.347022587269,
69.9986310746064, 68.5831622176591, 62.7843942505133, 63.006160164271,
65.45106091718, 70.5845311430527, 88.9308692676249, 75.7399041752224,
62.2231348391513, 56.7775496235455, 61.3935660506502, 69.0239561943874,
65.3415468856947, 66.0232717316906, 71.7700205338809, 66.4120465434634,
68.8788501026694, 60.6379192334018, 67.0225872689938, 63.5537303216975,
64.1724845995893, 64.1670088980151, 67.8001368925394, 68.7200547570157,
66.4996577686516, 62.9267624914442, 79.1403148528405, 71.6659822039699,
62.3326488706366, 71.1019849418207, 62.3408624229979, 65.3579739904175,
78.2067077344285, 63.0171115674196, 66.6365503080082, 63.8740588637919,
68.6899383983573, 68.4188911704312, 66.0260095824778, 67.5482546201232,
65.9329226557153, 59.9534565366188, 71.9452429842574, 68.4161533196441,
70.6420260095825, 63.2991101984942, 71.6249144421629, 60.6789869952088,
65.6810403832991, 65.347022587269, 62.4558521560575, 67.5318275154004,
64.9281314168378, 67.129363449692, 67.3292265571526, 65.2375085557837,
59.2881587953457, 64.1396303901437, 65.7713894592745, 65.7166324435318,
60.4818617385353, 66.5215605749487, 72.8186173853525, 68.6789869952088,
65.678302532512, 74.5790554414784, 64.1505817932923, 65.7166324435318,
57.7494866529774, 62.0150581793292, 62.0752908966461, 74.135523613963,
67.64681724846, 72.4900752908966, 65.8891170431211, 76.9308692676249,
68.4709103353867, 66.3983572895277, 69.5605749486653, 66.6721423682409,
65.0403832991102, 67.6386036960986, 67.5318275154004, 62.54893908282,
78.0041067761807, 77.0184804928131, 66.4914442162902, 80.8049281314168,
65.3251197809719, 75.2087611225188, 66.7241615331964, 56.6078028747433,
65.7713894592745, 70.611909650924, 66.6721423682409, 72.227241615332,
77.3114305270363, 82.2450376454483, 65.0294318959617, 63.315537303217,
71.0499657768652, 62.4722792607803, 62.7186858316222, 63.5373032169747,
69.4866529774127, 66.839151266256, 65.4647501711157, 66.8911704312115,
78.403832991102, 65.8590006844627, 64.2765229295003, 79.9671457905544,
85.07871321013, 66.7515400410678, 75.211498973306, 71.3620807665982,
72.2628336755647, 64.9363449691992, 77.9493497604381, 58.5817932922656,
70.2258726899384, 76.0191649555099, 68.4928131416838, 69.1143052703628,
69.3388090349076, 71.7262149212868, 90.9650924024641, 67.7043121149897,
77.9301848049281), sex = structure(c(1L, 1L, 1L, 1L, 1L, 2L,
1L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
2L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 1L, 2L, 2L, 1L, 2L, 2L, 1L,
1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 2L, 1L, 1L,
1L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 1L,
1L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0,
0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,
1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0,
1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1,
1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1,
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,
1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1,
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)), row.names = c(NA,
-570L), class = c("tbl_df", "tbl", "data.frame"))
And the model
model <- geeglm(formula=outcome_pres~exposure+sex+age, data=data, id=id, family=binomial("logit"), corstr="ar1")
How do I check if R actually used the 0's of outcome_pres as the reference category in this analysis?
I think you are misunderstanding something here. outcome_pres is your outcome, which you define as a binomial distribution, and has the values 0 and 1:
str(data)
tibble [570 x 6] (S3: tbl_df/tbl/data.frame)
$ id : num [1:570] 23 30 92 122 132 141 157 158 167 175 ...
$ group : Factor w/ 3 levels "1","2","3": 1 1 1 1 1 1 1 1 1 1 ...
$ age : num [1:570] 61.7 63.3 66.6 64.4 63.7 ...
$ sex : Factor w/ 2 levels "Women","Men": 1 1 1 1 1 2 1 2 1 1 ...
$ exposure : Factor w/ 3 levels "Stable","Fall",..: 1 1 1 3 1 3 1 1 1 1 ...
$ outcome_pres: num [1:570] 1 1 1 1 1 0 1 1 1 1 ...
There are no reference category in this case.
If your question is how do I know what is the reference category of my exposure, then you can see it directly in the summary of your model:
summary(model)
Call:
geeglm(formula = outcome_pres ~ exposure + sex + age, family = binomial("logit"),
data = data, id = id, corstr = "ar1")
Coefficients:
Estimate Std.err Wald Pr(>|W|)
(Intercept) -3.652686 1.826395 4.00 0.0455 *
exposureFall 0.718930 0.444144 2.62 0.1055
exposureRise -0.854571 0.325662 6.89 0.0087 **
sexMen 0.000538 0.242922 0.00 0.9982
age 0.080847 0.028230 8.20 0.0042 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
You have exposureFall and exposureRise, meaning that your reference is the category not present in the summary, that is stable:
data$exposure %>% unique()
[1] Stable Rise Fall
Levels: Stable Fall Rise
Rise has thus a protective effect (your Odd ratio is exp(-0.854571)) compared to stable

Is there a way to run multiple t.tests that produce results that can be easily stored in table format?

I'm working with a set of data that I want to subset and compare t-tests for. The end goal is to have an easily readable table as an output that can be presented to a reader.
Currently I am using individual t-tests that give results one at a time, such as the code below.
t.test(survey$numericDV[survey$condition == 0 & survey$partisan_guess == "Republican"], survey$numericDV[survey$condition == 1 & survey$partisan_guess == "Republican"])
$condition is a factor variable with 5 levels from 0 to 4,and $partisan_guess is a factor with 2 levels. The goal is to run t-tests comparing condition == 0 against the other 4 levels, with the ability to specify which level of partisan_guess to use.
Is there a way to run each of these tests simultaneously that stores the results in a table, i.e. I would get table that lists the result of a t-test of Condition 0 against Condition 1, Condition 0 against Condition 2, etc.
Thanks in advance for the help!
Minimum replicable data:
survey <- structure(list(numericDVedu = c(0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0,
1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1,
0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1,
0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1,
0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0,
0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0,
0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1,
1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0,
0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0,
0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1,
1, 0, 1, 0, 0, 0, 1, 0,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2L, 2L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 2L,
2L, 2L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 2L, 1L, 2L, 2L, 2L,
2L, 1L, 1L, 2L, 1L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 1L, 2L, 1L,
2L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 1L,
2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 1L,
2L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 2L, 1L, 1L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L,
2L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 2L, 1L, 1L,
1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 1L, 2L,
2L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 2L, 1L, 1L,
2L, 2L, 1L, 2L, 1L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 2L,
1L, 1L, 2L, 2L, 2L, 2L, 1L, 2L), .Label = c("Democrat", "Republican"
), class = "factor")), class = "data.frame", row.names = c(NA, -330L))
We can write a function to apply t.test for every condition against condition 0.
run_t_test <- function(data, partisan_guess) {
data <- subset(data, partisan_guess == partisan_guess)
zero_data <- data$numericDV[survey$condition == 0]
purrr::map_df(1:4, function(x) broom::tidy(t.test(
zero_data, data$numericDV[survey$condition == x])), .id = 'condition')
}
run_t_test(survey, 'Republican')
# A tibble: 4 x 11
# condition estimate estimate1 estimate2 statistic p.value parameter conf.low
# <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#1 1 -0.0490 0.333 0.382 -0.588 0.557 132. -0.214
#2 2 -0.113 0.333 0.446 -1.32 0.188 128. -0.282
#3 3 0.0635 0.333 0.270 0.782 0.436 127. -0.0972
#4 4 0.0980 0.333 0.235 1.25 0.212 130. -0.0565
# … with 3 more variables: conf.high <dbl>, method <chr>, alternative <chr>
run_t_test(survey, 'Democrat')
# A tibble: 4 x 11
# condition estimate estimate1 estimate2 statistic p.value parameter conf.low
# <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#1 1 -0.0490 0.333 0.382 -0.588 0.557 132. -0.214
#2 2 -0.113 0.333 0.446 -1.32 0.188 128. -0.282
#3 3 0.0635 0.333 0.270 0.782 0.436 127. -0.0972
#4 4 0.0980 0.333 0.235 1.25 0.212 130. -0.0565
# … with 3 more variables: conf.high <dbl>, method <chr>, alternative <chr>

How to make a stacked barplot with nested grouping variables?

I am trying to make a stacked barplot with two variables. My desired outcome looks like this:
This is the first part of my data. There are 220 more rows:
Type Week Stage
<chr> <dbl> <dbl>
1 Captured 1 2
2 Captured 1 1
3 Captured 1 1
4 Captured 1 2
5 Captured 1 1
6 Captured 1 3
7 Captured 1 NA
8 Captured 1 3
9 Captured 1 2
10 Captured 1 1
So far I'm not getting anywhere, this is my code so far
library(data.table)
dat.m <- melt(newrstudio2, id.vars="Type")
dat.m
library(ggplot2)
ggplot(dat.m, aes(x=Type, y=value, fill=variable)) +
geom_bar(stat="identity")
I guess I need to calculate the number of observations of each stage in each week of each type? I've tried both long and wide data, but I somehow need to combine week with type? I don't know, I'm at a loss.
Alternative way:
set.seed(123)
# sample data
my_data <- data.frame(Type = sample(c("W", "C"), 220, replace = TRUE),
Week = sample(paste0("Week ", 1:4), 220, replace = TRUE),
Stage = sample(paste0('S', 1:4), 220, replace = TRUE))
head(my_data)
library(ggplot2)
ggplot(my_data, aes(x = Type, fill = Stage)) +
geom_bar(aes(y = (..count..)/sum(..count..)), position = "fill") +
facet_grid(. ~ Week, switch="both") +
scale_y_continuous(labels = scales::percent) +
ylab("Stage [%]") +
theme(strip.background = element_blank(),
strip.placement = "outside",
panel.spacing = unit(0, "lines"))
Alternatively we could use base graphics. First, what you're probably most interested in, we should reshape the data.
For this we could split the data per week and run a dcast() over it.
L <- lapply(split(d, d$week), function(x)
data.table::dcast(x, type ~ stage, value.var="stage", fun=length))
d2 <- do.call(rbind, L) # transform back into a data frame
Now – with credits to #alemol – we want the proportions.
d2[-1] <- t(apply(d2[-1], 1, prop.table))
Then we are able to plot relatively simply. Note, that barplot() additionally gives us a vector of bar coordinates which we can use later for the axis() labels.
cols <- c("#ed1c24", "#ff7f27", "#00a2e8", "#fff200") # define stage colors
par(mar=c(5, 5, 3, 5) + .1, xpd=TRUE) # set plot margins
p <- barplot(t(d2[-1]), col=cols, border="white", space=rep(c(.2, 0), 5),
font.axis=2, xaxt="n", yaxt="n", xlab="Week")
axis(1, at=p, labels=rep(c("C", "W"), 5), tick=FALSE, line=0)
axis(1, at=apply(matrix(p, , 2, byrow=TRUE), 1, mean), labels=1:5, tick=FALSE, line=1)
axis(2, at=0:10/10, labels=paste0(seq(0, 100, 10), "%"), line=0, las=2)
legend(12, .5, legend=rev(names(d2[-1])), col=rev(cols), pch=15, title="Stage")
Result:
Data:
d <- structure(list(type = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L,
2L, 2L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 2L,
1L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 2L,
2L, 2L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 2L,
2L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 1L,
2L, 1L, 1L, 1L, 2L, 1L, 2L, 2L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 2L,
1L,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 3L, 3L, 3L, 3L, 2L,
1L, 2L, 2L, 1L, 1L, 3L, 4L, 3L, 4L, 2L, 4L, 1L, 1L, 2L, 1L, 3L,
2L, 1L, 3L, 3L, 2L, 2L, 1L, 3L, 2L, 2L, 2L, 1L, 4L, 2L, 4L, 2L,
4L, 3L, 3L, 1L, 3L, 4L, 3L, 2L, 1L, 2L, 4L, 1L, 2L, 4L, 2L, 1L,
2L, 1L, 2L, 2L, 3L, 1L, 3L, 3L, 3L, 2L, 2L, 1L, 2L, 3L, 2L, 2L,
1L, 2L, 1L, 3L, 3L, 2L, 1L, 3L, 4L, 2L, 1L, 2L, 4L, 3L, 4L, 2L,
3L, 2L, 4L, 1L, 4L, 4L, 2L, 1L, 2L)), row.names = c(NA, -250L
), class = "data.frame")
Is this what you're looking for:
set.seed(123)
# sample data
my_data <- data.frame(Type = sample(paste0('T', 1:4), 220, replace = TRUE),
Week = sample(paste0('W', 1:4), 220, replace = TRUE),
Stage = sample(paste0('S', 1:4), 220, replace = TRUE))
ggplot(my_data, aes(x=Week:Type, fill = Stage)) + geom_bar()

Trying to run a simple logistic regression without luck

I am trying to run a logistic regression on a small data set, but after going at it for three weeks I am about to give up. I have been getting a range of error messages and I am now even having doubts whether my R engine is working as it should. DPUT of my data looks like this:
structure(list(SEASON = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L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, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 1L, 1L, 3L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 3L), .Label = c("0", "1", "NA"), class = "factor"),
as.is = c(TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
TRUE)), .Names = c("SEASON", "OO_OBS", "HW_OBS", "F_OO",
"F_HW", "INIT_OO", "INIT_HW", "INIT_BOTH", "as.is"), row.names = c(NA,
-119L), class = "data.frame")
These variables are all factors with two levels, except SEASON, that has three levels.
I want to run a logistic regression where "F_HW" is the response variable and "SEASON" and "F_OO" are dependent variables. This is the script I have been trying to run, which should be really simple, but it doesn't work (my data object is called feed.df):
feed.df$SEASON <- as.factor(feed.df$SEASON)
feed.df$F_OO <- as.factor(feed.df$F_OO)
feed.df$FEED_HW <- as.factor(feed.df$FEED_HW)
attach(feed.df)
ml <- glm(F_HW ~ SEASON + F_OO, family=binomial)
lm.out = glm(F_HW ~ SEASON + F_OO, family=binomial)
summary (lm.out)

R scatterplot3d: a custom axis step and ticks

Greeting to all.
I am striving with a scatterplot3d plot -- a graphical representation of a data.frame of three variables where one of them is a response variable, where I have a wrong representation of the axis steps. Here is the code ("temp" is a data.frame):
library(scatterplot3d)
temp[,1] <- as.numeric(levels(temp[,1]))[temp[,1]]
for (m in temp[,2]) m <- as.factor(as.numeric(m))
for (m in temp[,3]) m <- as.factor(as.numeric(m))
colnames(temp) = c("Values", "Factors", "AntiFactors") # "Values" is that responce variable
xtickmarks<-c("AntiFactor1","AntiFactor1", "AntiFactor3")
ytickmarks<-c("Factor1","Factor2")
plot3d <- scatterplot3d(temp[,3], temp[,2], temp[,1], color = "blue",
pch = 19, type = "h", box = T, xaxt = "n",
x.ticklabs=xtickmarks, y.ticklabs=ytickmarks,
zlab = "Time, min.")
dput(temp)
structure(list(Values = c(395, 310, 235, 290, 240, 490, 270,
225, 430, 385, 170, 55, 295, 320, 270, 130, 300, 285, 130, 200,
225, 90, 205, 340, 3, 8, 1, 0, 0, 0, 3, 2, 5, 2, 3, 5, 2, 3,
200, 5, 5, 10, 5, 5, 5, 10, 10, 130, 5, 200, 80, 10, 360, 10,
5, 8, 30, 8, 10, 10, 10, 5, 240, 120, 3, 10, 25, 5, 5, 10, 190,
30, 115, 1, 1, 1, 2, 3, 5, 2, 5, 3, 3, 3, 2, 3, 2, 3, 0, 0, 195,
150, 2, 2, 0, 2, 1, 1, 2, 1, 2, 1, 1, 1, 3, 2, 2, 1, 2, 2, 1,
1, 2, 3, 2, 2, 1, 3, 1, 1), Factors = structure(c(1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L), .Label = c("Factor1", "Factor2"), class = "factor"),
AntiFactors = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("AntiFactor1", "AntiFactor2",
"AntiFactor3"), class = "factor")), .Names = c("Values",
"Factors", "AntiFactors"), row.names = c(NA, -120L), class = "data.frame")
Here is the picture of that plot I got:
The trouble is what I got twice more ticks at the x and y axis than it is needed. It is intended to have just one set of those Factor1..2 and AntiFactor1..3 ticks at each of those x, y axis. If I run that scatterplot3d without using x.ticklabs option, it gives "0, 0.5, 1, 1.5, 2.0, ...3.0" ticks etc at the axis. What is the way to set my step in x, y axis to be just a strong integer "1", so that all my discrete ticks to be displayed in their right place?
It seems that scatterplot3d coerces your discrete explanatory variables 'Factor' and 'AntiFactor' from factor to numeric. See e.g.:
levels(df$Factors)
# [1] "Factor1" "Factor2"
unique(as.numeric(df$Factors))
# [1] 1 2
levels(df$AntiFactors)
# [1] "AntiFactor1" "AntiFactor2" "AntiFactor3"
unique(as.numeric(df$AntiFactors))
# [1] 1 2 3
The labels you have created are recycled to get a label at each (default) tick mark. Also note your typo in 'xtickmarks' - I assume the second 'AntiFactor1' should be 'AntiFactor2'.
You may consider alternative ways to visualize your data, e.g. something like this:
library(ggplot2)
ggplot(data = temp, aes(x = AntiFactors, y = Values, fill = Factors)) +
geom_boxplot()

Resources