0

I'm getting an error running Bartlett’s test in R. I assume it's the format the data is in. I'm new to R.

I am working with one column from one .csv file, and another column from a second .csv file. The female dataset it about 25% larger than the male one.

I want to run the Bartlett test on the full datasets, not on equal sampled subsets. According to what I've read, this is valid.

I can run a t-test, but I can't figure out how to test the variance.

female <- read.csv("Set1.csv")
male <- read.csv("set2.csv")
female_1 <- subset(female, Region == 1, select = c("Rate"))
male_1 <- subset(male, Region ==1, select = c("Rate"))
bartlett.test(female1,male1)

Error: unexpected ',' in "bartlett.test(female1,male1)"

bt = table(female1,male1)
bartlett.test(female1 ~ male1, bt)

Error in bartlett.test.default(1L, 1L) : 
  all observations are in the same group

I need to run this on other data that will be in the same basic format, and the differences in sizes between the two files can vary a lot - so I'm looking for a general answer on calculating variances here.

Thanks for any help.

2 Answers2

0

Try this. You don't have to change anything except the region's number:

female<- read.csv("set1.csv")
male<- read.csv("set2.csv")

region<- 1   #Region for which you need to test
bartlett.test(list(male$Rate[male$Region == region],
                   female$Rate[female$Region == region]))
Mohanasundaram
  • 616
  • 2
  • 8
  • I want to compare the full datasets. I don't want to take an equal length sample. According to what I read this would be valid. –  Apr 11 '20 at 23:58
  • Check my updated code – Mohanasundaram Apr 12 '20 at 00:33
  • I haven't tried that. I found a solution and posted the answer. Your solution would get complicated with complicated subset statements - which is what I'm working with. Thanks for your help. –  Apr 12 '20 at 01:00
0

This works.

female <- read.csv("Set1.csv")
male <- read.csv("set2.csv")
female_1 <- subset(female, Region == 1, select = c("Rate"))
male_1 <- subset(male, Region ==1, select = c("Rate"))
female_2=female_1[,1]
male_2=male_1[,1]
my.data = stack(list(female_2=female_2, male_2=male_2))
bartlett.test(values~ind, my.data)