I have tried to perform the Kruskal-Wallis test, but I am not sure if the data is ordered correctly, therefore, I do not know if the result is correct.
I still do not know how to verify that it is correct, I do not know if you can help me identify the error.
Thank you.
Data:
There are 13 samples and 138 observation, divided by months.
ï..meses fajerae
1 ene-15 0
2 ene-15 1
3 ene-15 0
4 ene-15 0
5 ene-15 0
6 ene-15 0
7 ene-15 1
8 ene-15 1
9 ene-15 0
10 ene-15 1
11 feb-15 0
12 feb-15 0
13 feb-15 0
14 feb-15 1
15 feb-15 0
16 feb-15 1
17 feb-15 1
18 feb-15 0
19 feb-15 0
20 feb-15 3
21 feb-15 2
22 feb-15 2
23 feb-15 0
24 feb-15 0
25 feb-15 1
26 mar-15 1
27 mar-15 0
28 mar-15 3
29 mar-15 3
30 mar-15 1
31 mar-15 4
32 mar-15 2
33 mar-15 5
34 mar-15 0
35 mar-15 1
Here I do the Kruskal-Wallis test.
#kruskal-wallis test
setwd("~/")
datos <- read.csv(file.choose(), header = TRUE)
datos
#estructura de los datos
str(datos)
attach(datos)
names(datos)
class(datos)
factor(datos)
Here it does not recognize the levels, the results are null, I expected it to show me the months, ene-15, Feb-15, Mar-15, Nov-15, etc.
levels(datos$ï..meses)
But in the table, it's correct.
table(datos$ï..meses)
abr-17 dic-15 dic-16 dic-17 ene-15 ene-16 ene-17 ene-18 feb-15 feb-16 mar-15
10 10 10 12 10 10 13 20 15 2 10
mar-17 nov-15
4 12
I did the homocedasticity test
# Homocedasticidad: la varianza debe de ser constante entre todos los grupos.
leveneTest(fajerae ~ ï..meses, data = matriz, center = "median")
#Results#
Levene's Test for Homogeneity of Variance (center = "median")
Df F value Pr(>F)
group 12 1.8447 0.04784 *
125
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Warning message:
In leveneTest.default(y = y, group = group, ...) : group coerced to factor.
And the Kruskal-Wallis test, which gave me a result, but I don't know how to check if it is correct.
kruskal.test(fajerae ~ ï..meses, data = matriz)
#Results#
Kruskal-Wallis rank sum test
data: fajerae by ï..meses
Kruskal-Wallis chi-squared = 24.493, df = 12, p-value = 0.01742
The code in the question can be simplified.
1. Load the non-base package(s) you are going to use.
2. Check your data structure with
str.That first name,
ï..meses, is rather ugly with its accents and nonsense dots, make it prettier.From the output of
stryou know thatmesesis of class"character", so the next instruction is expected to returnNULL.But if you want a factor, it's simply
3 The distribution of
meses:4. Determine homocedasticity by groups of
meses.5. Finally, the Kuskall-Wallis test.
If you are trying to determine whether the groups have the same median, why not check a box-and-whiskers plot first? See your data.
The groups seem to have different locations, confirm with a non parametric test.
You ask if the test is right. Yes, it is, in the sense that base R functions are well coded and tested countless times by countless users along the years. Whether this is expected is a different question, and only you can answer to it.
Data in
dputformat.