Skip to contents

test_direction() evaluates differences in mean direction across different tracks using a specified statistical test. It includes options for ANOVA, Kruskal-Wallis test, and Generalized Linear Models (GLM), and checks for assumptions such as normality and homogeneity of variances. For datasets with more than two tracks, it performs pairwise comparisons to identify specific differences between tracks.

Usage

test_direction(data, analysis = NULL)

Arguments

data

A track R object, which is a list consisting of two elements:

  • Trajectories: A list of interpolated trajectories, where each trajectory is a series of midpoints between consecutive footprints.

  • Footprints: A list of data frames containing footprint coordinates, metadata (e.g., image reference, ID), and a marker indicating whether the footprint is actual or inferred.

analysis

A character string specifying the type of analysis: "ANOVA", "Kruskal-Wallis", or "GLM". Default is "ANOVA".

Value

A list with the results of the statistical analysis and diagnostic tests:

  • normality_results: A matrix of test statistics and p-values from the Shapiro-Wilk test for each track, with rows for the test statistic and p-value, and columns for each track.

  • homogeneity_test: The result of Levene's test, including the p-value for homogeneity of variances.

  • ANOVA (If analysis is "ANOVA"): A list containing the ANOVA table and Tukey HSD post-hoc test results.

  • Kruskal_Wallis (If analysis is "Kruskal-Wallis"): A list containing the Kruskal-Wallis test result and Dunn's test post-hoc results.

  • GLM (If analysis is "GLM"): A summary of the GLM fit and pairwise comparisons.

Details

The test_direction() function performs the following operations:

  • Condition Testing:

    • Normality: Shapiro-Wilk test for normality on step direction data within each track.

    • Homogeneity of Variances: Levene's test for equal variances across tracks.

  • Statistical Analysis:

    • ANOVA: Compares step mean directions across tracks, assuming normality and homogeneity of variances. Includes Tukey's HSD post-hoc test for pairwise comparisons.

    • Kruskal-Wallis Test: Non-parametric alternative to ANOVA for comparing step median directions across tracks when assumptions are violated. Includes Dunn's test for pairwise comparisons.

    • GLM: Generalized Linear Model with a Gaussian family for comparing step means if ANOVA assumptions are not met. Pairwise comparisons in the GLM are conducted using estimated marginal means (least-squares means) with the emmeans package, which computes differences between group means while adjusting for multiple comparisons using Tukey’s method.

  • Direction Measurement:

    • The direction is measured in degrees. The reference direction, or 0 degrees, is considered to be along the positive x-axis. Angles are measured counterclockwise from the positive x-axis, with 0 degrees pointing directly along this axis.

Author

Humberto G. Ferrón

humberto.ferron@uv.es

Macroevolution and Functional Morphology Research Group (www.macrofun.es)

Cavanilles Institute of Biodiversity and Evolutionary Biology

Calle Catedrático José Beltrán Martínez, nº 2

46980 Paterna - Valencia - Spain

Phone: +34 (9635) 44477

Examples

