Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

randtest and fourthcorner statistics for partial RLQ? Error in UseMethod("randtest" / "fourthcorner.rlq") : no applicable method for 'randtest' applied to an object of class "c('within', 'dudi')" #45

Open
maurinka opened this issue Dec 16, 2024 · 4 comments

Comments

@maurinka
Copy link

maurinka commented Dec 16, 2024

How can I evaluate global significance of a partial RLQ (wca.rlq), and calculate the contributions of the individual variables to the RLQ axes just as described by Wesuls et al. (2012, doi: 10.1111/j.1654-1103.2011.01342.x)?

i.e. what would be the corresponding functions for:

nrepet = 999
testrlq.env <- randtest(rlq.env, modeltype = 6, nrepet = nrepet)

randtest(wrlq_crop, modeltype = 6, nrepet = nrepet) # doesnt work
Error in UseMethod("randtest") :
no applicable method for 'randtest' applied to an object of class "c('within', 'dudi')"

and

testQaxes.comb.env <- fourthcorner.rlq(rlq.env, modeltype = 6, typetest = "Q.axes", nrepet = nrepet, p.adjust.method.G = "fdr", p.adjust.method.D = "fdr")
testRaxes.comb.env <- fourthcorner.rlq(rlq.env, modeltype = 6, typetest = "R.axes", nrepet = nrepet, p.adjust.method.G = "fdr", p.adjust.method.D = "fdr")

fourthcorner.rlq(wrlq_crop, modeltype = 6, typetest = "R.axes", nrepet = nrepet, p.adjust.method.G = "fdr", p.adjust.method.D = "fdr")
Error in fourthcorner.rlq(wrlq_crop, modeltype = 6, typetest = "R.axes", :
Object of class 'rlq' expected

Help very much appreciated @sdray

@sdray
Copy link
Collaborator

sdray commented Dec 19, 2024

Sorry for not replying before but was very busy these last days. The method is not properly implemented in ade4 and you should use a small trick. I give you some code from the original paper showing how to run the test:

## we assume that species abundances are stored in lnspec, traits in trait. Run  standard rlq and results stored in rlqTR
## habitat[,1] is a factor with a covariable that we want to remove the effect with withn-class rlq

wit1 <- within.rlq(rlqTR,habitat[,1], scannf = TRUE, nf = 2)

#then fourth-corner on the site scores of within RLQ
four1<-fourthcorner(wit1$lR,lnspec,trait,modeltype=2, nrepet=99) ## the trick : use output of within-RLQ wit1$lR instead of original environmental variables

summary(four1)
plot(four1,type = "G")
plot(four1,type = "D")

four2<-fourthcorner(wit1$lR,lnspec,trait,modeltype=4, nrepet=99)
summary(four2)
plot(four2,type = "G")
plot(four2,type = "D")

four3 <- combine.4thcorner(four1,four2)
summary(four3)
plot(four3,alpha=sqrt(0.05),type = "G")
plot(four3,alpha=sqrt(0.05),type = "D")

print(four3)

@maurinka
Copy link
Author

maurinka commented Dec 19, 2024

thank you very much for you reply.

am I correct to assume that fourthcorner2 with $lR instead of R, and the respective test (model 2 and 4) correspond to the randtest function implemented for the RLQ?

`# corresponds to randtest:
Srlq_partial2 <- fourthcorner2(wrlq_crop$lR, dat$spe,
dat$traits,
modeltype = 2, p.adjust.method.G = "none", nrepet = nrepet)
Srlq_partial4 <- fourthcorner2(wrlq_crop$lR, dat$spe,
dat$traits,
modeltype = 4, p.adjust.method.G = "none", nrepet = nrepet)

model 6:

Srlq_partial6 <- fourthcorner2(wrlq_crop$lR, dat$spe,
dat$traits,
modeltype = 6, p.adjust.method.G = "fdr", nrepet = nrepet)

Srlq_partial2$trRLQ
Srlq_partial4$trRLQ
Srlq_partial6$trRLQ
`

To test the significance of the variables with the RLQ axes, I used forthcorner.rlq() for the RLQ

the fourthcorner() D2 test-statistic resembles the output of forthcorner(RLQ, typetest = "Q.axes"). (so I assume, it corresponds. How can I obtain the output for the "R.axes"? I want to obtain the table corresponding to table 5 in the original publication.

@sdray
Copy link
Collaborator

sdray commented Dec 20, 2024

yep. so for rlq, the idea is to apply pca (without centering/scaling) on outputs of within class analysis performed on environmental variables:

pca_env <- dudi.pca(env_table)
wit_env <- wca(pca_env, habitat[,1]) # remove the effect of covar on env. table
pca_wit <- dudi.pca(wit$tab, scale = FALSE, center = FALSE, row. w= ca_abund$lw) # create a pca object that do nothing (but is accepted in randtest for rlq)
rlq(pca_wit, ca_abund, pca_trait)


Cheers

@maurinka
Copy link
Author

sorry, i dont get it. id would be amazing (and probably more efficient) of we could quickly talk. can I send you my phonenumber by email?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants