1
$\begingroup$

I am attempting to assess whether my explanatory variable of "startingpos" is best modelled via a quadratic regression model or a linear regression model. One way I can do this is to compute the models and assess their fit using the anova() function:

# example data
dat <- structure(list(FirstSteeringTime = c(0.3000240576829, 0.3833560075234, 
0.4333325988244, 0.332885282886096, 0.349735018357208, 0.500228955489106, 
0.33254630198401, 0.166676577506308, 0.400026140468498, 0.933583287728609, 
0.366613128009007, 0.400152315016001, 0.466582308819014, 0.43335584150401, 
0.516691111726999, 0.383459543097199, 0.483226482407986, 0.416576739631978, 
0.783127987777988, 0.449786605031989, 0.283220203865, 0.416811581253, 
0.383292920249005, 0.400114583392991, 0.18360026695899, 0.416630167609981, 
0.500080141967999, 0.466509864102989, 0.183366330894984, 0.69996205708, 
0.833361757822985, 0.516727937792041, 0.332522455597996, 0.38330197583997, 
0.533290611073994, 0.366722398789022, 0.316670042390001, 0.416698386385008, 
0.46657234767099, 0.733304737793958, 0.416654315848973, 0.433382404566999, 
0.416618697195986, 0.399949469809997, 0.733300000000042, 0.416799999999967, 
0.36669999999998, 0.433299999999974, 0.449899999999957, 0.616399999999999, 
0.398599999999988, 0.433400000000006, 0.599899999999991, 0.249961740134204, 
0.366800000000012, 0.466699999999946, 0.450099999999964, 0.300000000000011, 
0.466800000000035, 0.366199999999992, 0.300000000000011, 0.7166, 
0.483280000000001, 0.383409999999998, 0.366749999999996, 0.399969999999996, 
0.699960000000004, 0.61666, 0.582999999999998, 0.449999999999989, 
0.4495, 0.367099999999994, 0.416699999999992, 0.16670000000002, 
0.483250000000002, 0.367000000000019, 0.399999999999977, 0.583399999999983, 
0.516499999999979, 0.449899999999985, 0.466700000000003, 0.433300000000003, 
0.199899999999985, 0.433409999999999, 0.383399999999995, 0.416699999999992, 
0.416899999999998, 0.417000000000002, 0.4666, 0.400000000000006, 
0.282800000000009, 0.349999999999994, 0.299340000000001, 0.566699999999997, 
0.566600000000022, 0.4666, 0.466700000000003, 0.466699999999946, 
0.483299999999986, 0.416600000000017, 0.516700000000014, 0.533299999999997, 
0.333500000000015, 0.433199999999999, 0.61650000000003, 0.550000000000011, 
0.683300000000031, 0.38330000000002, 0.449999999999989, 0.433400000000006, 
0.483400000000017, 0.449999999999989, 0.466700000000003, 0.46669, 
0.399799999999999, 0.416605, 0.399989999999999, 0.416740000000004, 
0.366520000000001, 0.416670000000011, 0.583399999999997, 0.44999, 
0.550019999999989, 0.383279999999999, 0.333380000000005, 0.450000000000003, 
0.433400000000006, 0.565999999999988, 0.433400000000006, 0.383200000000002, 
0.549899999999994, 0.383399999999995, 0.549999999999983, 0.383299999999991, 
0.466819999999998, 0.716399999999993, 0.566499999999991, 0.400099999999981, 
0.533199999999994, 0.400000000000006, 0.616600000000005, 0.733399999999989, 
0.38335, 0.449899999999985, 0.449399999999997, 0.566699999999997, 
0.5, 0.483300000000014, 0.600099999999998, 0.5, 0.483439999999998, 
0.333400000000012, 0.516600000000011, 0.41670000000002, 0.483400000000017, 
0.54989999999998, 0.666699999999992, 0.716499999999996, 0.433300000000031, 
0.583300000000001, 0.433400000000006, 0.383299999999963, 0.433199999999999, 
0.633299999999963, 0.516599999999983, 0.499859999999998, 0.383299999999963, 
0.483400000000017, 0.400100000000009, 0.500099999999975, 0.500099999999975, 
0.416699999999992, 0.399999999999977, 0.433299999999974, 0.333399999999983, 
0.483300000000042, 0.550000000000011, 0.366700000000037, 0.449999999999989, 
0.383319999999998, 0.399824, 0.599970000000001, 0.5, 0.399969999999996, 
0.483379999999997, 0.550050000000013, 0.399969999999996, 0.366610000000001, 
0.400080000000003, 0.450100000000006, 0.683300000000003, 0.383200000000002, 
0.599999999999994, 0.583400000000012, 0.383290000000002, 0.349999999999994, 
0.333200000000005, 0.416799999999995, 0.566699999999997, 0.516099999999994, 
0.38330000000002, 0.382900000000006, 0.383399999999995, 0.466100000000012, 
0.366600000000005, 0.36669999999998, 0.433400000000006, 0.800000000000011, 
0.616700000000009, 0.433400000000006, 0.16670000000002, 0.599999999999994, 
0.516800000000018, 0.533299999999997, 0.550100000000043, 0.699999999999989, 
0.38330000000002, 0.416600000000017, 0.366570000000003, 0.400000000000034, 
0.466700000000003, 0.666799999999967, 0.583399999999983, 0.400100000000009, 
0.716600000000028, 0.599899999999991, 0.61669999999998, 0.416679999999999, 
0.466600000000028, 0.550000000000011, 0.599999999999966, 0.300099999999986, 
0.216599999999971, 0.5, 0.566699999999969, 0.383399999999995, 
0.449900000000014, 0.550099999999986, 0.466600000000028, 0.5, 
0.349999999999966, 0.416699999999992, 0.5, 0.583329999999997, 
0.400079999999999, 0.333350000000003, 0.39996, 0.449939999999998, 
0.400019999999998, 0.433340000000001, 0.450100000000006, 0.549980000000001, 
0.466790000000003, 0.25, 0.566599999999994, 0.666700000000006, 
0.566099999999992, 0.383399999999995, 0.349999999999994, 0.433290000000003, 
0.366700000000009, 0.41640000000001, 0.350100000000026, 0.350000000000023, 
0.416699999999992, 0.483299999999986, 0.566699999999997, 0.383299999999991, 
0.433400000000006, 0.399900000000002, 0.333400000000001, 0.349999999999994, 
0.199999999999989, 0.433399999999978, 0.366800000000012, 0.416600000000017, 
0.316900000000032, 0.466700000000003, 0.449999999999989, 0.400109999999998, 
0.183199999999999, 0.399900000000002, 0.366600000000005, 0.433300000000031, 
0.333300000000008, 0.483399999999961, 0.366700000000037, 0.517300000000034, 
0.383399999999995, 0.45010000000002, 0.566800000000001, 0.616600000000005, 
0.433499999999981, 0.483299999999986, 0.366199999999992, 0.449450000000006, 
0.383399999999995, 0.433399999999949, 0.699999999999989, 0.333399999999983, 
0.45010000000002, 0.333499999999958, 0.38344, 0.266697979166521, 
0.383198891827298, 0.516606743275602, 0.566645063859099, 0.483036463265194, 
0.48340925507739, 0.483681528935506, 0.516593159768306, 0.349836892262601, 
0.499657544687992, 0.566733809440009, 0.533366376472998, 0.383299107925993, 
0.549978704078995, 0.416578700880009, 0.700037822520983, 0.366653274334993, 
0.366637275980992, 0.616626333711991, 0.383385136805998, 0.416589265829003, 
0.466635434660986, 0.549884525094996, 0.400077758033007, 0.349995668371008, 
1.70000789965499, 0.600099999999998, 0.383400000000023, 0.400100000000009, 
0.416799999999995, 0.599900000000019, 0.4666, 0.583300000000008, 
0.516500000000008, 0.4666, 0.616700000000009, 0.483400000000017, 
0.566199999999981, 0.483400000000017, 0.516699999999958, 0.383299999999963, 
0.433400000000006, 0.399999999999977, 0.400000000000034, 0.45010000000002, 
0.566800000000001, 0.400000000000034, 0.483400000000017, 0.533299999999997, 
0.566700000000026, 0.516500000000008, 0.416500000000042, 0.382863228268405, 
0.500099999999975, 0.533400000000029, 0.416699999999992, 0.566700000000026, 
0.466700000000003, 0.41659999999996, 0.516700000000014, 0.45010000000002, 
0.300099999999986, 0.583399999999983, 0.433400000000006, 0.416600000000017, 
0.449999999999989, 0.666700000000048, 0.61669999999998, 0.383330000000001, 
0.44997, 0.500050000000002, 0.566670000000002, 0.5167, 0.433310000000006, 
0.732889999999998, 0.516690000000001, 0.516800000000003, 0.700000000000003, 
0.433400000000006, 0.616600000000005, 0.4161, 0.666599999999988, 
0.583300000000008, 0.299999999999983, 0.416500000000013, 0.466699999999999, 
0.433300000000003, 0.433500000000009, 0.466499999999996, 0.566800000000001, 
0.650000000000006, 0.500100000000003, 0.483399999999989, 0.333280000000002, 
0.5, 0.516600000000011, 0.566599999999994, 0.583300000000008, 
0.316800000000001, 0.516899999999993, 0.61669999999998, 0.316800000000001, 
0.599999999999994, 0.382999999999981, 0.533500000000004, 0.46629999999999, 
0.666699999999992, 0.433300000000031, 0.399999999999999, 0.399900000000002, 
0.550000000000011, 0.45010000000002, 0.550099999999986, 0.366600000000005, 
0.466700000000003, 0.566700000000026, 0.5, 0.366700000000037, 
0.316680000000005, 0.566800000000001, 0.416699999999992, 0.766500000000008, 
0.816599999999994, 0.449700000000007, 0.583300000000008, 0.499500000000012, 
0.516599999999983, 0.399499999999989, 0.532940000000004, 0.583300000000008, 
0.533299999999997, 0.5, 0.466599999999971, 0.483200000000011, 
0.5, 0.433299999999974, 0.650000000000034, 0.416699999999999, 
0.566574, 0.299979999999998, 0.333379999999998, 0.399949999999997, 
0.383309999999994, 0.533330000000007, 0.483369999999994, 0.500109999999992, 
0.483360000000005, 0.616789999999995, 0.5, 0.400099999999995, 
0.5501, 0.599599999999995, 0.433199999999999, 0.416600000000003, 
0.483400000000017, 0.316199999999981, 0.800000000000011, 0.616669999999999, 
0.599999999999994, 0.483300000000014, 0.316700000000026, 0.533399999999972, 
0.549800000000005, 0.450000000000017, 0.466700000000003, 0.41666, 
0.516700000000014, 0.5, 0.566600000000022, 0.383400000000023, 
0.4666, 0.33329999999998, 0.4666, 0.333300000000008, 0.35004, 
0.433300000000003, 0.4666, 0.4666, 0.650100000000009, 0.483400000000017, 
0.499900000000025, 0.466700000000003, 0.416679999999999, 0.533400000000029, 
0.400100000000009, 0.416800000000023, 0.483299999999986, 0.41700000000003, 
0.566599999999994, 0.450000000000045, 1.19999999999999, 0.516700000000014, 
0.533399999999972, 0.516599999999983, 0.550000000000011, 0.466700000000003, 
0.816700000000026), startingpos = c(8L, 0L, 8L, 8L, 4L, 8L, 4L, 
8L, 0L, 0L, 8L, 4L, 4L, 0L, 0L, 0L, 8L, 8L, 0L, 4L, 4L, 4L, 4L, 
8L, 4L, 4L, 8L, 8L, 4L, 0L, 0L, 0L, 8L, 4L, 0L, 8L, 0L, 8L, 4L, 
0L, 0L, 4L, 4L, 8L, 8L, 0L, 8L, 8L, 0L, 0L, 4L, 4L, 0L, 4L, 0L, 
8L, 0L, 8L, 4L, 4L, 0L, 0L, 8L, 8L, 8L, 0L, 0L, 0L, 8L, 0L, 4L, 
4L, 8L, 0L, 0L, 8L, 0L, 4L, 8L, 4L, 0L, 4L, 8L, 4L, 8L, 0L, 8L, 
0L, 4L, 4L, 4L, 4L, 0L, 4L, 4L, 0L, 0L, 8L, 4L, 8L, 8L, 0L, 8L, 
0L, 8L, 4L, 0L, 0L, 0L, 8L, 4L, 4L, 8L, 4L, 8L, 4L, 0L, 4L, 0L, 
4L, 0L, 0L, 4L, 8L, 8L, 8L, 8L, 0L, 8L, 4L, 0L, 8L, 4L, 0L, 4L, 
0L, 4L, 8L, 8L, 0L, 4L, 0L, 8L, 4L, 0L, 4L, 8L, 4L, 4L, 0L, 8L, 
4L, 0L, 4L, 0L, 0L, 4L, 0L, 8L, 0L, 0L, 8L, 8L, 0L, 8L, 8L, 4L, 
8L, 0L, 8L, 0L, 8L, 4L, 8L, 0L, 4L, 4L, 0L, 4L, 4L, 4L, 0L, 0L, 
4L, 4L, 0L, 8L, 0L, 4L, 4L, 0L, 8L, 8L, 4L, 8L, 8L, 8L, 8L, 0L, 
8L, 8L, 8L, 4L, 4L, 4L, 8L, 0L, 0L, 8L, 0L, 4L, 8L, 0L, 4L, 0L, 
0L, 8L, 0L, 0L, 4L, 4L, 0L, 0L, 4L, 0L, 4L, 8L, 4L, 8L, 0L, 8L, 
4L, 0L, 8L, 8L, 4L, 8L, 4L, 4L, 0L, 4L, 0L, 0L, 0L, 4L, 8L, 0L, 
0L, 4L, 0L, 0L, 0L, 4L, 8L, 4L, 0L, 0L, 8L, 4L, 4L, 4L, 4L, 8L, 
8L, 8L, 0L, 8L, 8L, 8L, 0L, 8L, 8L, 0L, 4L, 4L, 4L, 4L, 4L, 0L, 
8L, 4L, 0L, 8L, 4L, 8L, 8L, 8L, 0L, 0L, 8L, 8L, 0L, 4L, 4L, 0L, 
8L, 4L, 4L, 0L, 8L, 4L, 8L, 8L, 8L, 4L, 4L, 8L, 8L, 4L, 8L, 0L, 
4L, 4L, 4L, 0L, 8L, 4L, 8L, 8L, 0L, 8L, 0L, 0L, 4L, 0L, 0L, 8L, 
4L, 8L, 8L, 4L, 8L, 0L, 4L, 4L, 4L, 8L, 8L, 0L, 4L, 4L, 8L, 0L, 
0L, 4L, 0L, 4L, 8L, 8L, 0L, 8L, 4L, 0L, 0L, 4L, 0L, 8L, 4L, 4L, 
0L, 0L, 4L, 0L, 0L, 4L, 8L, 8L, 8L, 0L, 0L, 4L, 4L, 8L, 8L, 4L, 
8L, 0L, 0L, 8L, 8L, 0L, 8L, 8L, 8L, 8L, 4L, 0L, 4L, 0L, 4L, 8L, 
0L, 0L, 8L, 0L, 4L, 4L, 8L, 4L, 0L, 4L, 4L, 4L, 0L, 8L, 4L, 8L, 
0L, 4L, 4L, 0L, 8L, 0L, 0L, 4L, 4L, 0L, 0L, 4L, 0L, 0L, 8L, 8L, 
8L, 8L, 0L, 4L, 0L, 8L, 0L, 4L, 4L, 4L, 0L, 0L, 8L, 8L, 8L, 4L, 
0L, 8L, 8L, 8L, 4L, 4L, 8L, 8L, 8L, 0L, 8L, 0L, 8L, 4L, 4L, 8L, 
0L, 0L, 0L, 4L, 0L, 0L, 8L, 0L, 8L, 8L, 4L, 8L, 0L, 8L, 8L, 4L, 
0L, 8L, 0L, 4L, 8L, 8L, 8L, 0L, 4L, 8L, 8L, 4L, 8L, 4L, 8L, 0L, 
4L, 4L, 0L, 0L, 4L, 4L, 4L, 0L, 8L, 0L, 4L, 4L, 4L), startingpos_scaled = c(1.17470509188833, 
-1.28660587865873, 1.17470509188833, 1.17470509188833, -0.0559503933851987, 
1.17470509188833, -0.0559503933851987, 1.17470509188833, -1.28660587865873, 
-1.28660587865873, 1.17470509188833, -0.0559503933851987, -0.0559503933851987, 
-1.28660587865873, -1.28660587865873, -1.28660587865873, 1.17470509188833, 
1.17470509188833, -1.28660587865873, -0.0559503933851987, -0.0559503933851987, 
-0.0559503933851987, -0.0559503933851987, 1.17470509188833, -0.0559503933851987, 
-0.0559503933851987, 1.17470509188833, 1.17470509188833, -0.0559503933851987, 
-1.28660587865873, -1.28660587865873, -1.28660587865873, 1.17470509188833, 
-0.0559503933851987, -1.28660587865873, 1.17470509188833, -1.28660587865873, 
1.17470509188833, -0.0559503933851987, -1.28660587865873, -1.28660587865873, 
-0.0559503933851987, -0.0559503933851987, 1.17470509188833, 1.17470509188833, 
-1.28660587865873, 1.17470509188833, 1.17470509188833, -1.28660587865873, 
-1.28660587865873, -0.0559503933851987, -0.0559503933851987, 
-1.28660587865873, -0.0559503933851987, -1.28660587865873, 1.17470509188833, 
-1.28660587865873, 1.17470509188833, -0.0559503933851987, -0.0559503933851987, 
-1.28660587865873, -1.28660587865873, 1.17470509188833, 1.17470509188833, 
1.17470509188833, -1.28660587865873, -1.28660587865873, -1.28660587865873, 
1.17470509188833, -1.28660587865873, -0.0559503933851987, -0.0559503933851987, 
1.17470509188833, -1.28660587865873, -1.28660587865873, 1.17470509188833, 
-1.28660587865873, -0.0559503933851987, 1.17470509188833, -0.0559503933851987, 
-1.28660587865873, -0.0559503933851987, 1.17470509188833, -0.0559503933851987, 
1.17470509188833, -1.28660587865873, 1.17470509188833, -1.28660587865873, 
-0.0559503933851987, -0.0559503933851987, -0.0559503933851987, 
-0.0559503933851987, -1.28660587865873, -0.0559503933851987, 
-0.0559503933851987, -1.28660587865873, -1.28660587865873, 1.17470509188833, 
-0.0559503933851987, 1.17470509188833, 1.17470509188833, -1.28660587865873, 
1.17470509188833, -1.28660587865873, 1.17470509188833, -0.0559503933851987, 
-1.28660587865873, -1.28660587865873, -1.28660587865873, 1.17470509188833, 
-0.0559503933851987, -0.0559503933851987, 1.17470509188833, -0.0559503933851987, 
1.17470509188833, -0.0559503933851987, -1.28660587865873, -0.0559503933851987, 
-1.28660587865873, -0.0559503933851987, -1.28660587865873, -1.28660587865873, 
-0.0559503933851987, 1.17470509188833, 1.17470509188833, 1.17470509188833, 
1.17470509188833, -1.28660587865873, 1.17470509188833, -0.0559503933851987, 
-1.28660587865873, 1.17470509188833, -0.0559503933851987, -1.28660587865873, 
-0.0559503933851987, -1.28660587865873, -0.0559503933851987, 
1.17470509188833, 1.17470509188833, -1.28660587865873, -0.0559503933851987, 
-1.28660587865873, 1.17470509188833, -0.0559503933851987, -1.28660587865873, 
-0.0559503933851987, 1.17470509188833, -0.0559503933851987, -0.0559503933851987, 
-1.28660587865873, 1.17470509188833, -0.0559503933851987, -1.28660587865873, 
-0.0559503933851987, -1.28660587865873, -1.28660587865873, -0.0559503933851987, 
-1.28660587865873, 1.17470509188833, -1.28660587865873, -1.28660587865873, 
1.17470509188833, 1.17470509188833, -1.28660587865873, 1.17470509188833, 
1.17470509188833, -0.0559503933851987, 1.17470509188833, -1.28660587865873, 
1.17470509188833, -1.28660587865873, 1.17470509188833, -0.0559503933851987, 
1.17470509188833, -1.28660587865873, -0.0559503933851987, -0.0559503933851987, 
-1.28660587865873, -0.0559503933851987, -0.0559503933851987, 
-0.0559503933851987, -1.28660587865873, -1.28660587865873, -0.0559503933851987, 
-0.0559503933851987, -1.28660587865873, 1.17470509188833, -1.28660587865873, 
-0.0559503933851987, -0.0559503933851987, -1.28660587865873, 
1.17470509188833, 1.17470509188833, -0.0559503933851987, 1.17470509188833, 
1.17470509188833, 1.17470509188833, 1.17470509188833, -1.28660587865873, 
1.17470509188833, 1.17470509188833, 1.17470509188833, -0.0559503933851987, 
-0.0559503933851987, -0.0559503933851987, 1.17470509188833, -1.28660587865873, 
-1.28660587865873, 1.17470509188833, -1.28660587865873, -0.0559503933851987, 
1.17470509188833, -1.28660587865873, -0.0559503933851987, -1.28660587865873, 
-1.28660587865873, 1.17470509188833, -1.28660587865873, -1.28660587865873, 
-0.0559503933851987, -0.0559503933851987, -1.28660587865873, 
-1.28660587865873, -0.0559503933851987, -1.28660587865873, -0.0559503933851987, 
1.17470509188833, -0.0559503933851987, 1.17470509188833, -1.28660587865873, 
1.17470509188833, -0.0559503933851987, -1.28660587865873, 1.17470509188833, 
1.17470509188833, -0.0559503933851987, 1.17470509188833, -0.0559503933851987, 
-0.0559503933851987, -1.28660587865873, -0.0559503933851987, 
-1.28660587865873, -1.28660587865873, -1.28660587865873, -0.0559503933851987, 
1.17470509188833, -1.28660587865873, -1.28660587865873, -0.0559503933851987, 
-1.28660587865873, -1.28660587865873, -1.28660587865873, -0.0559503933851987, 
1.17470509188833, -0.0559503933851987, -1.28660587865873, -1.28660587865873, 
1.17470509188833, -0.0559503933851987, -0.0559503933851987, -0.0559503933851987, 
-0.0559503933851987, 1.17470509188833, 1.17470509188833, 1.17470509188833, 
-1.28660587865873, 1.17470509188833, 1.17470509188833, 1.17470509188833, 
-1.28660587865873, 1.17470509188833, 1.17470509188833, -1.28660587865873, 
-0.0559503933851987, -0.0559503933851987, -0.0559503933851987, 
-0.0559503933851987, -0.0559503933851987, -1.28660587865873, 
1.17470509188833, -0.0559503933851987, -1.28660587865873, 1.17470509188833, 
-0.0559503933851987, 1.17470509188833, 1.17470509188833, 1.17470509188833, 
-1.28660587865873, -1.28660587865873, 1.17470509188833, 1.17470509188833, 
-1.28660587865873, -0.0559503933851987, -0.0559503933851987, 
-1.28660587865873, 1.17470509188833, -0.0559503933851987, -0.0559503933851987, 
-1.28660587865873, 1.17470509188833, -0.0559503933851987, 1.17470509188833, 
1.17470509188833, 1.17470509188833, -0.0559503933851987, -0.0559503933851987, 
1.17470509188833, 1.17470509188833, -0.0559503933851987, 1.17470509188833, 
-1.28660587865873, -0.0559503933851987, -0.0559503933851987, 
-0.0559503933851987, -1.28660587865873, 1.17470509188833, -0.0559503933851987, 
1.17470509188833, 1.17470509188833, -1.28660587865873, 1.17470509188833, 
-1.28660587865873, -1.28660587865873, -0.0559503933851987, -1.28660587865873, 
-1.28660587865873, 1.17470509188833, -0.0559503933851987, 1.17470509188833, 
1.17470509188833, -0.0559503933851987, 1.17470509188833, -1.28660587865873, 
-0.0559503933851987, -0.0559503933851987, -0.0559503933851987, 
1.17470509188833, 1.17470509188833, -1.28660587865873, -0.0559503933851987, 
-0.0559503933851987, 1.17470509188833, -1.28660587865873, -1.28660587865873, 
-0.0559503933851987, -1.28660587865873, -0.0559503933851987, 
1.17470509188833, 1.17470509188833, -1.28660587865873, 1.17470509188833, 
-0.0559503933851987, -1.28660587865873, -1.28660587865873, -0.0559503933851987, 
-1.28660587865873, 1.17470509188833, -0.0559503933851987, -0.0559503933851987, 
-1.28660587865873, -1.28660587865873, -0.0559503933851987, -1.28660587865873, 
-1.28660587865873, -0.0559503933851987, 1.17470509188833, 1.17470509188833, 
1.17470509188833, -1.28660587865873, -1.28660587865873, -0.0559503933851987, 
-0.0559503933851987, 1.17470509188833, 1.17470509188833, -0.0559503933851987, 
1.17470509188833, -1.28660587865873, -1.28660587865873, 1.17470509188833, 
1.17470509188833, -1.28660587865873, 1.17470509188833, 1.17470509188833, 
1.17470509188833, 1.17470509188833, -0.0559503933851987, -1.28660587865873, 
-0.0559503933851987, -1.28660587865873, -0.0559503933851987, 
1.17470509188833, -1.28660587865873, -1.28660587865873, 1.17470509188833, 
-1.28660587865873, -0.0559503933851987, -0.0559503933851987, 
1.17470509188833, -0.0559503933851987, -1.28660587865873, -0.0559503933851987, 
-0.0559503933851987, -0.0559503933851987, -1.28660587865873, 
1.17470509188833, -0.0559503933851987, 1.17470509188833, -1.28660587865873, 
-0.0559503933851987, -0.0559503933851987, -1.28660587865873, 
1.17470509188833, -1.28660587865873, -1.28660587865873, -0.0559503933851987, 
-0.0559503933851987, -1.28660587865873, -1.28660587865873, -0.0559503933851987, 
-1.28660587865873, -1.28660587865873, 1.17470509188833, 1.17470509188833, 
1.17470509188833, 1.17470509188833, -1.28660587865873, -0.0559503933851987, 
-1.28660587865873, 1.17470509188833, -1.28660587865873, -0.0559503933851987, 
-0.0559503933851987, -0.0559503933851987, -1.28660587865873, 
-1.28660587865873, 1.17470509188833, 1.17470509188833, 1.17470509188833, 
-0.0559503933851987, -1.28660587865873, 1.17470509188833, 1.17470509188833, 
1.17470509188833, -0.0559503933851987, -0.0559503933851987, 1.17470509188833, 
1.17470509188833, 1.17470509188833, -1.28660587865873, 1.17470509188833, 
-1.28660587865873, 1.17470509188833, -0.0559503933851987, -0.0559503933851987, 
1.17470509188833, -1.28660587865873, -1.28660587865873, -1.28660587865873, 
-0.0559503933851987, -1.28660587865873, -1.28660587865873, 1.17470509188833, 
-1.28660587865873, 1.17470509188833, 1.17470509188833, -0.0559503933851987, 
1.17470509188833, -1.28660587865873, 1.17470509188833, 1.17470509188833, 
-0.0559503933851987, -1.28660587865873, 1.17470509188833, -1.28660587865873, 
-0.0559503933851987, 1.17470509188833, 1.17470509188833, 1.17470509188833, 
-1.28660587865873, -0.0559503933851987, 1.17470509188833, 1.17470509188833, 
-0.0559503933851987, 1.17470509188833, -0.0559503933851987, 1.17470509188833, 
-1.28660587865873, -0.0559503933851987, -0.0559503933851987, 
-1.28660587865873, -1.28660587865873, -0.0559503933851987, -0.0559503933851987, 
-0.0559503933851987, -1.28660587865873, 1.17470509188833, -1.28660587865873, 
-0.0559503933851987, -0.0559503933851987, -0.0559503933851987
), pNum = 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, 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, 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, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 
10L, 10L, 10L, 10L)), row.names = c(NA, 500L), class = "data.frame")
# models