# Example 1: Test for Differences in Direction Means with Pairwise Comparisons in MountTom dataset
test_direction(MountTom, analysis = "ANOVA")
#> Warning: The following tracks were removed from the analysis due to having 3 or fewer footprints: Track 05, Track 06, Track 10, Track 11, Track 12, Track 14, Track 17, Track 19, Track 20, Track 21, Track 22, Track 23.
#> Warning: One or more tracks do not follow a normal distribution (p-value <= 0.05). Assumptions for ANOVA are not met. Consider using 'Kruskal-Wallis' or 'GLM'.
#> $normality_results
#>              Track 01  Track 02  Track 03  Track 04    Track 07  Track 08
#> statistic.W 0.9651863 0.9159365 0.8835034 0.8785774 0.717041538 0.9574186
#> p_value     0.8507202 0.3596607 0.3254893 0.3029142 0.005672604 0.7996415
#>               Track 09  Track 13  Track 15  Track 16  Track 18
#> statistic.W 0.78162330 0.8903881 0.8576212 0.9064091 0.9483026
#> p_value     0.05691451 0.3590583 0.2198329 0.3294686 0.7250578
#> 
#> $homogeneity_test
#> Levene's Test for Homogeneity of Variance (center = median)
#>       Df F value  Pr(>F)  
#> group 10  1.8236 0.07643 .
#>       58                  
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#> 
#> $ANOVA
#> $ANOVA$ANOVA
#>             Df Sum Sq Mean Sq F value Pr(>F)    
#> track       10 372424   37242    1081 <2e-16 ***
#> Residuals   58   1999      34                   
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#> 
#> $ANOVA$Tukey
#>   Tukey multiple comparisons of means
#>     95% family-wise confidence level
#> 
#> Fit: aov(formula = dir ~ track, data = M_analysis)
#> 
#> $track
#>                           diff         lwr          upr     p adj
#> Track 02-Track 01   -8.0809326  -17.352515    1.1906495 0.1421812
#> Track 03-Track 01   -4.2235962  -15.193880    6.7466877 0.9669723
#> Track 04-Track 01   -8.9073199  -19.877604    2.0629641 0.2165280
#> Track 07-Track 01  -15.9377861  -25.849524   -6.0260479 0.0000688
#> Track 08-Track 01  -14.2962893  -24.662233   -3.9303453 0.0010286
#> Track 09-Track 01 -157.8393877 -168.809672 -146.8691037 0.0000000
#> Track 13-Track 01 -263.5986805 -274.568964 -252.6283965 0.0000000
#> Track 15-Track 01  -19.4449561  -30.415240   -8.4746721 0.0000090
#> Track 16-Track 01  -10.2244220  -19.781350   -0.6674939 0.0264453
#> Track 18-Track 01  -25.9444892  -36.914773  -14.9742053 0.0000000
#> Track 03-Track 02    3.8573364   -7.112948   14.8276203 0.9825136
#> Track 04-Track 02   -0.8263872  -11.796671   10.1438967 1.0000000
#> Track 07-Track 02   -7.8568535  -17.768592    2.0548847 0.2456248
#> Track 08-Track 02   -6.2153566  -16.581301    4.1505873 0.6437392
#> Track 09-Track 02 -149.7584550 -160.728739 -138.7881711 0.0000000
#> Track 13-Track 02 -255.5177478 -266.488032 -244.5474639 0.0000000
#> Track 15-Track 02  -11.3640234  -22.334307   -0.3937395 0.0362396
#> Track 16-Track 02   -2.1434894  -11.700418    7.4134387 0.9995411
#> Track 18-Track 02  -17.8635566  -28.833841   -6.8932727 0.0000536
#> Track 04-Track 03   -4.6837236  -17.122856    7.7554092 0.9716324
#> Track 07-Track 03  -11.7141899  -23.230589   -0.1977908 0.0429263
#> Track 08-Track 03  -10.0726930  -21.982256    1.8368699 0.1715168
#> Track 09-Track 03 -153.6157914 -166.054924 -141.1766587 0.0000000
#> Track 13-Track 03 -259.3750842 -271.814217 -246.9359515 0.0000000
#> Track 15-Track 03  -15.2213598  -27.660493   -2.7822271 0.0056705
#> Track 16-Track 03   -6.0008258  -17.213309    5.2116570 0.7791969
#> Track 18-Track 03  -21.7208930  -34.160026   -9.2817602 0.0000125
#> Track 07-Track 04   -7.0304663  -18.546865    4.4859329 0.6192299
#> Track 08-Track 04   -5.3889694  -17.298532    6.5205935 0.9084457
#> Track 09-Track 04 -148.9320678 -161.371201 -136.4929350 0.0000000
#> Track 13-Track 04 -254.6913606 -267.130493 -242.2522279 0.0000000
#> Track 15-Track 04  -10.5376362  -22.976769    1.9014966 0.1698520
#> Track 16-Track 04   -1.3171022  -12.529585    9.8953806 0.9999989
#> Track 18-Track 04  -17.0371694  -29.476302   -4.5980366 0.0011459
#> Track 08-Track 07    1.6414969   -9.300766   12.5837596 0.9999884
#> Track 09-Track 07 -141.9016015 -153.418001 -130.3852024 0.0000000
#> Track 13-Track 07 -247.6608943 -259.177293 -236.1444952 0.0000000
#> Track 15-Track 07   -3.5071699  -15.023569    8.0092292 0.9940963
#> Track 16-Track 07    5.7133641   -4.465791   15.8925190 0.7269309
#> Track 18-Track 07  -10.0067031  -21.523102    1.5096961 0.1450230
#> Track 09-Track 08 -143.5430984 -155.452661 -131.6335355 0.0000000
#> Track 13-Track 08 -249.3023912 -261.211954 -237.3928283 0.0000000
#> Track 15-Track 08   -5.1486668  -17.058230    6.7608961 0.9302534
#> Track 16-Track 08    4.0718672   -6.550065   14.6937990 0.9679259
#> Track 18-Track 08  -11.6482000  -23.557763    0.2613630 0.0605113
#> Track 13-Track 09 -105.7592928 -118.198426  -93.3201600 0.0000000
#> Track 15-Track 09  138.3944316  125.955299  150.8335644 0.0000000
#> Track 16-Track 09  147.6149656  136.402483  158.8274484 0.0000000
#> Track 18-Track 09  131.8948984  119.455766  144.3340312 0.0000000
#> Track 15-Track 13  244.1537244  231.714592  256.5928572 0.0000000
#> Track 16-Track 13  253.3742584  242.161776  264.5867412 0.0000000
#> Track 18-Track 13  237.6541912  225.215058  250.0933240 0.0000000
#> Track 16-Track 15    9.2205340   -1.991949   20.4330168 0.2018750
#> Track 18-Track 15   -6.4995332  -18.938666    5.9395996 0.8028891
#> Track 18-Track 16  -15.7200672  -26.932550   -4.5075844 0.0007922
#> 
#> 
#> 

