0
$\begingroup$

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.

$\endgroup$
2
  • $\begingroup$ can you check there's no typo? there is a missing " in subset(male, Region ==1, select = c("Rate)) $\endgroup$
    – StupidWolf
    Apr 11, 2020 at 22:26
  • 1
    $\begingroup$ I wrote similar code in here. It's not identical. I'll fix that. $\endgroup$
    – user252085
    Apr 11, 2020 at 23:56

2 Answers 2

0
$\begingroup$

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]))
$\endgroup$
3
  • $\begingroup$ 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. $\endgroup$
    – user252085
    Apr 11, 2020 at 23:58
  • $\begingroup$ Check my updated code $\endgroup$ Apr 12, 2020 at 0:33
  • $\begingroup$ 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. $\endgroup$
    – user252085
    Apr 12, 2020 at 1:00
0
$\begingroup$

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)
$\endgroup$