diff --git a/materials/tutorial_04/data/facebook_data.csv b/materials/tutorial_04/data/facebook_data.csv
new file mode 100644
index 0000000..e0cea71
--- /dev/null
+++ b/materials/tutorial_04/data/facebook_data.csv
@@ -0,0 +1,492 @@
+total_engagement_percentage,page_engagement_percentage,share_percentage,comment_percentage,post_category
+6.4680233,7.2560976,17,4,Product
+13.9292543,18.1282723,17.6829268,3.0487805,Product
+7.3352673,8.7824351,17.5,0,Inspiration
+4.4107086,4.3247629,8.2723692,3.263928,Product
+9.2628382,12.375,12.4681934,4.8346056,Product
+11.3731856,12.9393785,17.7419355,0.5376344,Product
+4.1139241,4.063036,9.6774194,1.0752688,Inspiration
+3.9139942,3.816932,4.1297935,0,Inspiration
+12.9179331,15.7987867,16.1458333,0,Product
+5.9650618,8.5628227,18.3098592,2.1126761,Inspiration
+19.5824135,20.0401013,7.5396825,0,Product
+6.6838046,7.5896964,16.9811321,0,Product
+6.7790657,7.3359073,13.4615385,0,Product
+9.7685367,9.5461659,6.5789474,3.2894737,Product
+3.8930829,3.5418393,3.3388982,0.3338898,Product
+12.5646123,13.5938231,16.6666667,3.7037037,Product
+9.4657375,11.7142857,22.2222222,3.7037037,Inspiration
+3.2029138,3.285901,2.8050491,2.1037868,Action
+3.307888,4.1908714,22.6666667,5.3333333,Inspiration
+7.6052797,8.6132644,19.047619,0,Inspiration
+7.0224719,7.9979623,14.8148148,3.7037037,Product
+3.4163289,3.4193548,11.1111111,0,Action
+6.4634594,8.821715,25,0,Inspiration
+15.7987747,18.9740656,15.7024793,2.4793388,Product
+18.3606953,22.3380491,16.9811321,0,Product
+14.351473,18.1087134,14.5748988,2.0242915,Product
+8.5552865,11.5038115,14.5299145,0,Inspiration
+10.1778243,13.0791912,10.1286174,5.7877814,Product
+3.1512373,3.9611678,7.4712644,10.3448276,Action
+7.7935223,9.3174061,13.5802469,20.3703704,Product
+11.4081996,15.2680653,28.2051282,2.5641026,Product
+6.969697,11.0652353,23.0392157,0.9803922,Inspiration
+8.9273817,11.575179,18.4,3.2,Inspiration
+7.9129049,8.3049694,22.6666667,2.6666667,Action
+9.375,10.6973595,10.5527638,3.0150754,Product
+9.3680297,11.522872,15.0442478,0,Inspiration
+2.4191919,9.0116279,8,16,Action
+30.4506145,34.8032564,11.5241636,4.0892193,Product
+9.3009119,9.5588235,23.7288136,1.6949153,Action
+15.4743976,18.364726,14.8854962,2.6717557,Product
+2.797619,4.7245261,8.5308057,2.8436019,Action
+28.7149147,27.8325817,8.3333333,19.4444444,Action
+5.0661626,7.3347858,21.7391304,15.2173913,Action
+8.286648,8.007705,18.9655172,0,Action
+2.5853414,3.95189,14.084507,5.6338028,Action
+21.5492278,23.3860956,16.8224299,1.8691589,Action
+5.038961,6.5254237,25,18.75,Action
+8.9276281,8.7064677,16.3043478,0,Action
+5.46875,5.4015636,7.1428571,7.1428571,Action
+6.25,6.25,15.5172414,1.7241379,Product
+2.8754753,5.2393123,8.3086053,7.1216617,Action
+7.2537801,9.0707965,12.8099174,3.7190083,Action
+8.0749574,9.8336595,21.8390805,4.5977011,Action
+10.7216495,11.589404,15.6626506,4.8192771,Action
+2.7960526,3.7938963,17.2839506,2.4691358,Action
+5.9015829,8.683068,24.5454545,0.9090909,Action
+6.4833006,7.0489216,24.5283019,0,Action
+10.1905184,10.7899807,12.2222222,3.3333333,Action
+1.5551123,2.7079901,10.625,2.5,Action
+3.8117002,6.254902,11.3821138,6.504065,Action
+1.2374293,2.7235516,6.1728395,4.9382716,Action
+2.7893712,5.472103,6.4356436,4.950495,Action
+1.9878013,4.0592784,8.9795918,1.6326531,Action
+9.8639456,10.278251,10.1449275,2.8985507,Action
+10.4215457,11.7252931,19.3277311,15.9663866,Action
+9.1670544,9.8170732,12.7272727,0,Action
+2.9482191,5.9281116,8.8945362,2.5412961,Action
+9.7324723,11.1111111,24.2857143,0,Action
+11.6054159,15.4494382,23.5294118,5.8823529,Action
+1.49451,2.9494382,5.5555556,4.3209877,Action
+2.0849873,4.6875,15.2727273,3.0909091,Action
+11.1086572,14.2857143,16.1172161,1.0989011,Inspiration
+4.8497029,10.1388889,20.1716738,6.0085837,Action
+3.8171884,3.8010204,11.4035088,1.754386,Action
+3.0768408,6.6544118,14.6534653,3.960396,Action
+1.9056735,5.273752,8.2474227,4.1237113,Action
+15.017301,15.3233831,12.5,0,Product
+17.5279702,18.5483871,18.4210526,5.2631579,Action
+26.2946838,28.5811547,12.8712871,1.980198,Product
+10.9682805,16.2861492,12.0181406,4.0816327,Inspiration
+9.908337,17.7119628,22.6190476,1.984127,Action
+10.9257999,12.7705628,15.5737705,1.6393443,Inspiration
+2.9736999,4.676259,13.6752137,1.7094017,Inspiration
+14.964926,14.7286822,5.0632911,6.3291139,Action
+1.558368,3.5251524,19.0184049,1.2269939,Action
+13.7088734,18.1695221,12.2186495,0.9646302,Inspiration
+13.8471587,20.7246377,15.3846154,7.6923077,Action
+12.7297481,13.8113571,13.4920635,1.5873016,Action
+3.4182848,6.2068966,18.2897862,3.087886,Action
+12.9337539,14.7826087,14.2857143,0,Product
+12.8275571,14.190051,9.3567251,2.6315789,Inspiration
+13.9325843,16.774658,12.4031008,1.5503876,Inspiration
+12.033511,15.2024922,14.8648649,1.3513514,Product
+12.6537217,16.3140312,14.5945946,2.7027027,Inspiration
+29.4277929,31.25,16.9230769,4.6153846,Action
+11.280596,14.7965475,18.3098592,0.7042254,Product
+17.1880013,21.7522263,16.1375661,1.8518519,Product
+6.1443331,7.3717949,20.9302326,2.7906977,Action
+3.8086391,6.8245968,5.8425584,1.599016,Product
+16.8322618,18.3363148,17.721519,2.5316456,Inspiration
+16.1383285,14.1680395,23.5294118,0,Action
+13.4971645,12.6130414,12.5,5.5555556,Action
+4.584854,7.4825311,12.2359155,3.6971831,Action
+12.3026674,17.3544974,14.4144144,4.0540541,Inspiration
+11.9107744,12.8807773,11.7647059,7.1428571,Product
+13.1904369,14.7268409,10.8108108,4.7297297,Inspiration
+19.2041522,21.5874233,18.4501845,1.4760148,Product
+20.2032277,18.2437032,11.7647059,5.8823529,Action
+12.8088962,15.1282051,12.9496403,2.8776978,Product
+16.5693758,17.9788484,16.4948454,2.0618557,Product
+23.241206,22.4896836,11.7647059,0,Action
+39.7293973,40.2877698,33.3333333,0,Action
+5.6197218,5.4474216,5.6768559,0.2183406,Action
+41.563786,40.3076923,0,0,Action
+47.8417266,49.8579545,22.2222222,0,Action
+33.4605598,33.6363636,25,0,Action
+17.2799697,19.8203492,17.2413793,2.5862069,Product
+41.5185784,42.0542636,50,25,Action
+37.1150729,36.6602687,33.3333333,16.6666667,Action
+34.859675,33.7931034,22.2222222,0,Action
+14.0819964,22.9988053,16.9421488,1.2396694,Inspiration
+30.2543507,30.6962025,10,0,Action
+30.2325581,29.9638989,20,0,Action
+27.3209549,25.3623188,0,0,Action
+22.7472527,22.5063939,20,0,Action
+22.2222222,20.5414013,30,0,Action
+30.1972686,29.3402778,20,10,Action
+32.8220859,30.952381,8.3333333,0,Action
+24.85482,25.1046025,11.7647059,5.8823529,Action
+11.4905149,11.4589666,17.6470588,0,Action
+4.373928,5.2045728,33.3333333,0,Action
+19.4444444,19.7002141,7.6923077,10.2564103,Action
+16.6366906,18.4045584,16.2337662,0,Product
+10.6520657,11.7312834,19,4,Action
+1.4958256,7.9058765,21.7821782,7.4257426,Action
+19.3354623,22.1595331,13.5849057,0.754717,Inspiration
+19.7970195,24.2464539,8.9197225,5.9464817,Product
+4.2560801,9.516129,13.4228188,2.2371365,Inspiration
+2.8815831,8.1983025,16.9811321,5.6603774,Action
+9.9173554,11.050814,14.5833333,6.25,Action
+2.3233996,12.5,7.3529412,0,Inspiration
+13.2256656,14.6836912,14.893617,0,Inspiration
+18.3078928,20.4596162,15.6424581,1.6759777,Product
+3.0696903,4.3498597,31.4285714,0,Action
+5.2646058,7.5440735,11.1716621,6.5395095,Action
+11.8952618,14.9872989,16,1,Product
+12.2790981,13.9910537,10.7929515,10.3524229,Product
+9.4403158,8.7402886,12.9533679,3.626943,Action
+13.3979885,16.9829222,14.2118863,3.3591731,Product
+19.1097923,24.8688353,22.8571429,0,Product
+12.486688,14.2801252,18.404908,9.8159509,Product
+14.6837349,17.9442509,15.3284672,0.729927,Inspiration
+12.22965,14.827168,13.8888889,11.9047619,Product
+16.836983,18.3808892,13.2653061,1.0204082,Product
+8.0669224,8.6039886,9.7799511,1.4669927,Inspiration
+14.9799599,17.9752066,11.3475177,2.1276596,Product
+10.2369542,16.2576687,23.902439,5.3658537,Inspiration
+16.609589,19.7536946,14.2361111,1.3888889,Product
+15.5913978,17.5587794,14.3939394,0,Product
+3.7456697,4.2917034,5.952381,2.3809524,Action
+8.2992185,9.2339979,11.4901257,1.4362657,Inspiration
+8.0268674,10.1586391,10.5369807,7.2948328,Action
+18.0412371,19.8924731,13.2231405,4.9586777,Product
+12.7678571,15.3846154,11.9815668,1.3824885,Inspiration
+23.331173,21.742671,15.7894737,5.2631579,Action
+22.7700414,24.5452478,11.8421053,16.6666667,Product
+12.1543265,15.8374793,17.7777778,2.6666667,Action
+13.2787631,16.4755352,13.9917695,2.0576132,Product
+20.2406174,22.8889758,11.6402116,1.0582011,Product
+8.0927188,10.1398076,8.3475298,2.4701874,Inspiration
+10.3737113,12.3256972,14.4927536,0.7246377,Action
+13.8556884,19.4764862,14.0468227,2.3411371,Product
+14.9916248,19.0207156,18.556701,2.0618557,Product
+16.1771153,18.7676255,14.5728643,10.0502513,Product
+4.4587337,6.0916767,7.0175439,3.5087719,Action
+13.8028169,17.9276316,16.2361624,0.3690037,Inspiration
+6.7920585,8.7398374,25.6355932,1.2711864,Action
+16.6314008,16.6107383,12.2222222,12.2222222,Product
+16.7562724,15.9770115,13.8888889,0,Action
+13.4387352,16.1403509,13.3079848,1.9011407,Product
+18.2926829,17.282127,8.9552239,0,Product
+15.7805189,16.080402,10.2564103,0.8547009,Inspiration
+16.7096774,16.1389622,9.1463415,1.8292683,Product
+18.4745763,18.7149095,12.605042,1.6806723,Inspiration
+6.9167345,7.5399172,5.2567237,1.1002445,Inspiration
+16.4270153,14.293305,10,0,Product
+13.0147433,12.4594419,12.7819549,2.2556391,Product
+4.8273064,5.6013324,8.5714286,1.2244898,Action
+13.3093525,14.4882861,13.030303,2.7272727,Product
+22.0563847,20.1393728,9.5890411,2.739726,Action
+19.0104167,16.524029,11.6666667,1.6666667,Product
+18.2190379,14.221219,6.25,0,Action
+5.8265744,6.3972513,7.9069767,2.5581395,Inspiration
+11.8458611,13.0127774,15.060241,1.2048193,Product
+12.6777251,11.7961511,11.1111111,0,Action
+12.4621048,13.642132,21.4285714,2.8571429,Product
+1.2983092,2.0898033,7.81893,1.6460905,Inspiration
+11.7331745,12.2835944,12.1212121,1.5151515,Inspiration
+11.4013522,9.9437807,7.1428571,0,Action
+4.4233807,5.1318807,7.3039742,0.4296455,Action
+14.167113,13.5634589,12.345679,3.0864198,Product
+13.3770239,11.9980648,16.6666667,1.5151515,Inspiration
+16.8458781,19.6784074,22.4489796,2.0408163,Product
+4.425859,4.5413053,2.8037383,5.6074766,Inspiration
+7.8947368,8.6932241,7.3170732,0.6968641,Inspiration
+20.79566,26.1202186,22,6,Product
+27.5347913,28.7250384,20,6.6666667,Inspiration
+6.6310497,7.4287653,6.5957447,0.8510638,Inspiration
+3.6772853,4.6811741,7.9365079,1.5873016,Action
+27.2932331,27.8113664,32.1428571,7.1428571,Product
+2.1075984,2.0702903,1.754386,71.9298246,Product
+9.8098592,9.2180024,10,3,Action
+13.3832231,13.619403,10.3321033,5.904059,Inspiration
+15.3149606,13.5239942,8.3333333,2.0833333,Product
+12.6734505,13.331117,12.7358491,2.8301887,Inspiration
+12.0702179,12.9891304,12.7906977,1.1627907,Product
+16.709639,18.6370882,13.3663366,4.4554455,Product
+10.4637337,10.0621415,20.3883495,1.9417476,Action
+18.4819561,19.5697954,14.0495868,7.4380165,Product
+13.8547159,15.0627615,11.9815668,1.3824885,Inspiration
+0.7325201,1.894077,8.7301587,4.7619048,Action
+5.8553697,7.5934579,5.4824561,14.0350877,Product
+12.6712329,12.7472527,14.6153846,6.9230769,Product
+15.0248051,16.1881188,14.8148148,1.4814815,Inspiration
+11.9744366,12.0471014,17.5438596,0,Inspiration
+1.2472284,1.2134052,4.7619048,28.5714286,Product
+6.9686411,10.5714286,18.5185185,1.8518519,Action
+11.7128463,11.5004122,17.5,0.8333333,Product
+1.1683096,1.1643317,5.8823529,17.6470588,Product
+8.3853784,8.971173,15.3061224,4.0816327,Inspiration
+11.7974402,12.5202593,16.5467626,2.8776978,Product
+13.3274232,13.7161085,19.53125,1.5625,Action
+11.8896484,12.561925,16.6666667,5.3763441,Product
+5.088141,5.1176312,13.3012821,0.9615385,Inspiration
+10.9566639,10.1759391,15.2777778,2.7777778,Action
+14.8214286,16.1440678,13.8111888,1.5734266,Product
+17.7029993,17.1671827,18.5819071,4.400978,Action
+4.4725177,6.4443408,12.4723713,5.873066,Product
+2.365959,3.9701705,15.9574468,2.1276596,Action
+19.0905935,15.8333333,17.0454545,0,Product
+15.6358382,13.8938053,16.5217391,0,Product
+16.7645332,13.6643572,16.1016949,0.8474576,Inspiration
+18.4089162,14.7482014,20.5882353,1.4705882,Product
+10.6361149,9.0930674,11.7647059,4.7058824,Action
+3.254899,5.5152821,14.5299145,2.5641026,Action
+14.2857143,15.1586369,15.3284672,2.189781,Inspiration
+15.5174628,16.9649446,17,3.6666667,Product
+2.9858449,4.0331902,7.0473876,1.2150668,Inspiration
+16.1567364,13.9901823,9.4117647,35.2941176,Product
+2.70499,4.4873768,20,1.25,Action
+3.4881991,6.1085668,8.4745763,3.3898305,Action
+16.2322275,17.4978504,12.8078818,4.9261084,Product
+15.6236605,16.2881476,20.2970297,4.4554455,Inspiration
+16.4014974,14.5385588,10.4895105,0,Product
+3.4174702,5.7194245,14.8275862,4.4827586,Action
+15.4054054,13.9799636,20.2531646,2.5316456,Product
+15.5895692,13.5338346,12,0,Product
+3.5125467,6.5510139,10.0671141,1.1744966,Inspiration
+20.0913242,17.7681473,18.1818182,5.4545455,Inspiration
+10.4811947,9.9957555,23.7623762,1.980198,Action
+14.4581861,16.3425492,14.9425287,14.9425287,Product
+14.1853933,12.1287129,3.5897436,13.3333333,Action
+15.0849443,12.5739645,7.5471698,3.7735849,Action
+3.7752563,5.700421,3.8356164,0.8219178,Product
+1.7782489,3.5456731,17.472119,2.6022305,Action
+3.7965202,6.4627229,5.2810903,3.7478705,Action
+18.4499817,16.7602996,15.7894737,0.5847953,Inspiration
+24.150027,18.0851064,9.8591549,25.3521127,Product
+20.4257642,22.1179625,9.4594595,24.3243243,Product
+31.1744387,24.3296272,16.6666667,0,Inspiration
+1.2797825,2.6033058,16.2361624,8.4870849,Action
+17.8168773,20.1451279,2.293578,5.0458716,Action
+2.3400822,5.4068095,20.1030928,3.6082474,Action
+22.882939,17.3450509,16.3265306,2.0408163,Product
+29.8424163,22.4365005,19.1011236,1.1235955,Product
+18.5984723,20.375,11.1111111,0,Product
+14.5047659,11.5358894,10.2564103,2.5641026,Action
+5.8017928,5.2261092,7.8947368,7.2368421,Action
+10.0834492,11.3890524,19.1489362,4.2553191,Product
+16.0016454,14.863103,16.6666667,0,Action
+4.5525292,11.9294606,7.2,11.2,Action
+6.7859877,7.3081429,5.4545455,17.0247934,Action
+7.0774355,7.6365663,7.4626866,7.4626866,Action
+34.4707924,24.1820768,8,0,Action
+17.4305556,16.4989216,15.1162791,2.9069767,Product
+22.0116054,16.2313433,20.8333333,0,Action
+18.3624323,16.7710197,24.2105263,1.0526316,Product
+19.1944444,20.6635071,22.5806452,0,Action
+9.9827883,8.7055261,10.6060606,7.5757576,Action
+17.0433145,16.088632,16.2393162,4.2735043,Inspiration
+20.412595,17.6553672,13.8888889,0,Inspiration
+17.4536256,16.8478261,17.0212766,0,Product
+10.0913023,8.557394,6.6666667,0,Action
+13.075374,15.0512582,15.0877193,3.8596491,Product
+19.5536663,17.7009156,17.9775281,1.1235955,Inspiration
+2.164787,4.6116505,11.965812,3.8461538,Action
+8.4855272,10.1712329,7.9889807,1.1019284,Inspiration
+1.516191,24.1477273,4.516129,0,Action
+17.6816464,16.2850601,11.7647059,0.8403361,Inspiration
+12.195122,11.8920363,14.893617,6.3829787,Product
+16.5374677,16.0941476,14.1304348,2.173913,Inspiration
+4.5806624,7.9545455,11.0429448,1.8404908,Inspiration
+21.0708578,18.6100386,14.8148148,5.9259259,Inspiration
+14.9595687,10.5360934,12,0,Action
+18.5682327,15.0823353,13.1313131,2.020202,Inspiration
+19.1215324,15.9798535,16.4383562,2.739726,Inspiration
+16.0865241,12.7717391,17.0731707,3.6585366,Inspiration
+3.1003489,8.6356467,14.2857143,0,Action
+3.2864742,5.2233213,10.5504587,4.1284404,Inspiration
+23.3766234,15.9613615,22.6666667,0,Inspiration
+21.1318483,16.6666667,15.5555556,2.2222222,Product
+11.3475177,10.1694915,19.4690265,0.8849558,Inspiration
+10.0937721,9.3846154,20.8510638,7.6595745,Product
+5.6039575,9.9029126,12.195122,0,Action
+16.9982446,12.480916,10.1694915,3.3898305,Inspiration
+15.2921901,11.9924812,16.8674699,2.4096386,Inspiration
+4.5507482,4.8946749,3.2661571,1.3898541,Inspiration
+15.9684274,11.2546125,9.2307692,3.0769231,Inspiration
+23.5369775,13.4645669,22.2222222,4.4444444,Inspiration
+18.9700473,13.023088,17.5257732,1.0309278,Product
+15.2807203,14.192808,18.0327869,2.4590164,Inspiration
+4.3135246,5.5854302,8.3936324,2.3154848,Inspiration
+16.9642857,16.3388805,18.8888889,3.8888889,Inspiration
+4.9369352,8.0432173,12.749004,7.9681275,Inspiration
+15.9300184,14.5174051,19.4029851,0.7462687,Inspiration
+20.8241354,15.3614458,16.6666667,0,Inspiration
+19.7089947,16.2535748,23.8095238,0,Inspiration
+16.1150512,17.9621381,14.9253731,2.9850746,Product
+14.4010195,14.4981413,20.5555556,0.5555556,Product
+18.975469,15.6973752,10.8433735,2.4096386,Inspiration
+19.0611664,17.4311927,16.1616162,4.040404,Inspiration
+12.7399381,13.9811739,14.057508,7.9872204,Inspiration
+5.8817014,4.7596415,14.8717949,6.4102564,Action
+13.5366826,14.6899458,14.1732283,2.3622047,Inspiration
+13.3219955,13.6904762,14.9122807,1.754386,Inspiration
+11.3904407,12.3791103,14.2241379,2.1551724,Product
+11.0139076,10.9465551,21.3235294,4.4117647,Inspiration
+2.7432217,2.6253634,22.2222222,4.7619048,Action
+13.8468592,14.5833333,11.1731844,1.6759777,Inspiration
+5.8983573,5.7553538,9.4936709,3.9029536,Inspiration
+12.4681934,12.6163873,18.0555556,1.3888889,Inspiration
+13.2380074,14.6438953,12.1052632,6.3157895,Inspiration
+3.6649726,6.4106308,6.7552602,2.4916944,Inspiration
+11.801676,12.7894453,16.8421053,1.5789474,Product
+11.7850638,12.8094726,16.2561576,1.9704433,Inspiration
+7.1374622,7.3904084,15.2941176,2.3529412,Action
+5.4172057,6.3869992,5.8275058,0.9324009,Inspiration
+13.3591481,14.4517066,15.2542373,1.6949153,Product
+12.7291242,14.6159317,20.212766,6.3829787,Action
+13.3745835,12.9775622,9.5808383,1.7964072,Inspiration
+11.5294511,12.0365793,12.9449838,0.6472492,Product
+10.8528621,11.1650485,16.6666667,0.5747126,Product
+11.1683849,11.9346734,16.119403,7.4626866,Inspiration
+9.6166667,9.6317916,24.2424242,3.030303,Action
+13.8955582,14.6351931,17.1428571,0,Inspiration
+9.8353553,11.7083333,21.686747,0.6024096,Product
+14.1212586,16.5465632,14.2857143,0.4761905,Inspiration
+6.5900099,6.3480482,13.9830508,3.8135593,Action
+14.5794393,19.6442688,20.3821656,0.6369427,Inspiration
+13.5236103,15.7075874,13.2394366,1.1267606,Inspiration
+13.2105828,17.0454545,20.6349206,6.3492063,Inspiration
+5.1429076,4.7637795,16.6666667,7.4074074,Action
+12.6836259,16.277031,17.5,1,Product
+5.2059819,4.8343668,14.3939394,8.5227273,Action
+15.3528361,19.7755961,20.9540034,2.8960818,Product
+0.9587104,2.8508772,19.6428571,12.5,Action
+10.5900484,10.7915718,21.4876033,1.6528926,Action
+9.752907,10.6269113,21.3333333,0,Action
+6.4722396,6.4277899,9.4936709,0,Inspiration
+8.5506367,8.5201794,16.4556962,0,Inspiration
+11.1852643,13.3359873,17.2881356,2.7118644,Inspiration
+2.7434068,5.7227222,6.6666667,1.2121212,Action
+3.7715844,7.0843091,5.8796509,2.3426734,Inspiration
+1.2017429,3.0416255,8.490566,3.7735849,Action
+16.0827494,17.0835418,12.1428571,3.9285714,Inspiration
+11.6331821,11.9981105,25.2873563,1.1494253,Action
+13.2771761,14.5201238,22.9508197,1.6393443,Inspiration
+10.0329934,10.4770017,18.8405797,4.3478261,Action
+12.400906,14.691204,20.7650273,2.7322404,Inspiration
+1.7738803,7.9975329,14.2857143,0,Action
+12.9581636,12.8757515,11.1111111,0,Action
+5.3036437,8.0726965,12.5,0,Action
+17.5164967,16.8970814,6.8181818,9.0909091,Action
+16.6773163,18.2291667,22.5806452,0,Inspiration
+6.0016145,6.3430421,12.3723042,0.6810443,Product
+3.3699809,5.5077805,15.6521739,0.8695652,Action
+13.3367662,14.5941921,18.3098592,1.4084507,Inspiration
+14.1745283,16.0739191,15.2173913,2.173913,Inspiration
+14.3623025,14.0932265,10.3448276,1.7241379,Action
+15.3377967,17.3913043,23.4782609,0.8695652,Inspiration
+2.5,4.2606613,11.3402062,5.1546392,Action
+17.416318,17.7419355,20,1.1111111,Inspiration
+11.2421384,13.0693582,23.1111111,4,Inspiration
+14.4588045,15.7245223,21.3114754,4.0983607,Inspiration
+2.9528923,4.4929245,10.106383,2.393617,Action
+1.8727254,3.2244036,11.409396,2.6845638,Action
+1.9376128,2.8936545,9.5238095,0.2380952,Action
+10.3471002,11.8618619,31.1688312,1.2987013,Inspiration
+11.0250569,12.1243885,28.8888889,1.1111111,Inspiration
+10.3563941,11.046885,20.1612903,1.6129032,Inspiration
+14.1750842,14.7260274,13.4328358,2.9850746,Inspiration
+0.9885353,1.3969874,15.9090909,2.2727273,Action
+11.7691437,12.2296173,15.4761905,2.3809524,Product
+11.5467626,11.8232891,13.8728324,4.0462428,Product
+10.8261462,11.8374558,16.4835165,1.0989011,Inspiration
+11.5689981,11.9662625,13.4615385,0.9615385,Action
+13.9880952,14.754717,19.7530864,2.4691358,Action
+12.1890547,12.9470349,13.9423077,1.4423077,Action
+3.3305126,3.1281012,6.0240964,2.811245,Action
+10.4276316,11.5442279,17.6470588,8.8235294,Action
+11.3051917,10.932768,28.2051282,2.5641026,Action
+10.2952756,10.3545735,26.4150943,0,Action
+13.2251721,12.5703565,17.5675676,0,Action
+14.1503667,13.5022693,17.9487179,0,Action
+60.0840336,41.9491525,0,0,Action
+16.1107802,12.2857143,2.5,6.6666667,Action
+11.484375,10.6152806,15.7894737,0,Action
+4.1012216,4.5027816,17.6470588,2.3529412,Inspiration
+33.5038363,24.4736842,14.2857143,0,Action
+12.9933604,12.2739602,5.6521739,1.7391304,Action
+7.7552611,7.6578332,0,0,Action
+3.8176034,3.7253858,0,0,Action
+0.8182748,0.944334,0,0,Action
+5.0317538,4.8923679,0,0,Action
+41.1504425,25.3333333,20,0,Action
+12.3555166,10.7694223,5.907173,5.0632911,Action
+7.9242637,6.7000742,5.8823529,5.8823529,Action
+8.1618465,7.1342201,3.6363636,10,Action
+11.0474802,8.8301603,0,11.1888112,Action
+1.1167686,3.6028519,8.7248322,0,Action
+1.7975567,1.9047619,30.6122449,4.0816327,Product
+11.4332381,9.7319035,10.4651163,1.1627907,Action
+13.2588635,10.9347952,19.4444444,2.7777778,Action
+4.6142691,4.2057292,12.5810636,1.2970169,Inspiration
+11.0340952,9.2602041,13.6986301,1.369863,Inspiration
+11.3516566,9.6153846,29.4117647,0,Product
+16.1151405,9.9482461,11.1111111,1.5873016,Action
+11.5892163,13.119195,9.2105263,4.3859649,Action
+32.5207756,12.1223565,20.3389831,5.0847458,Action
+12.9189944,8.85506,8.9552239,2.9850746,Action
+8.497191,4.5075519,9.7744361,2.2556391,Action
+9.1387373,8.5953878,12.2093023,1.744186,Action
+21.2281796,10.538592,23.2,0,Action
+21.3791912,10.138539,22.0588235,5.8823529,Action
+19.2582511,9.8498233,21.09375,2.34375,Inspiration
+14.5151134,10.0638978,24.822695,4.964539,Inspiration
+12.8823529,8.2446809,24.4239631,2.3041475,Inspiration
+25,14.7735709,20.6896552,3.4482759,Action
+8.1164676,13.6184211,10.1123596,3.3707865,Action
+17.1416713,11.3313388,19.3939394,3.030303,Inspiration
+19.905482,12.3253214,19.6319018,1.2269939,Product
+8.184438,7.2228774,9.6636412,7.7949813,Inspiration
+21.9557823,14.4553645,11.5789474,5.2631579,Action
+14.2330677,10.6547961,25.0803859,6.1093248,Inspiration
+1.1156992,10.4108146,19.3181818,4.5454545,Inspiration
+1.5688208,5.0174689,11.5015974,2.8753994,Action
+17.9827267,13.6214953,22.3529412,2.3529412,Inspiration
+19.607438,13.264095,29.5774648,4.2253521,Product
+7.4811083,4.9926254,15.5462185,0.4201681,Product
+10.2891156,7.9026442,11.8032787,1.6393443,Action
+13.0667506,10.926259,23.1060606,3.7878788,Inspiration
+4.7883711,4.6335697,9.9236641,3.0534351,Action
+13.7868598,11.6803279,25.4464286,3.125,Inspiration
+16.3549618,11.0113422,24.5901639,0,Action
+14.0773976,12.1621622,23.0769231,2.1978022,Inspiration
+6.8952937,13.5348584,15.1162791,0,Action
+20.4900938,11.8443316,22.6190476,0,Inspiration
+7.3554789,5.8832091,7.4249605,1.1058452,Action
+1.4444444,2.0425636,4.6728972,0.9345794,Action
+20.6105491,15.5907037,29.245283,0.9433962,Inspiration
+18.4445178,12.8563886,28.3464567,5.511811,Inspiration
+15.343086,14.0905543,19.223301,10.8737864,Product
+1.3365735,1.5509989,28.5714286,0,Action
+4.4456756,7.0709746,15.9292035,1.3274336,Inspiration
+19.8335143,13.2766706,26.8041237,2.0618557,Product
+21.0714286,14.243807,22.2222222,1.8518519,Inspiration
+1.2770898,1.4514515,14.2857143,0,Action
+20.2622169,14.221073,30.1204819,2.4096386,Inspiration
+19.4987775,13.8282899,31.8181818,1.5151515,Inspiration
+14.5051546,13.535685,21.1640212,5.5555556,Inspiration
+20.3125,15.3191489,27.184466,0.9708738,Inspiration
+18.0113636,13.0606061,27.2727273,0.9090909,Inspiration
+15.4592497,12.4785837,30.2631579,0.6578947,Inspiration
+1.6398084,2.0522388,6.5693431,0,Action
+14.0156919,13.0703067,21.4007782,6.614786,Inspiration
+15,13.0650155,23.2954545,5.6818182,Inspiration
+15.6490179,13.6300417,30.952381,5.952381,Inspiration
+15.4310345,14.3060837,29.3333333,0,Product
+16.5431445,15.201005,15.6521739,3.4782609,Action
+15.0625602,15.0897227,27.9411765,5.1470588,Inspiration
+13.4670487,14.3636364,23.5294118,0,Product
\ No newline at end of file
diff --git a/materials/tutorial_04/tests_tutorial_04.R b/materials/tutorial_04/tests_tutorial_04.R
new file mode 100644
index 0000000..bb524b2
--- /dev/null
+++ b/materials/tutorial_04/tests_tutorial_04.R
@@ -0,0 +1,416 @@
+library(digest)
+library(testthat)
+
+# +
+#abstraction templates
+
+check_TF <- function(answerX.X, expectedHash) {
+ var_name <- deparse(substitute(answerX.X))
+ test_that(paste('Did not assign answer to an object called ', var_name), {
+ expect_true(exists(var_name))
+ })
+
+
+ test_that('Solution should be "true" or "false"', {
+ expect_match(answerX.X, "true|false", ignore.case = TRUE)
+ })
+
+ answer_hash <- digest(tolower(answerX.X))
+ #if (answer_hash == "HASH_HERE") {
+ # print("HINT_HERE")
+ #}
+
+ test_that("Solution is incorrect", {
+ expect_equal(answer_hash, expectedHash)
+ })
+
+ print("Success!")
+}
+
+check_MC <- function(answerX.X, choiceList, expectedHash) {
+ var_name <- deparse(substitute(answerX.X))
+ test_that(paste('Did not assign answer to an object called ', var_name), {
+ expect_true(exists(var_name))
+ })
+
+
+ test_that(paste('Solution should be a single character ', toString(choiceList)), {
+ expect_true(tolower(answerX.X) %in% tolower(choiceList))
+ })
+
+ answer_hash <- digest(tolower(answerX.X))
+ #if (answer_hash == "HASH_HERE") {
+ # print("HINT_HERE")
+ #} else if (answer_hash == "HASH_HERE") {
+ # print("HINT_HERE")
+ #} else if (answer_hash == "HASH_HERE") {
+ # print("HINT_HERE")
+ #}
+
+ test_that("Solution is incorrect", {
+ expect_equal(answer_hash, expectedHash)
+ })
+
+ print("Success!")
+}
+
+
+
+# dataCheckTuples is data.frame(c(colnames), c(scale factor), c(expectedHash))
+check_DF <- function(answerX.X, expected_colnames, hashNRows, cols_to_check, precision_list, expectedHashes) {
+ dataCheckTuples <- data.frame(cols_to_check, precision_list, expectedHashes)
+ var_name <- deparse(substitute(answerX.X))
+ test_that(paste('Did not assign answer to an object called ', var_name), {
+ expect_true(exists(var_name))
+ })
+
+ test_that("Solution should be a data frame", {
+ expect_true("data.frame" %in% class(answerX.X))
+ })
+
+ given_colnames <- colnames(answerX.X)
+ test_that("Data frame does not have the correct columns", {
+ expect_equal(length(setdiff(
+ union(expected_colnames, given_colnames),
+ intersect(expected_colnames, given_colnames)
+ )), 0)
+ })
+
+ test_that("Data frame does not contain the correct number of rows", {
+ expect_equal(digest(as.integer(nrow(answerX.X))), hashNRows)
+ })
+
+
+
+ apply(dataCheckTuples, 1, function(tuple) {
+ test_that(paste(tuple[[1]], " does not contain the correct data"), {
+ expect_equal(digest(as.integer(sum(answerX.X[tuple[[1]]]) * as.double(tuple[[2]]))),
+ tuple[[3]])
+ })
+ })
+
+
+
+
+ print("Success!")
+}
+
+
+
+
+check_numeric <- function(answerX.X, precision, expectedHash) {
+ var_name <- deparse(substitute(answerX.X))
+ test_that(paste('Did not assign answer to an object called ', var_name), {
+ expect_true(exists(var_name))
+ })
+
+ answer_as_numeric <- as.numeric(answerX.X)
+ test_that(paste(var_name, " should be a number"), {
+ expect_false(is.na(answer_as_numeric))
+ })
+
+ test_that(paste(var_name, " value is incorrect"), {
+ expect_equal(digest(as.integer(answer_as_numeric * precision)), expectedHash)
+ })
+
+ print("Success!")
+}
+
+
+
+check_numeric_element <- function(answerX.X, precision, expectedHash) {
+ var_name <- deparse(substitute(answerX.X))
+
+ answer_as_numeric <- as.numeric(answerX.X)
+ test_that(paste(var_name, " should be a number"), {
+ expect_false(is.na(answer_as_numeric))
+ })
+
+ test_that(paste(var_name, " value is incorrect"), {
+ expect_equal(digest(as.integer(answer_as_numeric * precision)), expectedHash)
+ })
+
+ print("Success!")
+}
+
+
+
+
+check_plot <- function(answerX.X, x_axis_var, geom_type, hasVline, bin_width_hash, nrow_hash, x_axis_var_hash, hasTitle) {
+ var_name <- deparse(substitute(answerX.X))
+ test_that(paste('Did not assign answer to an object called ', var_name), {
+ expect_true(exists(var_name))
+ })
+
+
+ test_that("Solution should be a ggplot object", {
+ expect_true(is.ggplot(answerX.X))
+ })
+
+ properties <- c(answerX.X$layers[[1]]$mapping, answerX.X$mapping)
+
+ test_that(paste("Plot should have ", x_axis_var," on the x-axis"), {
+ expect_true(x_axis_var == rlang::get_expr(properties$x))
+ })
+
+ test_that("Plot does not have the correct layers", {
+ expect_true(geom_type %in% class(answerX.X$layers[[1]]$geom))
+
+ if(hasVline) {
+ expect_true("GeomVline" %in% class(answerX.X$layers[[2]]$geom))
+ }
+ })
+
+ test_that("Plot does not have the correct bin width", {
+ expect_equal(
+ digest(as.integer(mget("stat_params", answerX.X$layers[[1]])[["stat_params"]][["binwidth"]])),
+ bin_width_hash)
+ })
+
+ test_that("Plot does not use the correct data", {
+ expect_equal(digest(nrow(answerX.X$data)), nrow_hash)
+ expect_equal(digest(round(sum(answerX.X$data[x_axis_var]))), x_axis_var_hash)
+
+ # If X_AXIS_VAR is not known:
+ # expect_equal(digest(round(sum(pull(answerX.X$data, rlang::get_expr(properties$x))))), "HASH_HERE")
+ })
+
+ test_that("x-axis label should be descriptive and human readable", {
+ expect_false(answerX.X$labels$x == toString(rlang::get_expr(properties$x)))
+ })
+
+ if(hasTitle){
+
+ test_that("Plot should have a title", {
+ expect_true("title" %in% names(answerX.X$labels))
+ })
+ }
+
+
+ print("Success!")
+}
+
+
+getPermutations <- function(vec) {
+ rsf <- c()
+ for (i in 1:length(vec)) {
+ for (j in i:length(vec)) {
+ temp <- vec[i:j]
+ rsf <- c(rsf, paste(temp, collapse= ''))
+ if (i < j) {
+ for (k in i:j) {
+ rsf <- c(rsf, paste(temp[-k], collapse=''))
+ }
+ }
+ }
+ }
+ return(unique(rsf))
+}
+
+
+
+
+
+# +
+# Question 1.0
+
+test_1.0 <- function() {
+ check_MC(answer1.0, LETTERS[1:3], '127a2ec00989b9f7faf671ed470be7f8')
+}
+
+# +
+# Question 1.1
+
+test_1.1 <- function() {
+ check_MC(answer1.1, LETTERS[1:4], '127a2ec00989b9f7faf671ed470be7f8')
+}
+
+# +
+# Question 1.2
+
+test_1.2 <- function() {
+ check_MC(answer1.2, LETTERS[1:2], '127a2ec00989b9f7faf671ed470be7f8')
+}
+
+# +
+# Question 1.3
+
+test_1.3 <- function() {
+ check_MC(answer1.3, LETTERS[1:6], 'ddf100612805359cd81fdc5ce3b9fbba')
+}
+
+# +
+# Question 1.4
+
+test_1.4.0 <- function() {
+ check_numeric_element(caschools_MLR_add$coefficients[1],1e4,"7d5fdc4b1617f1213563cf12b0be1c68")
+}
+
+test_1.4.1 <- function() {
+ check_numeric_element(caschools_MLR_add$coefficients[2],1e4,"1cf3a32c120bd3f6faddc6ae470fd2b8")
+}
+
+test_1.4.2 <- function() {
+ check_numeric_element(caschools_MLR_add$coefficients[3],1e4,"8873eb87d376c1c05700be1435ff22dc")
+}
+
+
+# +
+# Question 1.5
+
+test_1.5 <- function() {
+ check_plot(caschools_MLR_add_plot,
+ "income",
+ "GeomPoint" ,
+ FALSE,
+ "3e2e4a08c44d0224de5b7e668c75ace3",
+ "d6af036ffbdd7ccfc34dc7862b0e50d3",
+ "13742f581e47f00fd8beeade76db838c",
+ TRUE)
+}
+
+# +
+# Question 1.6
+
+test_1.6 <- function() {
+ check_DF(caschools_MLR_add_results,
+ c("term","estimate", "std.error", "statistic", "p.value", "conf.low", "conf.high"),
+ "11946e7a3ed5e1776e81c0f0ecd383d0",
+ c("estimate", "std.error", "statistic", "p.value", "conf.low", "conf.high"),
+ c(100, 100, 100, 100, 100, 100),
+ c("3f2caceee58bc5e5092ab875c8066a9b",
+ "d3c5ba4fef4e46e63e649dc573977aad",
+ "6e4a7f58d3c649fe8d8313435565c283",
+ "569ddf8dcb5af0cbc7177be6a8b9700d",
+ "fd34f0720893972017cb2261e9353fb2",
+ "ee86da303eb6b2854286c84802788768"))
+}
+
+# +
+# Question 1.7
+
+# manual
+
+# +
+# Question 1.8
+
+test_1.8 <- function() {
+ check_MC(answer1.8, getPermutations(LETTERS[1:4]), "6e7a8c1c098e8817e3df3fd1b21149d1")
+}
+
+# +
+# Question 2.0
+
+test_2.0 <- function() {
+ check_MC(answer2.0, LETTERS[1:6], 'd110f00cfb1b248e835137025804a23b')
+}
+
+# +
+# Question 2.1
+
+test_2.1.0 <- function() {
+ check_numeric_element(caschools_MLR_int$coefficients[1], 1e4, "080bbbf3c10c028f53b1901022933269")
+}
+test_2.1.1 <- function() {
+ check_numeric_element(caschools_MLR_int$coefficients[2], 1e4, "6750c14599866d62ee03d881a88d4737")
+}
+test_2.1.2 <- function() {
+ check_numeric_element(caschools_MLR_int$coefficients[3], 1e4, "9c3c926f355b55c26682a59a66d621e3")
+}
+test_2.1.3 <- function() {
+ check_numeric_element(caschools_MLR_int$coefficients[4], 1e4, "491174b285abb2888e9e602eecfb6037")
+}
+
+
+# +
+# Question 2.2
+
+test_2.2 <- function() {
+ check_plot(caschools_MLR_int_plot,
+ "income",
+ "GeomPoint",
+ FALSE,
+ "3e2e4a08c44d0224de5b7e668c75ace3",
+ "d6af036ffbdd7ccfc34dc7862b0e50d3",
+ "13742f581e47f00fd8beeade76db838c",
+ TRUE)
+}
+
+# +
+# Question 2.3
+
+test_2.3 <- function() {
+ check_DF(caschools_MLR_int_results,
+ c("term","estimate", "std.error", "statistic", "p.value", "conf.low", "conf.high"),
+ "234a2a5581872457b9fe1187d1616b13",
+ c("estimate", "std.error", "statistic", "p.value", "conf.low", "conf.high"),
+ c(100, 100, 100, 100, 100, 100),
+ c("8adf1c6033759946124174b1ffecc9d1",
+ "2109c9c0db840505d06b32da37f3261e",
+ "6f11355413a4aa7c96bf7412868a7e7f",
+ "242f3fe311473815db79235ff6708bde",
+ "ec9d7c4ea6c09c65a368c4865e500886",
+ "8fcc24b94746de0d011202126d17c4e0"))
+}
+
+# +
+# Question 2.4
+
+test_2.4 <- function() {
+ check_MC(answer2.4, getPermutations(LETTERS[1:5]), '8310e591706d1e38cdbfd4e26f17a274')
+}
+
+# +
+# Question 2.5
+
+# manual
+
+# +
+# Quesiton 2.6
+
+
+test_2.6.0 <- function() {
+ check_DF(caschools_SLR_kk06_results,
+ c("term","estimate", "std.error", "statistic", "p.value"),
+ "c01f179e4b57ab8bd9de309e6d576c48",
+ c("estimate", "std.error", "statistic", "p.value"),
+ c(100, 100, 100, 100),
+ c("82798d4574cf47d5cb838e4aca470ed8",
+ "9a1e47f252c2f2aa62cab1323c75885b",
+ "878fe51e9e4a668776d114d06fd00cc9",
+ "1473d70e5646a26de3c52aa1abd85b1f"))
+}
+
+
+
+test_2.6.1 <- function() {
+ check_DF(caschools_SLR_kk08_results,
+ c("term","estimate", "std.error", "statistic", "p.value"),
+ "c01f179e4b57ab8bd9de309e6d576c48",
+ c("estimate", "std.error", "statistic", "p.value"),
+ c(100, 100, 100, 100),
+ c("8adf1c6033759946124174b1ffecc9d1",
+ "525d73b4c5528794642ceb4dd9f987c2",
+ "eda26e24431618557efc7037b20d0568",
+ "1473d70e5646a26de3c52aa1abd85b1f"))
+}
+
+
+test_2.6.2 <- function() {
+ check_DF(caschools_MLR_int_results,
+ c("term","estimate", "std.error", "statistic", "p.value", "conf.low", "conf.high"),
+ "234a2a5581872457b9fe1187d1616b13",
+ c("estimate", "std.error", "statistic", "p.value", "conf.low", "conf.high"),
+ c(100, 100, 100, 100, 100, 100),
+ c("8adf1c6033759946124174b1ffecc9d1",
+ "2109c9c0db840505d06b32da37f3261e",
+ "6f11355413a4aa7c96bf7412868a7e7f",
+ "242f3fe311473815db79235ff6708bde",
+ "ec9d7c4ea6c09c65a368c4865e500886",
+ "8fcc24b94746de0d011202126d17c4e0"))
+}
+
+# +
+# Question 2.7
+
+# manual
diff --git a/materials/tutorial_04/tutorial_04.ipynb b/materials/tutorial_04/tutorial_04.ipynb
new file mode 100644
index 0000000..f842418
--- /dev/null
+++ b/materials/tutorial_04/tutorial_04.ipynb
@@ -0,0 +1,1613 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "deletable": false,
+ "editable": false,
+ "nbgrader": {
+ "cell_type": "markdown",
+ "checksum": "f97f65e4d6b4c1d4d999d0c2ae225fc5",
+ "grade": false,
+ "grade_id": "cell-f1e1d845873036f4",
+ "locked": true,
+ "schema_version": 3,
+ "solution": false,
+ "task": false
+ }
+ },
+ "source": [
+ "# Tutorial 4: MLR with different types of input variables"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "deletable": false,
+ "editable": false,
+ "nbgrader": {
+ "cell_type": "markdown",
+ "checksum": "1c57f899f006691c0cb0f40be06bb51e",
+ "grade": false,
+ "grade_id": "cell-82d9926086d47a80",
+ "locked": true,
+ "schema_version": 3,
+ "solution": false,
+ "task": false
+ }
+ },
+ "source": [
+ "#### Lecture and Tutorial Learning Goals:\n",
+ "After completing this week's lecture and tutorial work, you will be able to:\n",
+ "\n",
+ "1. Give an example of a real problem that that could be answered by a multiple linear regression.\n",
+ "2. Interpret the coefficients and $p$-values of different types of input variables, including categorical input variables.\n",
+ "3. Define interactions in the context of linear regression.\n",
+ "4. Write a computer script to perform linear regression when input variables are continuous or discrete, and when there are interactions between some of these variables."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "deletable": false,
+ "editable": false,
+ "nbgrader": {
+ "cell_type": "code",
+ "checksum": "7fc505b9da3ba24a646a8a35b69f517d",
+ "grade": false,
+ "grade_id": "cell-a2a153352bc44a68",
+ "locked": true,
+ "schema_version": 3,
+ "solution": false,
+ "task": false
+ },
+ "tags": []
+ },
+ "outputs": [],
+ "source": [
+ "# Run this cell before continuing.\n",
+ "library(tidyverse)\n",
+ "library(repr)\n",
+ "library(infer)\n",
+ "library(cowplot)\n",
+ "library(broom)\n",
+ "library(AER)\n",
+ "source(\"tests_tutorial_04.R\")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "deletable": false,
+ "editable": false,
+ "nbgrader": {
+ "cell_type": "markdown",
+ "checksum": "ef63ebcfe8716aad38a2bf893e613b02",
+ "grade": false,
+ "grade_id": "cell-9be71f65643c5906",
+ "locked": true,
+ "schema_version": 3,
+ "solution": false,
+ "task": false
+ }
+ },
+ "source": [
+ "## The data\n",
+ "\n",
+ "In this tutorial, we will continue using the `CASchools` real world dataset from 420 K-6 and K-8 districts in California. The California School data set comes with an R package called `AER`, an acronym for Applied Econometrics with R (by Christian Kleiber & Zeileis, 2017). \n",
+ "\n",
+ "The dataset contains data on test performance, school characteristics and student demographic backgrounds for school districts in California. Among many variables available we will use the following:\n",
+ "\n",
+ "- `grades`: factor indicating grade span of district.\n",
+ "\n",
+ "- `income`: District average income (in USD 1,000).\n",
+ "\n",
+ "- `english`: Percent of English learners.\n",
+ "\n",
+ "- `read`: Average reading score.\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "deletable": false,
+ "editable": false,
+ "nbgrader": {
+ "cell_type": "code",
+ "checksum": "e46acff06f2da23622a95dcad738046c",
+ "grade": false,
+ "grade_id": "cell-751a3a4db77146a7",
+ "locked": true,
+ "schema_version": 3,
+ "solution": false,
+ "task": false
+ },
+ "tags": []
+ },
+ "outputs": [],
+ "source": [
+ "#run this cell\n",
+ "\n",
+ "data(CASchools)\n",
+ "\n",
+ "caschools <- CASchools %>%\n",
+ " select(grades, income, english, read) %>%\n",
+ " mutate_if(is.numeric, round, 2)\n",
+ "\n",
+ "head(caschools)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "deletable": false,
+ "editable": false,
+ "nbgrader": {
+ "cell_type": "markdown",
+ "checksum": "491d42046529205e254c52113200e55a",
+ "grade": false,
+ "grade_id": "cell-3dfb99accf2154a8",
+ "locked": true,
+ "schema_version": 3,
+ "solution": false,
+ "task": false
+ }
+ },
+ "source": [
+ "#### Important: Note that if the categorical variable is not a factor, `lm` won't create a dummy variable!! \n",
+ "\n",
+ "> Make sure that categorical variables in your model are factors. If they are not, then **set them as factors**!!"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "deletable": false,
+ "editable": false,
+ "nbgrader": {
+ "cell_type": "markdown",
+ "checksum": "f058fbba73a9a4936f333e50270d5d74",
+ "grade": false,
+ "grade_id": "cell-a7382e79e72c9703",
+ "locked": true,
+ "schema_version": 3,
+ "solution": false,
+ "task": false
+ }
+ },
+ "source": [
+ "## 1. MLR: additive\n",
+ "\n",
+ "As discussed in the lecture, R will create dummy variables to include categorical variables in the model. In this example, `grades` is a categorical variable with 2 levels. "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "deletable": false,
+ "editable": false,
+ "nbgrader": {
+ "cell_type": "markdown",
+ "checksum": "9367815b59f44875ddc3b3cedffd41a2",
+ "grade": false,
+ "grade_id": "cell-18576173209dcbfe",
+ "locked": true,
+ "schema_version": 3,
+ "solution": false,
+ "task": false
+ }
+ },
+ "source": [
+ "**Question 1.0**\n",
+ "
{points: 1}\n",
+ "\n",
+ "Since the input variable `grades` is a discrete and nominal variable with 2 levels, KK-06 and KK-08. Since this variable is a factor in the dataset, `lm` selects one level as a baseline to create a dummy variable. Which level of `grades` is selected, by default, as a baseline?\n",
+ "\n",
+ "**A.** `KK-06`\n",
+ "\n",
+ "**B.** `KK-08`\n",
+ "\n",
+ "*Assign your answer to an object called `answer1.0`. Your answer should be one of `\"A\"` or `\"B\"` surrounded by quotes.*"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "deletable": false,
+ "nbgrader": {
+ "cell_type": "code",
+ "checksum": "cd4bd2ff4058b85570033044f5e731a9",
+ "grade": false,
+ "grade_id": "cell-f073f90a4398375f",
+ "locked": false,
+ "schema_version": 3,
+ "solution": true,
+ "task": false
+ },
+ "tags": []
+ },
+ "outputs": [],
+ "source": [
+ "# answer1.0 <- ...\n",
+ "\n",
+ "# your code here\n",
+ "fail() # No Answer - remove if you provide an answer"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "deletable": false,
+ "editable": false,
+ "nbgrader": {
+ "cell_type": "code",
+ "checksum": "d6f3723f0f8ef72f8cbfa6906e42b426",
+ "grade": true,
+ "grade_id": "cell-b6ce784a5466648d",
+ "locked": true,
+ "points": 1,
+ "schema_version": 3,
+ "solution": false,
+ "task": false
+ },
+ "tags": []
+ },
+ "outputs": [],
+ "source": [
+ "test_1.0()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "deletable": false,
+ "editable": false,
+ "nbgrader": {
+ "cell_type": "markdown",
+ "checksum": "dc00d710ccdb843088fd0cd32e7120bc",
+ "grade": false,
+ "grade_id": "cell-3e16a0eb1d1251a6",
+ "locked": true,
+ "schema_version": 3,
+ "solution": false,
+ "task": false
+ }
+ },
+ "source": [
+ "**Question 1.1**\n",
+ "
{points: 1}\n",
+ "\n",
+ "How many dummy variables does `lm` create to fit a linear regression with the categorical variable `grades`?\n",
+ "\n",
+ "**A.** 1\n",
+ "\n",
+ "**B.** 2\n",
+ "\n",
+ "**C.** 3\n",
+ "\n",
+ "**D.** 4\n",
+ "\n",
+ "*Assign your answer to an object called `answer1.1`. Your answer should be one of `\"A\"`, `\"B\"`, `\"C\"`, or `\"D\"` surrounded by quotes.*"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "deletable": false,
+ "nbgrader": {
+ "cell_type": "code",
+ "checksum": "c3a74807a9fd10b0a98bf7040df5d7ca",
+ "grade": false,
+ "grade_id": "cell-49fd43204dbbbe64",
+ "locked": false,
+ "schema_version": 3,
+ "solution": true,
+ "task": false
+ },
+ "tags": []
+ },
+ "outputs": [],
+ "source": [
+ "# answer1.1 <- \n",
+ "\n",
+ "# your code here\n",
+ "fail() # No Answer - remove if you provide an answer"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "deletable": false,
+ "editable": false,
+ "nbgrader": {
+ "cell_type": "code",
+ "checksum": "aab29ab12d9f21578b4e0bb9fb243b26",
+ "grade": true,
+ "grade_id": "cell-8a6966bb42e5995c",
+ "locked": true,
+ "points": 1,
+ "schema_version": 3,
+ "solution": false,
+ "task": false
+ },
+ "tags": []
+ },
+ "outputs": [],
+ "source": [
+ "test_1.1()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "deletable": false,
+ "editable": false,
+ "nbgrader": {
+ "cell_type": "markdown",
+ "checksum": "accc4ebe5b88ec809ed324f02192458c",
+ "grade": false,
+ "grade_id": "cell-75a9578496bd6d9c",
+ "locked": true,
+ "schema_version": 3,
+ "solution": false,
+ "task": false
+ }
+ },
+ "source": [
+ "**Question 1.2**\n",
+ "
{points: 1}\n",
+ "\n",
+ "In the previous tutorial, you used a simple linear regression (SLR) to study the relation between `read` and `income`, on average for all type of schools. Suppose you want to examine if there is any difference in this relation depending on the grade span of the school (i.e.,KK-06 vs KK-08). \n",
+ "\n",
+ "If for all types of school (i.e., for all levels of `grades`) you expect the same change in reading score per unit change in the average income, which MLR will you fit in `R` using the `lm` function?\n",
+ "\n",
+ "**A.** `lm(read ~ income + grades, data = caschools)`\n",
+ "\n",
+ "**B.** `lm(read ~ income * grades, data = caschools)`\n",
+ "\n",
+ "*Assign your answer to an object called `answer1.2`. Your answer should be one of `\"A\"` or `\"B\"` surrounded by quotes.*"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "deletable": false,
+ "nbgrader": {
+ "cell_type": "code",
+ "checksum": "e97fed2fc79c181b9447e6caafaa4b18",
+ "grade": false,
+ "grade_id": "cell-f6b2d0e8025cf80e",
+ "locked": false,
+ "schema_version": 3,
+ "solution": true,
+ "task": false
+ },
+ "tags": []
+ },
+ "outputs": [],
+ "source": [
+ "# answer1.2 <- \n",
+ "\n",
+ "# your code here\n",
+ "fail() # No Answer - remove if you provide an answer"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "deletable": false,
+ "editable": false,
+ "nbgrader": {
+ "cell_type": "code",
+ "checksum": "d810fcc6f81a8afc5987ec10316adfb0",
+ "grade": true,
+ "grade_id": "cell-645245eaf0a415b6",
+ "locked": true,
+ "points": 1,
+ "schema_version": 3,
+ "solution": false,
+ "task": false
+ },
+ "tags": []
+ },
+ "outputs": [],
+ "source": [
+ "test_1.2()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "deletable": false,
+ "editable": false,
+ "nbgrader": {
+ "cell_type": "markdown",
+ "checksum": "12af6ed36232289caa83e3518b468b98",
+ "grade": false,
+ "grade_id": "cell-37a0395078a18c50",
+ "locked": true,
+ "schema_version": 3,
+ "solution": false,
+ "task": false
+ }
+ },
+ "source": [
+ "**Question 1.3**\n",
+ "
{points: 1}\n",
+ "\n",
+ "Which of the following descriptions will best describe a visualization of the MLR considered in **Question 1.2**? \n",
+ "\n",
+ "**A.** one line through a cloud of data points\n",
+ "\n",
+ "**B.** two lines with equal slopes but different intercepts\n",
+ "\n",
+ "**C.** two lines with different slopes and different intercepts\n",
+ "\n",
+ "**D.** a smooth concave curve through a cloud of data points\n",
+ "\n",
+ "**E.** two boxplots for different levels of `grades`\n",
+ "\n",
+ "*Assign your answer to an object called `answer1.3`. Your answer should be one of `\"A\"`, `\"B\"`, `\"C\"`, `\"D\"`, or `\"E\"` surrounded by quotes.*"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "deletable": false,
+ "nbgrader": {
+ "cell_type": "code",
+ "checksum": "a44f499620bcd84405a2c6bd2a8a9d73",
+ "grade": false,
+ "grade_id": "cell-fd274734aed6b6c7",
+ "locked": false,
+ "schema_version": 3,
+ "solution": true,
+ "task": false
+ },
+ "tags": []
+ },
+ "outputs": [],
+ "source": [
+ "# answer1.3 <- \n",
+ "\n",
+ "# your code here\n",
+ "fail() # No Answer - remove if you provide an answer"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "deletable": false,
+ "editable": false,
+ "nbgrader": {
+ "cell_type": "code",
+ "checksum": "35393769c0469b8c86febb09350aee54",
+ "grade": true,
+ "grade_id": "cell-905c24ed72606cd0",
+ "locked": true,
+ "points": 1,
+ "schema_version": 3,
+ "solution": false,
+ "task": false
+ },
+ "tags": []
+ },
+ "outputs": [],
+ "source": [
+ "test_1.3()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "deletable": false,
+ "editable": false,
+ "nbgrader": {
+ "cell_type": "markdown",
+ "checksum": "b0960d461c3ee4f2a8374e801249aa6e",
+ "grade": false,
+ "grade_id": "cell-e905a3e604e8750e",
+ "locked": true,
+ "schema_version": 3,
+ "solution": false,
+ "task": false
+ }
+ },
+ "source": [
+ "**Question 1.4**\n",
+ "
{points: 1}\n",
+ "\n",
+ "Using `caschools`, estimate the MLR proposed in **Question 1.2** and called it `caschools_MLR_add`.\n",
+ "\n",
+ "*Fill out those parts indicated with `...`, uncomment the corresponding code in the cell below, and run it.*"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "deletable": false,
+ "nbgrader": {
+ "cell_type": "code",
+ "checksum": "50c8eb2ff60b12ebb21f9c86ca8d4190",
+ "grade": false,
+ "grade_id": "cell-537a5de8c45b73fd",
+ "locked": false,
+ "schema_version": 3,
+ "solution": true,
+ "task": false
+ },
+ "tags": []
+ },
+ "outputs": [],
+ "source": [
+ "# caschools_MLR_add <- ...(...,\n",
+ "# ...\n",
+ "# )\n",
+ "# caschools_MLR_add\n",
+ "\n",
+ "# your code here\n",
+ "fail() # No Answer - remove if you provide an answer"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "deletable": false,
+ "editable": false,
+ "nbgrader": {
+ "cell_type": "code",
+ "checksum": "1024a6c0ac471806ff34ea856ddcbc0a",
+ "grade": true,
+ "grade_id": "cell-c955967bb20ade73",
+ "locked": true,
+ "points": 1,
+ "schema_version": 3,
+ "solution": false,
+ "task": false
+ },
+ "tags": []
+ },
+ "outputs": [],
+ "source": [
+ "test_1.4.0()\n",
+ "test_1.4.1()\n",
+ "test_1.4.2()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "deletable": false,
+ "editable": false,
+ "nbgrader": {
+ "cell_type": "markdown",
+ "checksum": "1b032d1a200038ebfb0c9418863f77a5",
+ "grade": false,
+ "grade_id": "cell-8a3de76c80df5397",
+ "locked": true,
+ "schema_version": 3,
+ "solution": false,
+ "task": false
+ }
+ },
+ "source": [
+ "**Question 1.5**\n",
+ "
{points: 1}\n",
+ "\n",
+ "Create a plot of the data in `caschools` (using `geom_point()`) along with the estimated regression lines coming from the additive regression model `caschools_MLR_add`. Use different colours for the points and regression lines of each type of school (levels of `grades`). Include a legend indicating what colour corresponds to each level with proper axis labels. The `ggplot()` object's name will be `caschools_MLR_add_plot`.\n",
+ "\n",
+ "*Fill out those parts indicated with `...`, uncomment the corresponding code in the cell below, and run it.*"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "deletable": false,
+ "nbgrader": {
+ "cell_type": "code",
+ "checksum": "3a291e10325632cc6dbe54e29fbd0a5b",
+ "grade": false,
+ "grade_id": "cell-9dcae296b8566967",
+ "locked": false,
+ "schema_version": 3,
+ "solution": true,
+ "task": false
+ },
+ "tags": []
+ },
+ "outputs": [],
+ "source": [
+ "options(repr.plot.width = 15, repr.plot.height = 7) # Adjust these numbers so the plot looks good in your desktop.\n",
+ "\n",
+ "# caschools$pred_MLR_Add <- predict(caschools_MLR_add) # Using predict() to create estimated regression lines.\n",
+ "\n",
+ "# caschools_MLR_add_plot <- ggplot(..., aes(\n",
+ "# ...,\n",
+ "# ...,\n",
+ "# color = ...\n",
+ "# )) +\n",
+ "# ...() +\n",
+ "# geom_line(aes(y = pred_MLR_Add), size = 1) +\n",
+ "# labs(\n",
+ "# title = ...,\n",
+ "# x = ...,\n",
+ "# y = ...\n",
+ "# ) +\n",
+ "# theme(\n",
+ "# text = element_text(size = 16.5),\n",
+ "# plot.title = element_text(face = \"bold\"),\n",
+ "# axis.title = element_text(face = \"bold\"),\n",
+ "# legend.title = element_text(face = \"bold\"),\n",
+ "# ) +\n",
+ "# labs(color = \"grades\")\n",
+ "# caschools_MLR_add_plot\n",
+ "\n",
+ "# your code here\n",
+ "fail() # No Answer - remove if you provide an answer"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "deletable": false,
+ "editable": false,
+ "nbgrader": {
+ "cell_type": "code",
+ "checksum": "125d765392989a6f948357a6cc048d01",
+ "grade": true,
+ "grade_id": "cell-60b4784943979e31",
+ "locked": true,
+ "points": 1,
+ "schema_version": 3,
+ "solution": false,
+ "task": false
+ },
+ "tags": []
+ },
+ "outputs": [],
+ "source": [
+ "test_1.5()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "deletable": false,
+ "editable": false,
+ "nbgrader": {
+ "cell_type": "markdown",
+ "checksum": "806f32d510d22cb6fee3cde12b870e5f",
+ "grade": false,
+ "grade_id": "cell-5a6b3d5e566adacc",
+ "locked": true,
+ "schema_version": 3,
+ "solution": false,
+ "task": false
+ }
+ },
+ "source": [
+ "**Question 1.6**\n",
+ "
{points: 1}\n",
+ "\n",
+ "Find the estimated coefficients of `caschools_MLR_add` using `tidy()`. Report the estimated coefficients, their standard errors and corresponding $p$-values. Include the corresponding asymptotic **90% confidence intervals**. Store the results in the variable `caschools_MLR_add_results`.\n",
+ "\n",
+ "*Fill out those parts indicated with `...`, uncomment the corresponding code in the cell below, and run it.*"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "deletable": false,
+ "nbgrader": {
+ "cell_type": "code",
+ "checksum": "d35aa6dc891e12999af8ebac83a3f01d",
+ "grade": false,
+ "grade_id": "cell-253df594cc213305",
+ "locked": false,
+ "schema_version": 3,
+ "solution": true,
+ "task": false
+ },
+ "tags": []
+ },
+ "outputs": [],
+ "source": [
+ "# caschools_MLR_add_results <- ...(..., ..., ....) %>% mutate_if(is.numeric, round, 2)\n",
+ "# caschools_MLR_add_results\n",
+ "\n",
+ "# your code here\n",
+ "fail() # No Answer - remove if you provide an answer"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "deletable": false,
+ "editable": false,
+ "nbgrader": {
+ "cell_type": "code",
+ "checksum": "182cc3fee5a4319bbefb8dee3139a641",
+ "grade": true,
+ "grade_id": "cell-2e20842d0ef2e18c",
+ "locked": true,
+ "points": 1,
+ "schema_version": 3,
+ "solution": false,
+ "task": false
+ },
+ "tags": []
+ },
+ "outputs": [],
+ "source": [
+ "test_1.6()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "deletable": false,
+ "editable": false,
+ "nbgrader": {
+ "cell_type": "markdown",
+ "checksum": "99fa41618949973ba0ef9a3898cfcdac",
+ "grade": false,
+ "grade_id": "cell-045d79b6d3e4e227",
+ "locked": true,
+ "schema_version": 3,
+ "solution": false,
+ "task": false
+ }
+ },
+ "source": [
+ "**Question 1.7**\n",
+ "
{points: 1}\n",
+ "\n",
+ "Using the results in `caschools_MLR_add_results` from **Question 1.6**, how would you interpret the estimated coefficient of the continuous variable `income` ?"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "deletable": false,
+ "nbgrader": {
+ "cell_type": "markdown",
+ "checksum": "885cf006afa42b04df3d244c08372d30",
+ "grade": true,
+ "grade_id": "cell-c4f0c10f52097476",
+ "locked": false,
+ "points": 1,
+ "schema_version": 3,
+ "solution": true,
+ "task": false
+ },
+ "tags": []
+ },
+ "source": [
+ "> *Your answer goes here.*\n",
+ "\n",
+ "DOUBLE CLICK TO EDIT **THIS CELL** AND REPLACE THIS TEXT WITH YOUR ANSWER."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "deletable": false,
+ "editable": false,
+ "nbgrader": {
+ "cell_type": "markdown",
+ "checksum": "29524df0c431f38b0c86393221e632ae",
+ "grade": false,
+ "grade_id": "cell-2c547503213abacd",
+ "locked": true,
+ "schema_version": 3,
+ "solution": false,
+ "task": false
+ }
+ },
+ "source": [
+ "**Question 1.8**\n",
+ "
{points: 1}\n",
+ "\n",
+ "Using a **significance level $\\alpha = 0.10$**, which of the following claims are correct?\n",
+ "\n",
+ "\n",
+ "**A.** for any average income, the expected reading score is the same for schools with KK-06 and schools with KK-08 grades. \n",
+ "\n",
+ "**B.** there is enough evidence to reject the hypothesis that, for any average income, the expected reading score is the same for schools with KK-06 and schools with KK-08 grades.\n",
+ "\n",
+ "**C.** for any type of school, the change in `read` per unit change in `income` is statistically significant.\n",
+ "\n",
+ "**D.** there is enough evidence to believe that the association between `income` and `read` varies depending on the grade span of the school.\n",
+ "\n",
+ "\n",
+ "*Assign your answers to the object `answer1.8`. Your answers have to be included in a single string indicating the correct options **in alphabetical order** and surrounded by quotes (e.g., `\"ABCD\"` indicates you are selecting the four options).*"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "deletable": false,
+ "nbgrader": {
+ "cell_type": "code",
+ "checksum": "e77708faa194004e77f8a89d1d0fa38c",
+ "grade": false,
+ "grade_id": "cell-7ded1cd632f3869e",
+ "locked": false,
+ "schema_version": 3,
+ "solution": true,
+ "task": false
+ },
+ "tags": []
+ },
+ "outputs": [],
+ "source": [
+ "# answer1.8 <- \n",
+ "\n",
+ "# your code here\n",
+ "fail() # No Answer - remove if you provide an answer"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "deletable": false,
+ "editable": false,
+ "nbgrader": {
+ "cell_type": "code",
+ "checksum": "041fdc33a657af0a6e2e3f9dbd1d9fb7",
+ "grade": true,
+ "grade_id": "cell-51e7b8a61bab24c9",
+ "locked": true,
+ "points": 1,
+ "schema_version": 3,
+ "solution": false,
+ "task": false
+ },
+ "tags": []
+ },
+ "outputs": [],
+ "source": [
+ "test_1.8()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "deletable": false,
+ "editable": false,
+ "nbgrader": {
+ "cell_type": "markdown",
+ "checksum": "66e67b9204bf0f10fb51ab869301f118",
+ "grade": false,
+ "grade_id": "cell-e9994b034ba662aa",
+ "locked": true,
+ "schema_version": 3,
+ "solution": false,
+ "task": false
+ },
+ "tags": []
+ },
+ "source": [
+ "**Question 1.9**\n",
+ "
{points: 1}\n",
+ "\n",
+ "In one or two sentence explain what \"statistically significant\" mean in the following sentence and how it is different from \"practical significant\".\n",
+ "\n",
+ "> \"for any type of school, the change in `read` per unit change in `income` is statistically significant\"\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "deletable": false,
+ "nbgrader": {
+ "cell_type": "markdown",
+ "checksum": "a810e419b66aa68785aac7a6f64b97e0",
+ "grade": true,
+ "grade_id": "cell-66c583a8d25d2564",
+ "locked": false,
+ "points": 1,
+ "schema_version": 3,
+ "solution": true,
+ "task": false
+ },
+ "tags": []
+ },
+ "source": [
+ "> *Your answer goes here.*\n",
+ "\n",
+ "DOUBLE CLICK TO EDIT **THIS CELL** AND REPLACE THIS TEXT WITH YOUR ANSWER."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "deletable": false,
+ "editable": false,
+ "nbgrader": {
+ "cell_type": "markdown",
+ "checksum": "2a9dc9062fbfdf7e4d6b107eacc71562",
+ "grade": false,
+ "grade_id": "cell-873ce5c231e18f2c",
+ "locked": true,
+ "schema_version": 3,
+ "solution": false,
+ "task": false
+ },
+ "tags": []
+ },
+ "source": [
+ "## 2. MLR: with interactions\n",
+ "\n",
+ "In this section we will explore if the relation between `read` and `income` is the same for all types of schools. We can do this using **interactions** between the input variables!\n",
+ "\n",
+ "> **Note** that interactions can be used, in general, when the relation between an input and the response depends on another input variable (not necessarily categorical!)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "deletable": false,
+ "editable": false,
+ "nbgrader": {
+ "cell_type": "markdown",
+ "checksum": "4fa6f32f5ed0f62df4758f88422b5fcd",
+ "grade": false,
+ "grade_id": "cell-004da4c289bb7b52",
+ "locked": true,
+ "schema_version": 3,
+ "solution": false,
+ "task": false
+ }
+ },
+ "source": [
+ "**Question 2.0**\n",
+ "
{points: 1}\n",
+ "\n",
+ "We can use `lm` to fit the MLR with interactions between the continuous variable `income` and the categorical variable `grades` (with 2 levels) defined above.\n",
+ "\n",
+ "How many regression coefficients will be estimated by `lm`?\n",
+ "\n",
+ "**A.** 1\n",
+ "\n",
+ "**B.** 2\n",
+ "\n",
+ "**C.** 3\n",
+ "\n",
+ "**D.** 4\n",
+ "\n",
+ "\n",
+ "*Assign your answer to an object called `answer2.0`. Your answer should be one of `\"A\"`, `\"B\"`, `\"C\"`, `\"D\"`, `\"E\"`, or `\"F\"` surrounded by quotes.*"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "deletable": false,
+ "nbgrader": {
+ "cell_type": "code",
+ "checksum": "c879ea7b9e4c78544e35bad40039dbff",
+ "grade": false,
+ "grade_id": "cell-598588b1701bd38d",
+ "locked": false,
+ "schema_version": 3,
+ "solution": true,
+ "task": false
+ },
+ "tags": []
+ },
+ "outputs": [],
+ "source": [
+ "# answer2.0 <- \n",
+ "\n",
+ "# your code here\n",
+ "fail() # No Answer - remove if you provide an answer"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "deletable": false,
+ "editable": false,
+ "nbgrader": {
+ "cell_type": "code",
+ "checksum": "7392fce520cd1b366107f36865b48507",
+ "grade": true,
+ "grade_id": "cell-632b241ba713f5aa",
+ "locked": true,
+ "points": 1,
+ "schema_version": 3,
+ "solution": false,
+ "task": false
+ },
+ "tags": []
+ },
+ "outputs": [],
+ "source": [
+ "test_2.0()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "deletable": false,
+ "editable": false,
+ "nbgrader": {
+ "cell_type": "markdown",
+ "checksum": "38550478a20bfdac1e3007e1eeaa8707",
+ "grade": false,
+ "grade_id": "cell-d67f4a30fbd6b249",
+ "locked": true,
+ "schema_version": 3,
+ "solution": false,
+ "task": false
+ }
+ },
+ "source": [
+ "**Question 2.1**\n",
+ "
{points: 1}\n",
+ "\n",
+ "Using `caschools`, estimate the MLR with interaction described above and called it `caschools_MLR_int`.\n",
+ "\n",
+ "> **Hint:** Interaction terms can be easily specified in `lm()` using the notation `*`.\n",
+ "\n",
+ "*Fill out those parts indicated with `...`, uncomment the corresponding code in the cell below, and run it.*"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "deletable": false,
+ "nbgrader": {
+ "cell_type": "code",
+ "checksum": "3f7cd83f01098924b263228b29661d5e",
+ "grade": false,
+ "grade_id": "cell-d99a7bc9a1759fac",
+ "locked": false,
+ "schema_version": 3,
+ "solution": true,
+ "task": false
+ },
+ "tags": []
+ },
+ "outputs": [],
+ "source": [
+ "# caschools_MLR_int <- ...(...,\n",
+ "# ...\n",
+ "# )\n",
+ "# caschools_MLR_int\n",
+ "\n",
+ "# your code here\n",
+ "fail() # No Answer - remove if you provide an answer"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "deletable": false,
+ "editable": false,
+ "nbgrader": {
+ "cell_type": "code",
+ "checksum": "2fdb37752dd73b167cb7c10e09747df9",
+ "grade": true,
+ "grade_id": "cell-a2d3def81c3ee729",
+ "locked": true,
+ "points": 1,
+ "schema_version": 3,
+ "solution": false,
+ "task": false
+ },
+ "tags": []
+ },
+ "outputs": [],
+ "source": [
+ "test_2.1.0()\n",
+ "test_2.1.1()\n",
+ "test_2.1.2()\n",
+ "test_2.1.3()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "deletable": false,
+ "editable": false,
+ "nbgrader": {
+ "cell_type": "markdown",
+ "checksum": "cf9923865860d6e214047d8d307a97e2",
+ "grade": false,
+ "grade_id": "cell-1fc6d7f5ba4c6352",
+ "locked": true,
+ "schema_version": 3,
+ "solution": false,
+ "task": false
+ }
+ },
+ "source": [
+ "**Question 2.2**\n",
+ "
{points: 1}\n",
+ "\n",
+ "Create a plot of the data in `caschools` (using `geom_point()`) along with the estimated regression lines coming from the interaction regression model `caschools_MLR_int` (note that your plot should have two regression lines, one for each `grades`). Use different colours for the points and regression lines of each type of school (levels of `grades`). Include a legend indicating what colour corresponds to each level with proper axis labels. The `ggplot()` object's name will be `caschools_MLR_int_plot`.\n",
+ "\n",
+ "*Fill out those parts indicated with `...`, uncomment the corresponding code in the cell below, and run it.*"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "deletable": false,
+ "nbgrader": {
+ "cell_type": "code",
+ "checksum": "f174d5a9cf49023348e6d142454b81c4",
+ "grade": false,
+ "grade_id": "cell-0264d31dfcee946e",
+ "locked": false,
+ "schema_version": 3,
+ "solution": true,
+ "task": false
+ },
+ "tags": []
+ },
+ "outputs": [],
+ "source": [
+ "# caschools$pred_MLR_int <- predict(caschools_MLR_int) # Using predict() to create estimated regression lines.\n",
+ "\n",
+ "# caschools_MLR_int_plot <- ggplot(..., aes(\n",
+ "# ...,\n",
+ "# ...,\n",
+ "# color = ...\n",
+ "# )) +\n",
+ "# ...() +\n",
+ "# geom_line(aes(y = pred_MLR_int), size = 1) +\n",
+ "# labs(\n",
+ "# title = ...,\n",
+ "# x = ...,\n",
+ "# y = ...\n",
+ "# ) +\n",
+ "# theme(\n",
+ "# text = element_text(size = 16.5),\n",
+ "# plot.title = element_text(face = \"bold\"),\n",
+ "# axis.title = element_text(face = \"bold\"),\n",
+ "# legend.title = element_text(face = \"bold\"),\n",
+ "# ) +\n",
+ "# labs(color = \"grades\")\n",
+ "# caschools_MLR_int_plot\n",
+ "\n",
+ "# your code here\n",
+ "fail() # No Answer - remove if you provide an answer"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "deletable": false,
+ "editable": false,
+ "nbgrader": {
+ "cell_type": "code",
+ "checksum": "a0895f6f2f13d7ce6a6805aa3ca750a7",
+ "grade": true,
+ "grade_id": "cell-1de4883ebac641a7",
+ "locked": true,
+ "points": 1,
+ "schema_version": 3,
+ "solution": false,
+ "task": false
+ },
+ "tags": []
+ },
+ "outputs": [],
+ "source": [
+ "test_2.2()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "deletable": false,
+ "editable": false,
+ "nbgrader": {
+ "cell_type": "markdown",
+ "checksum": "766e5717f264eef3dd6af79a62b04deb",
+ "grade": false,
+ "grade_id": "cell-e850e2f516d793c9",
+ "locked": true,
+ "schema_version": 3,
+ "solution": false,
+ "task": false
+ }
+ },
+ "source": [
+ "**Question 2.3**\n",
+ "
{points: 1}\n",
+ "\n",
+ "Find the estimated coefficients of `caschools_MLR_int` using `tidy()`. Report the estimated coefficients, their standard errors and corresponding $p$-values. Include the corresponding asymptotic 90% confidence intervals. Store the results in the variable `caschools_MLR_int_results`.\n",
+ "\n",
+ "*Fill out those parts indicated with `...`, uncomment the corresponding code in the cell below, and run it.*"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "deletable": false,
+ "nbgrader": {
+ "cell_type": "code",
+ "checksum": "41ef5655a7cbfe3e5ae00bdddcae0a2a",
+ "grade": false,
+ "grade_id": "cell-b8a3711ac0aa9e78",
+ "locked": false,
+ "schema_version": 3,
+ "solution": true,
+ "task": false
+ },
+ "tags": []
+ },
+ "outputs": [],
+ "source": [
+ "# caschools_MLR_int_results <- ...(..., ..., ....) %>% mutate_if(is.numeric, round, 2)\n",
+ "# caschools_MLR_int_results\n",
+ "\n",
+ "# your code here\n",
+ "fail() # No Answer - remove if you provide an answer"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "deletable": false,
+ "editable": false,
+ "nbgrader": {
+ "cell_type": "code",
+ "checksum": "243d015f2afebda5db3917619f72d6fd",
+ "grade": true,
+ "grade_id": "cell-db1c5162e30c84bd",
+ "locked": true,
+ "points": 1,
+ "schema_version": 3,
+ "solution": false,
+ "task": false
+ },
+ "tags": []
+ },
+ "outputs": [],
+ "source": [
+ "test_2.3()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "deletable": false,
+ "editable": false,
+ "nbgrader": {
+ "cell_type": "markdown",
+ "checksum": "08d7282803f182d6211ed4dbf302b04c",
+ "grade": false,
+ "grade_id": "cell-3867f871a7af4b28",
+ "locked": true,
+ "schema_version": 3,
+ "solution": false,
+ "task": false
+ }
+ },
+ "source": [
+ "**Question 2.4**\n",
+ "
{points: 1}\n",
+ "\n",
+ "Using a **significance level $\\alpha = 0.10$**, which of the following claims are correct?\n",
+ "\n",
+ "\n",
+ "**A.** There is enough evidence to reject the hypothesis that, for any average income, the expected reading score is the same for schools with KK-06 and schools with KK-08 grades.\n",
+ "\n",
+ "**B.** For any type of school, the change in `read` per unit change in `income` is statistically significant.\n",
+ "\n",
+ "**C.** There is enough evidence to reject the hypothesis that the change in `read` per unit change in `income` is the same for schools with KK-06 and schools with KK-08 grades.\n",
+ "\n",
+ "**D.** There is not enough evidence to reject the hypothesis that the change in `read` per unit change in `income` is the same for schools with KK-06 and schools with KK-08 grades.\n",
+ "\n",
+ "**E.** For schools with KK-06 grade span, the change in `read` per unit change in `income` is statistically significant.\n",
+ "\n",
+ "*Assign your answers to the object `answer2.4`. Your answers have to be included in a single string indicating the correct options **in alphabetical order** and surrounded by quotes (e.g., `\"ABCDEFG\"` indicates you are selecting the seven options).*"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "deletable": false,
+ "nbgrader": {
+ "cell_type": "code",
+ "checksum": "feef0f6cf6e41f07ab507be043fcd7fa",
+ "grade": false,
+ "grade_id": "cell-8040936e931b0c26",
+ "locked": false,
+ "schema_version": 3,
+ "solution": true,
+ "task": false
+ },
+ "tags": []
+ },
+ "outputs": [],
+ "source": [
+ "# answer2.4 <- \n",
+ "\n",
+ "# your code here\n",
+ "fail() # No Answer - remove if you provide an answer"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "deletable": false,
+ "editable": false,
+ "nbgrader": {
+ "cell_type": "code",
+ "checksum": "3e0e9dc82c3cc0b9ec220187142156a4",
+ "grade": true,
+ "grade_id": "cell-1873e4d29d602968",
+ "locked": true,
+ "points": 1,
+ "schema_version": 3,
+ "solution": false,
+ "task": false
+ },
+ "tags": []
+ },
+ "outputs": [],
+ "source": [
+ "test_2.4()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "deletable": false,
+ "editable": false,
+ "nbgrader": {
+ "cell_type": "markdown",
+ "checksum": "3f41bec2efe1206490c1b9db22847a4e",
+ "grade": false,
+ "grade_id": "cell-a4830b2233d003de",
+ "locked": true,
+ "schema_version": 3,
+ "solution": false,
+ "task": false
+ }
+ },
+ "source": [
+ "**Question 2.5**\n",
+ "
{points: 1}\n",
+ "\n",
+ "A common practice is not to interpret coefficients that are not statistically significant, since what you observe is not significantly different from 0 and reflects just noise in the data. Alternatively, you can provide an interpretation but with the caveat that the result is not statistically significant. \n",
+ "\n",
+ "Following the second approach, what would be a correct interpretation of estimated coefficient of the interaction term `income:gradesKK-08` from `caschools_MLR_int_results` in **Question 2.3**? (remember to comment on the significance of the result)."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "deletable": false,
+ "nbgrader": {
+ "cell_type": "markdown",
+ "checksum": "af5ae4b1617c5eb5fa76f953cc7fc90d",
+ "grade": true,
+ "grade_id": "cell-94b5d3fd08f12a3f",
+ "locked": false,
+ "points": 1,
+ "schema_version": 3,
+ "solution": true,
+ "task": false
+ }
+ },
+ "source": [
+ "> *Your answer goes here.*\n",
+ "\n",
+ "DOUBLE CLICK TO EDIT **THIS CELL** AND REPLACE THIS TEXT WITH YOUR ANSWER."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "deletable": false,
+ "editable": false,
+ "nbgrader": {
+ "cell_type": "markdown",
+ "checksum": "fec03cccfbc7e114c21bfd7fceaf1439",
+ "grade": false,
+ "grade_id": "cell-ad8a6bbdaf066526",
+ "locked": true,
+ "schema_version": 3,
+ "solution": false,
+ "task": false
+ }
+ },
+ "source": [
+ "**Question 2.6**\n",
+ "
{points: 1}\n",
+ "\n",
+ "Fit the following 3 models as indicated:\n",
+ "\n",
+ "**A.** a SLR with `read` as the response and `income` as the *only* input variable using only KK-06 schools in `caschools`. Use `tidy` to get estimated parameters and standard errors. Call the results `caschools_SLR_kk06_results`\n",
+ "\n",
+ "**B.** a SLR with `read` as the response and `income` as the *only* input variable using only KK-08 schools in `caschools`. Use `tidy` to get estimated parameters and standard errors. Call the results `caschools_SLR_kk08_results`\n",
+ "\n",
+ "**C.** a MLR with `read` as the response and `income` and `grades` as input variables, *including their interaction*, using `caschools`. Note that you already have the estimated parameters and standard errors in `caschools_MLR_int_results`. Uncomment the line to get the results again here.\n",
+ "\n",
+ "*Fill out those parts indicated with `...`, uncomment the corresponding code in the cell below, and run it.*"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "deletable": false,
+ "nbgrader": {
+ "cell_type": "code",
+ "checksum": "0162042f6abfbd87251fe0c24ba68add",
+ "grade": false,
+ "grade_id": "cell-6e18beb71a4fb71f",
+ "locked": false,
+ "schema_version": 3,
+ "solution": true,
+ "task": false
+ },
+ "tags": []
+ },
+ "outputs": [],
+ "source": [
+ "# caschools_SLR_kk06_results <- tidy(lm(... ~ ... , \n",
+ "# data= subset(...,... == ...))) %>% mutate_if(is.numeric, round, 2)\n",
+ "# caschools_SLR_kk06_results\n",
+ "\n",
+ "# caschools_SLR_kk08_results <- tidy(lm(... ~ ... , \n",
+ "# data= subset(...,... == ...))) %>% mutate_if(is.numeric, round, 2)\n",
+ "# caschools_SLR_kk08_results\n",
+ "\n",
+ "# caschools_MLR_int_results\n",
+ "\n",
+ "\n",
+ "# your code here\n",
+ "fail() # No Answer - remove if you provide an answer"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "deletable": false,
+ "editable": false,
+ "nbgrader": {
+ "cell_type": "code",
+ "checksum": "3588b0c0ddca3eaaa2cfe7eb68472928",
+ "grade": true,
+ "grade_id": "cell-7211318468890365",
+ "locked": true,
+ "points": 1,
+ "schema_version": 3,
+ "solution": false,
+ "task": false
+ },
+ "tags": []
+ },
+ "outputs": [],
+ "source": [
+ "test_2.6.0()\n",
+ "test_2.6.1()\n",
+ "test_2.6.2()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "deletable": false,
+ "editable": false,
+ "nbgrader": {
+ "cell_type": "markdown",
+ "checksum": "7607e9621ddc4c26db6df310297f81dc",
+ "grade": false,
+ "grade_id": "cell-22795bb3ed88a300",
+ "locked": true,
+ "schema_version": 3,
+ "solution": false,
+ "task": false
+ }
+ },
+ "source": [
+ "**Question 2.7**\n",
+ "
{points: 1}\n",
+ "\n",
+ "**2.7.0** Using the results from `caschools_SLR_kk06_results` and `caschools_MLR_int_results` in **Question 2.6**, explain why the estimated coefficients of `income` are the same in both models\n",
+ "\n",
+ "**2.7.1** Using the results from `caschools_SLR_kk08_results` and `caschools_MLR_int_results` in **Question 2.6**, explain why the estimated coefficients of `income` are *not* the same in both models. \n",
+ "\n",
+ "**2.7.2** Explain why the estimated coefficients of `income` in `caschools_SLR_kk08_results` is *not* the same as that of `income:gradesKK-08` in `caschools_MLR_int_results` using the results from **Question 2.6**."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "deletable": false,
+ "nbgrader": {
+ "cell_type": "markdown",
+ "checksum": "8c6973a0f022fe93f2585f89c5365adb",
+ "grade": true,
+ "grade_id": "cell-1bc7a024f2ac0de4",
+ "locked": false,
+ "points": 1,
+ "schema_version": 3,
+ "solution": true,
+ "task": false
+ }
+ },
+ "source": [
+ "> *Your answer goes here.*\n",
+ "\n",
+ "DOUBLE CLICK TO EDIT **THIS CELL** AND REPLACE THIS TEXT WITH YOUR ANSWER."
+ ]
+ }
+ ],
+ "metadata": {
+ "jupytext": {
+ "formats": "ipynb,Rmd"
+ },
+ "kernelspec": {
+ "display_name": "R",
+ "language": "R",
+ "name": "ir"
+ },
+ "language_info": {
+ "codemirror_mode": "r",
+ "file_extension": ".r",
+ "mimetype": "text/x-r-source",
+ "name": "R",
+ "pygments_lexer": "r",
+ "version": "4.2.3"
+ },
+ "latex_envs": {
+ "LaTeX_envs_menu_present": true,
+ "autoclose": false,
+ "autocomplete": true,
+ "bibliofile": "biblio.bib",
+ "cite_by": "apalike",
+ "current_citInitial": 1,
+ "eqLabelWithNumbers": true,
+ "eqNumInitial": 1,
+ "hotkeys": {
+ "equation": "Ctrl-E",
+ "itemize": "Ctrl-I"
+ },
+ "labels_anchors": false,
+ "latex_user_defs": false,
+ "report_style_numbering": false,
+ "user_envs_cfg": false
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 4
+}