# Example 2: Test for Differences in Direction Means with Pairwise Comparisons in MountTom dataset
test_direction(MountTom, analysis = "Kruskal-Wallis")
#> Warning: The following tracks were removed from the analysis due to having 3 or fewer footprints: Track 05, Track 06, Track 10, Track 11, Track 12, Track 14, Track 17, Track 19, Track 20, Track 21, Track 22, Track 23.
#> Warning: One or more tracks do not follow a normal distribution (p-value <= 0.05). Assumptions for ANOVA are not met. Consider using 'Kruskal-Wallis' or 'GLM'.
#>   Kruskal-Wallis rank sum test
#> 
#> data: x and group
#> Kruskal-Wallis chi-squared = 53.6361, df = 10, p-value = 0
#> 
#> 
#>                            Comparison of x by group                            
#>                                 (No adjustment)                                
#> Col Mean-|
#> Row Mean |   Track 01   Track 02   Track 03   Track 04   Track 07   Track 08
#> ---------+------------------------------------------------------------------
#> Track 02 |   1.879941
#>          |     0.0301
#>          |
#> Track 03 |   0.844071  -0.744769
#>          |     0.1993     0.2282
#>          |
#> Track 04 |   1.809292   0.220451   0.851244
#>          |     0.0352     0.4128     0.1973
#>          |
#> Track 07 |   2.969080   1.210555   1.751332   0.831882
#>          |    0.0015*     0.1130     0.0399     0.2027
#>          |
#> Track 08 |   2.974102   1.292630   1.811121   0.922025   0.128001
#>          |    0.0015*     0.0981     0.0351     0.1783     0.4491
#>          |
#> Track 09 |   4.865825   3.276984   3.546853   2.695608   2.079707   1.893445
#>          |    0.0000*    0.0005*    0.0002*    0.0035*    0.0188*     0.0291
#>          |
#> Track 13 |   5.312686   3.723845   3.940948   3.089703   2.505378   2.305064
#>          |    0.0000*    0.0001*    0.0000*    0.0010*    0.0061*    0.0106*
#>          |
#> Track 15 |   3.668236   2.079395   2.490679   1.639434   0.938908   0.790307
#>          |    0.0001*    0.0188*    0.0064*     0.0506     0.1739     0.2147
#>          |
#> Track 16 |   2.238443   0.414632   1.082092   0.137720  -0.789466  -0.888419
#>          |    0.0126*     0.3392     0.1396     0.4452     0.2149     0.1872
#>          |
#> Track 18 |   4.240219   2.651378   2.995120   2.143875   1.483767   1.317179
#>          |    0.0000*    0.0040*    0.0014*    0.0160*     0.0689     0.0939
#> Col Mean-|
#> Row Mean |   Track 09   Track 13   Track 15   Track 16
#> ---------+--------------------------------------------
#> Track 13 |   0.394094
#>          |     0.3468
#>          |
#> Track 15 |  -1.056174  -1.450268
#>          |     0.1454     0.0735
#>          |
#> Track 16 |  -2.852788  -3.289997  -1.681068
#>          |    0.0022*    0.0005*     0.0464
#>          |
#> Track 18 |  -0.551732  -0.945827   0.504441   2.240695
#>          |     0.2906     0.1721     0.3070    0.0125*
#> 
#> alpha = 0.05
#> Reject Ho if p <= alpha/2
#> $normality_results
#>              Track 01  Track 02  Track 03  Track 04    Track 07  Track 08
#> statistic.W 0.9651863 0.9159365 0.8835034 0.8785774 0.717041538 0.9574186
#> p_value     0.8507202 0.3596607 0.3254893 0.3029142 0.005672604 0.7996415
#>               Track 09  Track 13  Track 15  Track 16  Track 18
#> statistic.W 0.78162330 0.8903881 0.8576212 0.9064091 0.9483026
#> p_value     0.05691451 0.3590583 0.2198329 0.3294686 0.7250578
#> 
#> $homogeneity_test
#> Levene's Test for Homogeneity of Variance (center = median)
#>       Df F value  Pr(>F)  
#> group 10  1.8236 0.07643 .
#>       58                  
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#> 
#> $Kruskal_Wallis
#> $Kruskal_Wallis$Kruskal_Wallis
#> 
#> 	Kruskal-Wallis rank sum test
#> 
#> data:  dir by track
#> Kruskal-Wallis chi-squared = 53.636, df = 10, p-value = 5.671e-08
#> 
#> 
#> $Kruskal_Wallis$Dunn
#> $Kruskal_Wallis$Dunn$chi2
#> [1] 53.63609
#> 
#> $Kruskal_Wallis$Dunn$Z
#>  [1]  1.8799419  0.8440717 -0.7447692  1.8092926  0.2204517  0.8512448
#>  [7]  2.9690804  1.2105558  1.7513323  0.8318828  2.9741021  1.2926309
#> [13]  1.8111218  0.9220257  0.1280017  4.8658252  3.2769843  3.5468532
#> [19]  2.6956084  2.0797071  1.8934455  5.3126867  3.7238459  3.9409480
#> [25]  3.0897032  2.5053781  2.3050641  0.3940948  3.6682364  2.0793955
#> [31]  2.4906791  1.6394344  0.9389087  0.7903077 -1.0561741 -1.4502689
#> [37]  2.2384437  0.4146322  1.0820921  0.1377208 -0.7894666 -0.8884194
#> [43] -2.8527883 -3.2899972 -1.6810683  4.2402191  2.6513782  2.9951205
#> [49]  2.1438757  1.4837676  1.3171795 -0.5517327 -0.9458275  0.5044413
#> [55]  2.2406958
#> 
#> $Kruskal_Wallis$Dunn$P
#>  [1] 3.005800e-02 1.993147e-01 2.282056e-01 3.520278e-02 4.127597e-01
#>  [6] 1.973167e-01 1.493462e-03 1.130328e-01 3.994435e-02 2.027375e-01
#> [11] 1.469236e-03 9.806936e-02 3.506100e-02 1.782576e-01 4.490738e-01
#> [16] 5.699010e-07 5.246109e-04 1.949309e-04 3.513010e-03 1.877620e-02
#> [21] 2.914932e-02 5.401032e-08 9.810538e-05 4.058011e-05 1.001783e-03
#> [26] 6.116028e-03 1.058149e-02 3.467555e-01 1.221146e-04 1.879051e-02
#> [31] 6.374960e-03 5.056141e-02 1.738888e-01 2.146740e-01 1.454443e-01
#> [36] 7.349178e-02 1.259607e-02 3.392056e-01 1.396058e-01 4.452305e-01
#> [41] 2.149197e-01 1.871576e-01 2.166874e-03 5.009419e-04 4.637482e-02
#> [46] 1.116508e-05 4.008200e-03 1.371682e-03 1.602142e-02 6.893529e-02
#> [51] 9.388923e-02 2.905657e-01 1.721183e-01 3.069756e-01 1.252289e-02
#> 
#> $Kruskal_Wallis$Dunn$P.adjusted
#>  [1] 3.005800e-02 1.993147e-01 2.282056e-01 3.520278e-02 4.127597e-01
#>  [6] 1.973167e-01 1.493462e-03 1.130328e-01 3.994435e-02 2.027375e-01
#> [11] 1.469236e-03 9.806936e-02 3.506100e-02 1.782576e-01 4.490738e-01
#> [16] 5.699010e-07 5.246109e-04 1.949309e-04 3.513010e-03 1.877620e-02
#> [21] 2.914932e-02 5.401032e-08 9.810538e-05 4.058011e-05 1.001783e-03
#> [26] 6.116028e-03 1.058149e-02 3.467555e-01 1.221146e-04 1.879051e-02
#> [31] 6.374960e-03 5.056141e-02 1.738888e-01 2.146740e-01 1.454443e-01
#> [36] 7.349178e-02 1.259607e-02 3.392056e-01 1.396058e-01 4.452305e-01
#> [41] 2.149197e-01 1.871576e-01 2.166874e-03 5.009419e-04 4.637482e-02
#> [46] 1.116508e-05 4.008200e-03 1.371682e-03 1.602142e-02 6.893529e-02
#> [51] 9.388923e-02 2.905657e-01 1.721183e-01 3.069756e-01 1.252289e-02
#> 
#> $Kruskal_Wallis$Dunn$comparisons
#>  [1] "Track 01 - Track 02" "Track 01 - Track 03" "Track 02 - Track 03"
#>  [4] "Track 01 - Track 04" "Track 02 - Track 04" "Track 03 - Track 04"
#>  [7] "Track 01 - Track 07" "Track 02 - Track 07" "Track 03 - Track 07"
#> [10] "Track 04 - Track 07" "Track 01 - Track 08" "Track 02 - Track 08"
#> [13] "Track 03 - Track 08" "Track 04 - Track 08" "Track 07 - Track 08"
#> [16] "Track 01 - Track 09" "Track 02 - Track 09" "Track 03 - Track 09"
#> [19] "Track 04 - Track 09" "Track 07 - Track 09" "Track 08 - Track 09"
#> [22] "Track 01 - Track 13" "Track 02 - Track 13" "Track 03 - Track 13"
#> [25] "Track 04 - Track 13" "Track 07 - Track 13" "Track 08 - Track 13"
#> [28] "Track 09 - Track 13" "Track 01 - Track 15" "Track 02 - Track 15"
#> [31] "Track 03 - Track 15" "Track 04 - Track 15" "Track 07 - Track 15"
#> [34] "Track 08 - Track 15" "Track 09 - Track 15" "Track 13 - Track 15"
#> [37] "Track 01 - Track 16" "Track 02 - Track 16" "Track 03 - Track 16"
#> [40] "Track 04 - Track 16" "Track 07 - Track 16" "Track 08 - Track 16"
#> [43] "Track 09 - Track 16" "Track 13 - Track 16" "Track 15 - Track 16"
#> [46] "Track 01 - Track 18" "Track 02 - Track 18" "Track 03 - Track 18"
#> [49] "Track 04 - Track 18" "Track 07 - Track 18" "Track 08 - Track 18"
#> [52] "Track 09 - Track 18" "Track 13 - Track 18" "Track 15 - Track 18"
#> [55] "Track 16 - Track 18"
#> 
#> 
#> 

