[R-sig-eco] using Pearson's Chi-squared to verify dependence among species distribuion

Zoltan Botta-Dukat botta-dukat.zoltan at okologia.mta.hu
Mon May 6 08:20:06 CEST 2013


Dear Antonio,

chisq.test function uses this equation, but it round the results, thus 
in your example it gives 0 instead of 0.39. For hypothesis testing the 
difference is unimportant, both mean lack of sifnificant association. If 
you need the unrounded values or you want to calculate dissimilarity 
matrix, you should follow Jari's suggestion.

Best wishes

Zoltan

2013.05.01. 10:22 keltezéssel, Jari Oksanen írta:
> On 01/05/2013, at 06:09 AM, Antonio Silva wrote:
>
>> Thanks Zoltan R R-sig list members
>>
>> I still with some doubts.
>>
>> Is there a way to calculate in R the results for the equation
>>
>> X2= n*[|ad-bc|-(p/2)]^2 / [(a+b)*(c+d)*(a+c)*(b+d)]
>>
>> (see Legendre & Legendre pg 295 eq. 7.6)
> This should be doable in vegan::designdist() function. Set 'abcd = TRUE' and you can directly use terms like you defined them above. I won't give the equation here as I don't know what is the equation you used: Your previous message had a different equation than this one here with some mix up with 'n' and 'p'. The designdist() function calculates (dis)similarities between rows. You must transpose (t()) your data if you want to have dissimilarities between columns. The code is pure R so that you can see how to do these calculations yourself.
>
> Cheers, Jari Oksanen
>
>> for the following data:
>>
>>
>> ST01 ST02 ST03 ST04 ST05 ST06 ST07 ST08 ST09  SP1 1 1 1 1 1 0 0 1 1  SP2 1 1
>> 0 1 0 1 0 1 0
>>
>> We have a=4, b=3, c=1, d=1, N=9 and the 2x2 table for this example is
>>
>>
>>
>> SP2
>>
>>
>> Presence Absent
>> SP1 Presence 4 3
>> Absent 1 1
>>
>>
>>
>>
>>
>> Following the Chi square formula I got 110.25 / 280 = 0.3937
>>
>> I have tried many things, without success.
>>
>> Thanks in advance for any suggestion.
>>
>> Antonio Olinto
>>
>>
>> 2013/4/25 Zoltan Botta-Dukat <botta-dukat.zoltan at okologia.mta.hu>
>>
>>> Dear Antonio,
>>>
>>> Try this:
>>>
>>> chisq.test(table(sp1,sp2))
>>>
>>> Best wishes
>>>
>>> Zoltan
>>>
>>
>>>> On Wed, Apr 24, 2013 at 6:02 PM, Antonio Silva <aolinto.lst at gmail.com
>>>> wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> I'm trying to use Pearson's Chi-squared to verify the dependence among
>>>>> species distribuion.
>>>>>
>>>>> I have a dataframe with the presence/absence data of two species in a
>>>>> number of sample units
>>>>>
>>>>> The equation I'm using is:
>>>>>
>>>>> X2= p*(|ad-bc|-p/2)^2 / ((a+b)*(c+d)*(a+c)*(b+d))
>>>>>
>>>>> where a is the number of double presence (1-1), b is the number of 1-0,
>>> c
>>>>> is the number of 0-1 and d is the number of 0,0 (double absence)
>>>>> p is a+b+c+d
>>>>>
>>>>> Is there a function to caltulate it using R? I could not understand how
>>> to
>>>>> use chisq.test function for this.
>>>>>
>>>>> Thanks in advance.
>>>>>
>>>>> Antonio Olinto
>>>
>>> --
>>>
>>> Zoltán BOTTA-Dukát
>>> --------------------------------
>>> Institute of Ecology and Botany
>>> Hungarian Academy of Sciences
>>> Centre for Ecological Research
>>> --------------------------------
>>> H-2163 Vácrátót, Alkomány u. 2-4.
>>> HUNGARY
>>> Phone: +36 28 360122/157
>>> Fax..: +36 28 360110
>>> botta-dukat.zoltan at okologia.mta.hu
>>> www.okologia.mta.hu
>>>
>> 	[[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-ecology mailing list
>> R-sig-ecology at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology


-- 
Botta-Dukát Zoltán
--------------------------------
Ökológiai és Botanikai Intézet
Magyar Tudományos Akadémia
Ökológiai Kutatóközpont
--------------------------------
2163. Vácrátót, Alkotmány u. 2-4.
tel: +36 28 360122/157
fax: +36 28 360110
botta-dukat.zoltan at okologia.mta.hu
www.okologia.mta.hu


Zoltán BOTTA-Dukát
--------------------------------
Institute of Ecology and Botany
Hungarian Academy of Sciences
Centre for Ecological Research
--------------------------------
H-2163 Vácrátót, Alkomány u. 2-4.
HUNGARY
Phone: +36 28 360122/157
Fax..: +36 28 360110
botta-dukat.zoltan at okologia.mta.hu
www.okologia.mta.hu



More information about the R-sig-ecology mailing list