quadratic <- glmer(formula = FirstSteeringTime ~ I(startingpos_scaled^2) + (1 | pNum),
            family = Gamma(link = "identity"),
            data = dat)

linear <- glmer(formula = FirstSteeringTime ~ startingpos_scaled + (1 | pNum),
            family = Gamma(link = "identity"),
            data = dat)

anova(quadratic, linear, test = "Chisq")

Data: dat
Models:
quadratic: FirstSteeringTime ~ I(startingpos_scaled^2) + (1 | pNum)
linear: FirstSteeringTime ~ startingpos_scaled + (1 | pNum)
          Df     AIC     BIC logLik deviance  Chisq Chi Df Pr(>Chisq)    
quadratic  4 -736.42 -719.56 372.21  -744.42                             
linear     4 -744.14 -727.28 376.07  -752.14 7.7248      0  < 2.2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

This shows that the linear model is the better fit (lower AIC, lower deviance and significant chi squared.

However I was thinking of another way to compare the models. Would it be valid to compute individual regressions (linear and quadratic) for each subject, and then compare the coefficients using a t-test? For example:

quad_coefs <-  c()
linear_coefs <-  c()

for (i in c(1,10)){

  # Quadratic

  # Create temporary data frame:
df_tmp <- dat[dat$pNum == i,]
  # Perform regression:
reg_result <- lm(FirstSteeringTime ~ I(startingpos^2), data = df_tmp)
  # Get coefficient:
tmp_coef <- coef(reg_result)
# Store coefficient and intercept for each subject:
quad_coefs[i] <- tmp_coef[2] 

  # linear

  # Perform regression:
reg_result <- lm(FirstSteeringTime ~ startingpos, data = df_tmp)
  # Get coefficient:
tmp_coef <- coef(reg_result)
# Store coefficient and intercept for each subject:
linear_coefs[i] <- tmp_coef[2] 
}

linear_coefs <- na.omit(linear_coefs)
quad_coefs <- na.omit(quad_coefs)

t.test(linear_coefs, quad_coefs)

    Welch Two Sample t-test

data:  linear_coefs and quad_coefs
t = -1.2629, df = 1.0211, p-value = 0.4231
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
 -0.05398666  0.04378464
sample estimates:
    mean of x     mean of y 
-0.0056349833 -0.0005339694 

If a coefficient is the size of the effect of my explanatory variable on my dependent variable and if I have a significant difference between quadratic and linear coefficients, could I conclude that the model coefficient that was larger was the better fit?

Any thoughts and advice would be most appreciated, thank you!

$\endgroup$
1
  • 2
    $\begingroup$ First of all, it usually doesn't make sense to have a quadratic effect without the corresponding linear effect. Then, no, you can't compare model fits with your proposed approach. A coefficient being larger, does not mean a fit is better. And you are not even comparing the same coefficient but different coefficients. Can you please explain your reasoning in your question? $\endgroup$ – Roland Jan 29 '20 at 11:28
5
$\begingroup$

A couple of points:

  • As @Roland said, it is not a good idea to fit a model with a quadratic term of a variable without also including the linear term in the model.
  • You cannot compare the quadratic and linear models using a $\chi^2$ test because they are not nested. Namely, this test requires that one model is a special case of the other. For example, the following linear and quadratic can be compared:

    quadratic <- glmer(formula = FirstSteeringTime ~ poly(startingpos_scaled, 2) + (1 | pNum),
                       family = Gamma(link = "identity"), data = dat)
    
    linear <- glmer(formula = FirstSteeringTime ~ startingpos_scaled + (1 | pNum),
                    family = Gamma(link = "identity"), data = dat)
    
    anova(linear, quadratic)
    
  • The procedure your described of first fitting linear models per subject and then comparing the coefficients with a t-test is typically called a two-stage approach. Even though it can be done, it is less optimal than fitting the corresponding mixed-effects model. There are several reasons for this. Among others, this is because (i) in the t-test you are going to perform in the second step you do not account for the uncertainty in the estimated coefficients from the first step, (ii) this procedure will only be valid if you have missing completely at random missing data in the outcome, and (iii) that in your specific example in the mixed model you have assumed that a Gamma distribution is better for your data than a normal distribution. Hence, fitting a linear model for FirstSteeringTime does not seem appropriate.

$\endgroup$
0
$\begingroup$

It doesn't really make sense to compare two models using the anova() function when one model is not a sub-model of the other. So the p-value there is not interpretable. I suppose you could use the AIC to compare them but it's a little funny to have a quadratic term in the model without the main effect. The main reason is because a location shift in the predictor would result in the main effect being brought back into the model. You could hypothetically make an argument for the quadratic only model but that argument would probably undercut the need for hypothesis testing at all...But if you are doing the test, having an instability such as making the model formulation change inherently due to a simple location shift in the predictor is not ideal.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.