# Example 3: Test for Differences in Direction Means with Pairwise Comparisons in MountTom dataset
test_direction(MountTom, analysis = "GLM")
#> Warning: The following tracks were removed from the analysis due to having 3 or fewer footprints: Track 05, Track 06, Track 10, Track 11, Track 12, Track 14, Track 17, Track 19, Track 20, Track 21, Track 22, Track 23.
#> Warning: One or more tracks do not follow a normal distribution (p-value <= 0.05). Assumptions for ANOVA are not met. Consider using 'Kruskal-Wallis' or 'GLM'.
#> $normality_results
#>              Track 01  Track 02  Track 03  Track 04    Track 07  Track 08
#> statistic.W 0.9651863 0.9159365 0.8835034 0.8785774 0.717041538 0.9574186
#> p_value     0.8507202 0.3596607 0.3254893 0.3029142 0.005672604 0.7996415
#>               Track 09  Track 13  Track 15  Track 16  Track 18
#> statistic.W 0.78162330 0.8903881 0.8576212 0.9064091 0.9483026
#> p_value     0.05691451 0.3590583 0.2198329 0.3294686 0.7250578
#> 
#> $homogeneity_test
#> Levene's Test for Homogeneity of Variance (center = median)
#>       Df F value  Pr(>F)  
#> group 10  1.8236 0.07643 .
#>       58                  
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#> 
#> $GLM
#> $GLM$GLM
#> 
#> Call:
#> glm(formula = dir ~ track, family = gaussian(), data = M_analysis)
#> 
#> Coefficients:
#>               Estimate Std. Error t value Pr(>|t|)    
#> (Intercept)    136.609      1.957  69.810  < 2e-16 ***
#> trackTrack 02   -8.081      2.767  -2.920 0.004978 ** 
#> trackTrack 03   -4.224      3.274  -1.290 0.202220    
#> trackTrack 04   -8.907      3.274  -2.720 0.008595 ** 
#> trackTrack 07  -15.938      2.959  -5.387 1.36e-06 ***
#> trackTrack 08  -14.296      3.094  -4.621 2.18e-05 ***
#> trackTrack 09 -157.839      3.274 -48.203  < 2e-16 ***
#> trackTrack 13 -263.599      3.274 -80.501  < 2e-16 ***
#> trackTrack 15  -19.445      3.274  -5.938 1.72e-07 ***
#> trackTrack 16  -10.224      2.853  -3.584 0.000694 ***
#> trackTrack 18  -25.944      3.274  -7.923 8.24e-11 ***
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#> 
#> (Dispersion parameter for gaussian family taken to be 34.4641)
#> 
#>     Null deviance: 374423.4  on 68  degrees of freedom
#> Residual deviance:   1998.9  on 58  degrees of freedom
#> AIC: 452.09
#> 
#> Number of Fisher Scoring iterations: 2
#> 
#> 
#> $GLM$pairwise_results
#> $emmeans
#>  track    emmean   SE df lower.CL upper.CL
#>  Track 01  136.6 1.96 58    132.7      141
#>  Track 02  128.5 1.96 58    124.6      132
#>  Track 03  132.4 2.63 58    127.1      138
#>  Track 04  127.7 2.63 58    122.4      133
#>  Track 07  120.7 2.22 58    116.2      125
#>  Track 08  122.3 2.40 58    117.5      127
#>  Track 09  -21.2 2.63 58    -26.5      -16
#>  Track 13 -127.0 2.63 58   -132.2     -122
#>  Track 15  117.2 2.63 58    111.9      122
#>  Track 16  126.4 2.08 58    122.2      131
#>  Track 18  110.7 2.63 58    105.4      116
#> 
#> Confidence level used: 0.95 
#> 
#> $contrasts
#>  contrast            estimate   SE df t.ratio p.value
#>  Track 01 - Track 02    8.081 2.77 58   2.920  0.1422
#>  Track 01 - Track 03    4.224 3.27 58   1.290  0.9670
#>  Track 01 - Track 04    8.907 3.27 58   2.720  0.2165
#>  Track 01 - Track 07   15.938 2.96 58   5.387  0.0001
#>  Track 01 - Track 08   14.296 3.09 58   4.621  0.0010
#>  Track 01 - Track 09  157.839 3.27 58  48.203  <.0001
#>  Track 01 - Track 13  263.599 3.27 58  80.501  <.0001
#>  Track 01 - Track 15   19.445 3.27 58   5.938  <.0001
#>  Track 01 - Track 16   10.224 2.85 58   3.584  0.0264
#>  Track 01 - Track 18   25.944 3.27 58   7.923  <.0001
#>  Track 02 - Track 03   -3.857 3.27 58  -1.178  0.9825
#>  Track 02 - Track 04    0.826 3.27 58   0.252  1.0000
#>  Track 02 - Track 07    7.857 2.96 58   2.656  0.2456
#>  Track 02 - Track 08    6.215 3.09 58   2.009  0.6437
#>  Track 02 - Track 09  149.758 3.27 58  45.735  <.0001
#>  Track 02 - Track 13  255.518 3.27 58  78.033  <.0001
#>  Track 02 - Track 15   11.364 3.27 58   3.470  0.0362
#>  Track 02 - Track 16    2.143 2.85 58   0.751  0.9995
#>  Track 02 - Track 18   17.864 3.27 58   5.455  0.0001
#>  Track 03 - Track 04    4.684 3.71 58   1.261  0.9716
#>  Track 03 - Track 07   11.714 3.44 58   3.408  0.0429
#>  Track 03 - Track 08   10.073 3.55 58   2.834  0.1715
#>  Track 03 - Track 09  153.616 3.71 58  41.374  <.0001
#>  Track 03 - Track 13  259.375 3.71 58  69.858  <.0001
#>  Track 03 - Track 15   15.221 3.71 58   4.100  0.0057
#>  Track 03 - Track 16    6.001 3.35 58   1.793  0.7792
#>  Track 03 - Track 18   21.721 3.71 58   5.850  <.0001
#>  Track 04 - Track 07    7.030 3.44 58   2.045  0.6192
#>  Track 04 - Track 08    5.389 3.55 58   1.516  0.9084
#>  Track 04 - Track 09  148.932 3.71 58  40.112  <.0001
#>  Track 04 - Track 13  254.691 3.71 58  68.596  <.0001
#>  Track 04 - Track 15   10.538 3.71 58   2.838  0.1699
#>  Track 04 - Track 16    1.317 3.35 58   0.394  1.0000
#>  Track 04 - Track 18   17.037 3.71 58   4.589  0.0011
#>  Track 07 - Track 08   -1.641 3.27 58  -0.503  1.0000
#>  Track 07 - Track 09  141.902 3.44 58  41.281  <.0001
#>  Track 07 - Track 13  247.661 3.44 58  72.047  <.0001
#>  Track 07 - Track 15    3.507 3.44 58   1.020  0.9941
#>  Track 07 - Track 16   -5.713 3.04 58  -1.880  0.7269
#>  Track 07 - Track 18   10.007 3.44 58   2.911  0.1450
#>  Track 08 - Track 09  143.543 3.55 58  40.380  <.0001
#>  Track 08 - Track 13  249.302 3.55 58  70.131  <.0001
#>  Track 08 - Track 15    5.149 3.55 58   1.448  0.9303
#>  Track 08 - Track 16   -4.072 3.17 58  -1.284  0.9679
#>  Track 08 - Track 18   11.648 3.55 58   3.277  0.0605
#>  Track 09 - Track 13  105.759 3.71 58  28.484  <.0001
#>  Track 09 - Track 15 -138.394 3.71 58 -37.274  <.0001
#>  Track 09 - Track 16 -147.615 3.35 58 -44.107  <.0001
#>  Track 09 - Track 18 -131.895 3.71 58 -35.523  <.0001
#>  Track 13 - Track 15 -244.154 3.71 58 -65.758  <.0001
#>  Track 13 - Track 16 -253.374 3.35 58 -75.707  <.0001
#>  Track 13 - Track 18 -237.654 3.71 58 -64.008  <.0001
#>  Track 15 - Track 16   -9.221 3.35 58  -2.755  0.2019
#>  Track 15 - Track 18    6.500 3.71 58   1.751  0.8029
#>  Track 16 - Track 18   15.720 3.35 58   4.697  0.0008
#> 
#> P value adjustment: tukey method for comparing a family of 11 estimates 
#> 
#> 
#> 

