I'm currently trying to run and RLQ analysis which conducts a double inertia analysis on two arrays R and Q, which represent ecological environmental variables and species traits respectively, which are linked via a contingency table representing abundance data (L) of those weed species found within each 'environment', in this case sample sites.

I am doing this following the tutorial from Stéphane Dray titled "A tutorial to perform fourth-corner and RLQ analyses in R (2013). The process first involves running separate analyses on each data frame (Correspondence Analysis for the species abundance table, and Hill-Smith Analysis for the environmental and traits tables as they contain both quantitative and numerical values. This step has worked out fine, but the following one (the fourth-corner) utilises these data frames (not the analyses performed on them) once more. I have used the code from the tutorial as am completely new to this, which reads:

FourthCorner <- fourthcorner(Environmental, Species, Traits, modeltype = 6, p.adjust.method.G = "none", p.adjust.method.D = "none", nrepet = nrepret).

When doing so however, I get the following error:

Error in fourthcorner(tabR, tabL, tabQ, modeltype = 2, nrepet = nrepet,  : 
      'tabR' must contain only numeric values or factors (see the 'Treatment' variable in    'tabR').

The first 10 samples in my environmental data frame Apologies for not putting the data directly but it is my first time trying this.

I first tried setting my categorical variables in my R and Q data frames as factors, while leaving the remaining quantitative variables as numerical:

Environmental$Field <- as.factor(Environmental$Field)
    Environmental$Treatment <- as.factor(Environmental$Treatment)

I then tried setting all my categorical variables to numerical, which also did not work:

Environmental$Field <- as.numeric(Environmental$Field)
    Environmental$Treatment <- as.numeric(Environmental$Treatment)

And again for all my environmental variables:

Environmental$Field <- as.numeric(as.character(Environmental$Field))
    Environmental$Treatment <- as.numeric(as.character(Environmental$Treatment))
    Environmental$Moisture_content_perc <- as.numeric(Environmental$Moisture_content_perc)
    Environmental$Soil_organic_matter_gkg <- as.numeric(Environmental$Soil_organic_matter_gkg)
    Environmental$N_NO3_gkg <- as.numeric(Environmental$N_NO3_gkg)
    Environmental$N_NH4_gkg <- as.numeric(Environmental$N_NH4_gkg)
    Environmental$P_PO4_gkg <- as.numeric(Environmental$P_PO4_gkg)
    Environmental$K_gkg <- as.numeric(Environmental$K_gkg)

I tried removing one environmental variable from the R table at a time but the error simply shifted to the following variable (even ones that seemed clearly numerical).

When running the as.numeric(variable) for each, the result is TRUE, but when running it on the entire data frame, it results as FALSE. I think the issue could therefore be with how the data frame itself and not the variables.

Running str(Environmental) for example results in: tibble [60 × 8] (S3: tbl_df/tbl/data.frame), where 60 are my observations and 8 are my variables. Could this be what's causing the issue? when running str(Environmental)

Thanks in advance and hope this was clear enough!

0

There are 0 best solutions below