Dr. Leigh S. Sutherland
2015-Oct-19 12:02 UTC
[R] leveneTest between 2-levels of 3-level factor in R?
Still feeling my way around using R... What I have done so far: I have a data.frame 'results' with response 'Fail', and three factors 'PREP', 'CLEAN' & 'ADHES'. ADHES has 3 levels: Crest Cryst Poly I calculated the variances: sigma..k=tapply(Fail,ADHES,var) print(sqrt(sigma..k)): Crest Cryst Poly 17.56668 41.64679 39.42669 then used leveneTest to test for constance of variance: print(leveneTest(Fail~ADHES)) Levene's Test for Homogeneity of Variance (center = median) Df F value Pr(>F) group 2 3.929 0.02588 * 51 The Question: Now I want to use Levene's to test for constance of variance between only the Cryst & Poly levels of the factor ADHES, but I cant work out the syntax to do this in R. Could anyone help, please? ? [[alternative HTML version deleted]]
On 20/10/15 01:02, Dr. Leigh S. Sutherland wrote:> Still feeling my way around using R... > > What I have done so far: > > I have a data.frame 'results' with response 'Fail', and three factors > 'PREP', 'CLEAN' & 'ADHES'. ADHES has 3 levels: Crest Cryst Poly > > I calculated the variances: > > sigma..k=tapply(Fail,ADHES,var) > print(sqrt(sigma..k)): > > Crest Cryst Poly 17.56668 41.64679 39.42669 > > then used leveneTest to test for constance of variance: > > print(leveneTest(Fail~ADHES))How does leveneTest() find the variables "Fail" and "ADHES" given that you do not provide it with a "data" argument?> Levene's Test for Homogeneity of Variance (center = median) > Df F value Pr(>F) > group 2 3.929 0.02588 * > 51 > > The Question: > Now I want to use Levene's to test for constance of variance between only > the Cryst & Poly levels of the factor ADHES, but I cant work out the syntax > to do this in R. > > Could anyone help, please?I am not at all sure that I understand your somewhat incoherently expressed question, but I *think* that what you want to do might be done by setting ok <- with(results,ADHES%in%c("Cryst","Poly")) leveneTest(Fail ~ ADHES, data=results[ok,]) It's hard to say, since you do not provide a reproducible example. cheers, Rolf Turner -- Technical Editor ANZJS Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. 88276
Dr. Leigh S. Sutherland
2015-Oct-20 08:28 UTC
[R] leveneTest between 2-levels of 3-level factor in R?
Thanks Rolf, Sorry, I was trying to be coherent, but obviously failed abysmally! I am new to this list, I will give a reproducible example next time, and more of the relevant script. I managed to do what I wanted to with subset: leveneTest(subset(results,ADHES == 'Poly'|ADHES == 'Cryst')[,5], subset(results,ADHES == 'Poly'|ADHES == 'Cryst')[,3]) which gives the same results as your suggestion, which I can now look into how it works many thanks. Leigh On 19 October 2015 at 22:13, Rolf Turner <r.turner at auckland.ac.nz> wrote:> On 20/10/15 01:02, Dr. Leigh S. Sutherland wrote: > >> Still feeling my way around using R... >> >> What I have done so far: >> >> I have a data.frame 'results' with response 'Fail', and three factors >> 'PREP', 'CLEAN' & 'ADHES'. ADHES has 3 levels: Crest Cryst Poly >> >> I calculated the variances: >> >> sigma..k=tapply(Fail,ADHES,var) >> print(sqrt(sigma..k)): >> >> Crest Cryst Poly 17.56668 41.64679 39.42669 >> >> then used leveneTest to test for constance of variance: >> >> print(leveneTest(Fail~ADHES)) >> > > How does leveneTest() find the variables "Fail" and "ADHES" given that you > do not provide it with a "data" argument? > > Levene's Test for Homogeneity of Variance (center = median) >> Df F value Pr(>F) >> group 2 3.929 0.02588 * >> 51 >> >> The Question: >> Now I want to use Levene's to test for constance of variance between only >> the Cryst & Poly levels of the factor ADHES, but I cant work out the >> syntax >> to do this in R. >> >> Could anyone help, please? >> > > I am not at all sure that I understand your somewhat incoherently > expressed question, but I *think* that what you want to do might be done by > setting > > ok <- with(results,ADHES%in%c("Cryst","Poly")) > leveneTest(Fail ~ ADHES, data=results[ok,]) > > It's hard to say, since you do not provide a reproducible example. > > cheers, > > Rolf Turner > > -- > Technical Editor ANZJS > Department of Statistics > University of Auckland > Phone: +64-9-373-7599 ext. 88276 >-- Leigh Sutherland Centre for Marine Technology and Ocean Engineering (CENTEC) Instituto Superior T?cnico Av. Rovisco Pais 1049-001 LISBOA PORTUGAL Tel: +351 218 417 947 [[alternative HTML version deleted]]