# Example 4: Test for Differences in Direction Means with Pairwise Comparisons in PaluxyRiver
# dataset
test_direction(PaluxyRiver, analysis = "ANOVA")
#> Warning: One or more tracks do not follow a normal distribution (p-value <= 0.05). Assumptions for ANOVA are not met. Consider using 'Kruskal-Wallis' or 'GLM'.
#> $normality_results
#>                 Track 1    Track 2
#> statistic.W 0.900319498 0.91666968
#> p_value     0.009971017 0.04932503
#> 
#> $homogeneity_test
#> Levene's Test for Homogeneity of Variance (center = median)
#>       Df F value Pr(>F)
#> group  1  0.2935 0.5903
#>       51               
#> 
#> $ANOVA
#> $ANOVA$ANOVA
#>             Df Sum Sq Mean Sq F value Pr(>F)
#> track        1     49   49.01   0.646  0.425
#> Residuals   51   3867   75.82               
#> 
#> $ANOVA$Tukey
#>   Tukey multiple comparisons of means
#>     95% family-wise confidence level
#> 
#> Fit: aov(formula = dir ~ track, data = M_analysis)
#> 
#> $track
#>                      diff       lwr      upr     p adj
#> Track 2-Track 1 -1.931824 -6.755731 2.892084 0.4251435
#> 
#> 
#> 

