I am getting the following error:
Error: Cannot compute effect size for a non-numeric vector.
When I try to calculate cohens_d
(RStatix) in R Studio using this code:
> # Calculate (Cohen's D) effect size
> Cohen <- LST_Weather_dataset %>%
+ group_by(Month, .add = FALSE) %>%
+ cohens_d(
+ LST ~ TimePeriod, paired = TRUE
+ )
LST, Month and TimePeriod are all numeric:
> str(LST_Weather_dataset)
'data.frame': 456 obs. of 15 variables:
$ Buffer : int 100 200 100 100 100 100 100 100 100 100 ...
$ Date : Date, format: "0006-10-20" ...
$ LST : num 1.7 1.38 2.66 3.81 3.2 ...
$ Month : num 10 10 12 1 2 3 4 5 6 7 ...
$ Year : int 2013 2013 2013 2014 2014 2014 2014 2014 2014 2014 ...
$ JulianDay : int 279 279 359 10 42 74 106 122 170 202 ...
$ TimePeriod : num 1 1 1 1 1 1 1 1 1 1 ...
...
The error persists if I remove group_by
.
What am I missing?
Edit
Data requested in comments:
> test <- dput(LST_Weather_dataset[1:300, c("Month", "LST", "TimePeriod")])
structure(list(Month = c(3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9,
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11,
11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12), LST = c(-0.2210116, -0.24720568, -0.26111535,
-0.25316346, -0.30848301, -0.33180257, -0.27721127, -0.20766731,
-0.14346835, -0.06433451, -0.02385345, -0.03473869, -0.0511723,
-0.04610033, -0.03462484, -0.03734767, -0.04306532, -0.02964348,
-0.01385088, -0.22618709, -0.2425393, -0.2541757, -0.25475207,
-0.29917977, -0.36117768, -0.31852919, -0.28564376, -0.2359735,
-0.12195752, -0.06586962, -0.05811313, -0.03766735, -0.02261001,
-0.03555068, -0.05061729, -0.05351268, -0.02241539, -0.00981671,
-0.22016505, -0.26550893, -0.29015481, -0.28068968, -0.3103153,
-0.33183916, -0.2798485, -0.24933379, -0.23071591, -0.15598767,
-0.0976511, -0.07922456, -0.06455107, -0.03039455, -0.00439505,
-0.00427336, -0.01586557, -0.03632884, -0.02813621, -0.34759789,
-0.40494336, -0.41258461, -0.38127643, -0.38749164, -0.43010968,
-0.38592257, -0.31959701, -0.25699752, -0.17257249, -0.13109291,
-0.11687805, -0.10309548, -0.0933909, -0.07803618, -0.06782885,
-0.05547398, -0.02602688, -0.01469682, -0.16601023, -0.20167048,
-0.18983419, -0.1591577, -0.15829101, -0.18991115, -0.15560403,
-0.08758369, -0.0419441, 0.02094988, 0.06149603, 0.04233754,
0.05957017, 0.08024451, 0.07646054, 0.05378477, 0.01491128, 0.02128012,
0.01505348, -0.27509869, -0.29971987, -0.28898894, -0.26678469,
-0.26546793, -0.2767395, -0.21621339, -0.13996242, -0.0772666,
-0.01513719, 0.01099537, 0.00156385, 0.03741067, 0.05769562,
0.05522714, 0.03726737, 0.00673056, -0.0086786, -0.00868214,
-0.24094543, -0.27829062, -0.27762726, -0.26392197, -0.25151899,
-0.2454435, -0.20808879, -0.15734442, -0.11566806, -0.07631076,
-0.05374834, -0.06464258, -0.04748078, -0.04106418, -0.02877574,
-0.04559453, -0.04936476, -0.03311713, -0.0184964, -0.161790125,
-0.207325856, -0.202609595, -0.182737706, -0.176479067, -0.172051143,
-0.115534666, -0.069043871, -0.045666582, -0.016103689, -0.0097142,
-0.027125424, -0.031078945, -0.027668948, -0.038168329, -0.04902581,
-0.049393072, -0.029093549, -0.016435892, -0.18777984, -0.22560193,
-0.21353557, -0.19873006, -0.21000726, -0.19960744, -0.16449805,
-0.12677822, -0.09319863, -0.05365756, -0.03196716, -0.03521089,
-0.01844106, -0.01675121, -0.02673582, -0.0336761, -0.03909757,
-0.02311188, -0.00841367, -0.06879569, -0.11193502, -0.11645102,
-0.11313204, -0.1241938, -0.12764257, -0.09562478, -0.06360073,
-0.03919549, -0.01310477, 0.00199091, -0.00299883, 0.00071001,
-0.0009422, -0.01377567, -0.03184663, -0.0422166, -0.02251581,
-0.00296154, -0.16582354, -0.19623703, -0.19219006, -0.16517101,
-0.18704658, -0.15345162, -0.10262394, -0.08604339, -0.08749103,
-0.06062491, -0.03485287, -0.0373792, -0.03525576, -0.04025037,
-0.02994186, -0.03698465, -0.0445463, -0.03625804, -0.01916101,
-0.32618398, -0.38494187, -0.37563704, -0.3362058, -0.33109373,
-0.28774767, -0.23600731, -0.18341335, -0.14375045, -0.09224798,
-0.06322383, -0.06435687, -0.04382372, -0.04243214, -0.04790463,
-0.05992479, -0.05804111, -0.03623521, -0.01380783, 0.07521048,
0.08923107, 0.04085175, 0.02369799, -0.01174092, -0.00924432,
0.02309842, 0.03106341, 0.01589905, 0.02520586, 0.02755641, 0.01418465,
0.03378753, 0.0356642, 0.03617703, 0.0236984, 0.01581965, 0.00092364,
-0.00135577, -0.01808666, -0.02659894, -0.06659976, -0.07161127,
-0.07336009, -0.05201086, -0.00927892, 0.02300103, 0.03837143,
0.05036375, 0.06564468, 0.0600014, 0.06562315, 0.05419116, 0.04456497,
0.01096535, -0.00228103, -0.00411322, -0.00017688, -0.06780171,
-0.06119238, -0.07202179, -0.05932171, -0.09219981, -0.0933819,
-0.0571732, -0.03830071, -0.02184744, 0.01698308, 0.02923943,
0.01394951, 0.01748671, 0.01059124, -0.00520207, -0.02724512,
-0.02908047, -0.01867358, -0.0086791, -0.02430298, -0.04431464,
-0.0597082, -0.07027699, -0.09412717, -0.08051615, -0.04382819,
-0.01872886, -0.00143456, 0.01274511, 0.02342804, 0.00065864,
0.00322716, -0.00126722, -0.00821571), TimePeriod = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("1",
"2"), class = "factor")), row.names = c(NA, 300L), class = "data.frame")
> Cohen <- test %>%
+ # group_by(TimePeriod) %>%
+ cohens_d(
+ LST ~ Month, paired = FALSE
+ )
Error: Cannot compute effect size for a non-numeric vector.
>
Using the effsize
package instead of rstatix
the test ran successfully:
LST_Weather_dataset %>% group_by(Month, .add = FALSE)
# A tibble: 456 x 14
# Groups: Month [12]
Buffer Date LST Month Year JulianDay TimePeriod
<int> <date> <dbl> <dbl> <dbl> <dbl> <dbl>
1 100 2010-01-15 0.581 1 2010 15 1
2 100 2010-02-16 0.971 2 2010 47 1
3 100 2010-03-20 1.63 3 2010 79 1
4 100 2011-04-24 2.14 4 2011 114 1
5 100 2010-05-07 1.90 5 2010 127 1
6 100 2010-06-08 3.32 6 2010 159 1
7 100 2011-07-13 1.67 7 2011 194 1
8 100 2010-08-11 2.74 8 2010 223 1
9 100 2010-09-12 2.27 9 2010 255 1
10 100 2011-10-17 0.987 10 2011 290 1
# ... with 446 more rows, and 7 more variables: Humidity <dbl>,
# Wind_speed <dbl>, Wind_gust <dbl>, Wind_trend <dbl>,
# Wind_direction <dbl>, Pressure <dbl>, Pressure_trend <dbl>
> CohenD2 <- cohen.d(
+ LST ~ TimePeriod | Subject(Buffer), paired = TRUE
+ )
> CohenD2
Cohen's d
d estimate: 0.5875947 (medium)
95 percent confidence interval:
lower upper
0.4328020 0.7423874
> ungroup(LST_Weather_dataset)
# A tibble: 456 x 14
Buffer Date LST Month Year JulianDay TimePeriod
<int> <date> <dbl> <dbl> <dbl> <dbl> <dbl>
1 100 2010-01-15 0.581 1 2010 15 1
2 100 2010-02-16 0.971 2 2010 47 1
3 100 2010-03-20 1.63 3 2010 79 1
4 100 2011-04-24 2.14 4 2011 114 1
5 100 2010-05-07 1.90 5 2010 127 1
6 100 2010-06-08 3.32 6 2010 159 1
7 100 2011-07-13 1.67 7 2011 194 1
8 100 2010-08-11 2.74 8 2010 223 1
9 100 2010-09-12 2.27 9 2010 255 1
10 100 2011-10-17 0.987 10 2011 290 1
# ... with 446 more rows, and 7 more variables: Humidity <dbl>,
# Wind_speed <dbl>, Wind_gust <dbl>, Wind_trend <dbl>,
# Wind_direction <dbl>, Pressure <dbl>, Pressure_trend <dbl>
> CohenD2 <- cohen.d(
+ LST ~ TimePeriod | Subject(Buffer), paired = TRUE
+ )
> CohenD2
Cohen's d
d estimate: 0.5875947 (medium)
95 percent confidence interval:
lower upper
0.4328020 0.7423874
Grouping the data using group_by made no difference as | Subject() does this within the function.