Bartlett Test with NA values on Subsets of Dataframe
0
0
Entering edit mode
2.1 years ago
eswarrijah • 0

I am new to R programming and I am stuck for some time on a certain problem. I have a dataframe where I have 7 columns. The first column are bins. I define columns 2-4 as one subset (one sample) and columns 5-7 as another sample. I want to perform statistical tests on these samples for each bin (so for each row). Here is a photo for better understanding:

enter image description here

I did this with the t-test and it worked. But for the Bartlett test I stumble upon some difficulties due to the syntax. So I tried this but I get an error that all observations are in the same group: Note: I save the p-value of the b.test in a new column.

#perform Bartlett test Data$P_Value_Bartlett <- NA
for (i in 1:nrow(Data)) {
  Data$P_Value_Bartlett[i] <- bartlett.test(unlist(Data[i, 2:7]),rep(LETTERS[1:2], each=3))$p.value
} # transforms row i into a vector, rep defines 2 groups, then bartlett test has a numeric vector and grouping variable to run the test

So e.g. I want to perform a test: I take data of row 1 (9,75) and compare the col 2-4 with col 5-7 and see if there is for example a difference in variance. I want to perform this test in each row, always comparing the same set of cols with each other.

I also have the problem, that the test is not working if I have NA values:

I added the input: na.action=na.omit But it is not working.

Anyone an idea whether this is the correct way or if it should be done in another way?

R statistics bartlett-test • 529 views
ADD COMMENT

Login before adding your answer.

Traffic: 3137 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6