# Example 5: Test for Differences in Direction Means with Pairwise Comparisons in PaluxyRiver
# dataset
test_direction(PaluxyRiver, analysis = "Kruskal-Wallis")
#> Warning: One or more tracks do not follow a normal distribution (p-value <= 0.05). Assumptions for ANOVA are not met. Consider using 'Kruskal-Wallis' or 'GLM'.
#>   Kruskal-Wallis rank sum test
#> 
#> data: x and group
#> Kruskal-Wallis chi-squared = 0.5368, df = 1, p-value = 0.46
#> 
#> 
#>                            Comparison of x by group                            
#>                                 (No adjustment)                                
#> Col Mean-|
#> Row Mean |    Track 1
#> ---------+-----------
#>  Track 2 |   0.732639
#>          |     0.2319
#> 
#> alpha = 0.05
#> Reject Ho if p <= alpha/2
#> $normality_results
#>                 Track 1    Track 2
#> statistic.W 0.900319498 0.91666968
#> p_value     0.009971017 0.04932503
#> 
#> $homogeneity_test
#> Levene's Test for Homogeneity of Variance (center = median)
#>       Df F value Pr(>F)
#> group  1  0.2935 0.5903
#>       51               
#> 
#> $Kruskal_Wallis
#> $Kruskal_Wallis$Kruskal_Wallis
#> 
#> 	Kruskal-Wallis rank sum test
#> 
#> data:  dir by track
#> Kruskal-Wallis chi-squared = 0.53676, df = 1, p-value = 0.4638
#> 
#> 
#> $Kruskal_Wallis$Dunn
#> $Kruskal_Wallis$Dunn$chi2
#> [1] 0.536761
#> 
#> $Kruskal_Wallis$Dunn$Z
#> [1] 0.7326398
#> 
#> $Kruskal_Wallis$Dunn$P
#> [1] 0.2318891
#> 
#> $Kruskal_Wallis$Dunn$P.adjusted
#> [1] 0.2318891
#> 
#> $Kruskal_Wallis$Dunn$comparisons
#> [1] "Track 1 - Track 2"
#> 
#> 
#> 

