barlett.test (test of homogenity)

Hello, I would like to perform a test of homogeneity for my data but I am struggling with erros. Please help.

bartlett.test(citaloprampodsebou$namount,citaloprampodsebou$nconcentration)
Error in bartlett.test.default(citaloprampodsebou$namount, citaloprampodsebou$nconcentration) :
all observations are in the same group

I am sorry that my data are in PDF
citaloprampodsebou.pdf (22.1 KB)

Well, the error message is clear: all lines in nconcentration have the same value, so all observations are in the same group. You might need to use rbind() to assemble a data frame with both the nominal and actual values.

Or you can use pivot_longer() to transform your "wide" dataset to a "long" one.

Makes sense. Then easiest is to use c(datacitalopram$nominal, datacitalopram$actual) as input for x in bartlett.test(), and build input g using rep() and nrow(datacitalopram).

I understand the first part but please can you tell me how to build g input.

rep() repeats a vector. So you can use something like rep(c("nominal", "actual"), each = nrow(datacita))

Is this the right formula?

bartlett.test(c(datacitalopram$nominal,datacitalopram$actual),rep(c("nominal", "actual"), each = nrow(datacitalopram)))

Looks like it should work.

I have lots to learn. Thank you very much. You really helped me.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

The error message suggests that there is no column nconcentration in datacitalopram. Perhaps you could use citaloprampodsebou if that's better? I don't know what your data actually looks like.

Anyway, you can't pivot the data.frame if it contains nconcentration and aconcentration, so you'll need to ignore these columns as you did above:

pivot_longer(citalopram, -c(nconcentration, aconcentration), names_to = "nominal")

So if you have a data.frame already without these columns, that's good too.

please can you show me how to pivot_longer formula? Unfortunately, I do not understand the explanation of what I found on the internet.

pivot_longer(-nconcentration,names_to = 'nominal',data=datacitalopram)
Error: Can't subset columns that don't exist.
x Column nconcentration doesn't exist.

Is that datacitalopram? Because in that case this error message seems strange:

pivot_longer(-nconcentration,names_to = 'nomi nal',data=datacitalopram)
Error: Can't subset columns that don't exist.
x Column nconcentration doesn't exist.

This are the data. There to two different values (nominal and actual)

nconcentration namount aconcentrataiaomn ount
nominal 8000 actual 8110
nominal 1000 actual 864.93
nominal 100 actual 81.51
nominal 10 actual 9.2
nominal 1 actual 1.41
nominal 1000 actual 973.98
nominal 100 actual 65.74
nominal 10 actual 8.3
nominal 1 actual 0.97
nominal 1000 actual 1017.97
nominal 100 actual 70.5
nominal 10 actual 8.74
nominal 1 actual 0.83
nominal 15 actual 7
nominal 1.5 actual 1.8
nominal 1.5 actual 0.79
nominal 0.15 actual 0.09
nominal 1.5 actual 1.01
nominal 0.15 actual 0.09
nominal 1 actual 0.81
nominal 3000 actual 2641
nominal 3 actual 2.3
nominal 300 actual 284
nominal 0.3 actual 0.2
nominal 30000 actual 23200
nominal 23.2 actual 15
nominal 0.5 actual 0.4
nominal 0.1 actual 0.1
nominal 0.5 actual 0.59595
nominal 8000 actual 5600
nominal 2000 actual 1567
nominal 500 actual 373
nominal 125 actual 98
nominal 31 actual 26
nominal 0.24 actual 0.113
nominal 2.401 actual 1.66

I have the data also like this:
It has 4 collumns

antidepressant nominal actual %
Citalopram 8000 8110 101.375
Citalopram 1000 864.93 86.493
Citalopram 100 81.51 81.51
Citalopram 10 9.2 92
Citalopram 1 1.41 141
Citalopram 1000 973.98 97.398
Citalopram 100 65.74 65.74
Citalopram 10 8.3 83
Citalopram 1 0.97 97
Citalopram 1000 1017.97 101.797
Citalopram 100 70.5 70.5
Citalopram 10 8.74 87.4
Citalopram 1 0.83 83
Citalopram 15 7 46.66667
Citalopram 1.5 1.8 120
Citalopram 1.5 0.79 52.66667
Citalopram 0.15 0.09 60
Citalopram 1.5 1.01 67.33333
Citalopram 0.15 0.09 60
Citalopram 1 0.81 81
Citalopram 3000 2641 88.03333
Citalopram 3 2.3 76.66667
Citalopram 300 284 94.66667
Citalopram 0.3 0.2 66.66667
Citalopram 30000 23200 77.33333
Citalopram 23.2 15 64.65517
Citalopram 0.5 0.4 80
Citalopram 0.1 0.1 100
Citalopram 0.5 0.59595 119.19
Citalopram 8000 5600 70
Citalopram 2000 1567 78.35
Citalopram 500 373 74.6
Citalopram 125 98 78.4
Citalopram 31 26 83.87097
Citalopram 0.24 0.113 47.08333
Citalopram 2.401 1.66 69.13786

I am sorry datacitalopram are the seconds data