# Example 6: Test for Differences in Direction Means with Pairwise Comparisons in PaluxyRiver
# dataset
test_direction(PaluxyRiver, analysis = "GLM")
#> Warning: One or more tracks do not follow a normal distribution (p-value <= 0.05). Assumptions for ANOVA are not met. Consider using 'Kruskal-Wallis' or 'GLM'.
#> $normality_results
#>                 Track 1    Track 2
#> statistic.W 0.900319498 0.91666968
#> p_value     0.009971017 0.04932503
#> 
#> $homogeneity_test
#> Levene's Test for Homogeneity of Variance (center = median)
#>       Df F value Pr(>F)
#> group  1  0.2935 0.5903
#>       51               
#> 
#> $GLM
#> $GLM$GLM
#> 
#> Call:
#> glm(formula = dir ~ track, family = gaussian(), data = M_analysis)
#> 
#> Coefficients:
#>              Estimate Std. Error t value Pr(>|t|)    
#> (Intercept)    85.550      1.617  52.909   <2e-16 ***
#> trackTrack 2   -1.932      2.403  -0.804    0.425    
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#> 
#> (Dispersion parameter for gaussian family taken to be 75.82002)
#> 
#>     Null deviance: 3915.8  on 52  degrees of freedom
#> Residual deviance: 3866.8  on 51  degrees of freedom
#> AIC: 383.77
#> 
#> Number of Fisher Scoring iterations: 2
#> 
#> 
#> $GLM$pairwise_results
#> $emmeans
#>  track   emmean   SE df lower.CL upper.CL
#>  Track 1   85.6 1.62 51     82.3     88.8
#>  Track 2   83.6 1.78 51     80.1     87.2
#> 
#> Confidence level used: 0.95 
#> 
#> $contrasts
#>  contrast          estimate  SE df t.ratio p.value
#>  Track 1 - Track 2     1.93 2.4 51   0.804  0.4251
#> 
#> 
#> 
#>