4
$\begingroup$

I have the response variable that is an abundance matrix Y. for example, I have four columns with

  • species 1

  • species 2

  • species 3

  • and species 4

    abundances at each location (each location is separate row).

I have a matrix X which include a set of environmental parameters (e.g. Temperature and salinity).

I need to predict what will be my abundance matrix $Y_i$ (i.e. abundance of

  • Species1=...,
  • species 2=...,
  • species 3=...,
  • and species 4=...)

at a given set of environmental conditions ( for example T=20, S=35)

I saw a method that was using multivariate multiple regression approach:

model=lm(cbind(A,B) ~ c+d+e+f+g)

However, in my model, the relationship is not linear. so I was wondering whether you can suggest some other method.

I was thinking of doing the following steps:

  1. Train a model to give a probability of occurrence of any combination of abundance matrix Y in a given set of environmental conditions
  2. Use this model to predict what abundance matrix will look like for a new set of env conditions

I am trying it on on another dataset :

dataset(airquality)
fmla= cbind(Day, Month)~Ozone + Wind + Temp

I am not sure whether GAM model will be appropriate for this.

$\endgroup$
8
  • $\begingroup$ It could definitely be appropriate! But we need to see your data to answer. Can you share them? $\endgroup$
    – DeltaIV
    Commented Nov 28, 2017 at 21:10
  • $\begingroup$ I agree with DeltaIV, there is no reason to think a GAM would be inappropriate. You might wish to consider a multivariate normal additive model. $\endgroup$
    – usεr11852
    Commented Nov 28, 2017 at 21:15
  • $\begingroup$ Ps you can also share just a random sample, if you're concerned about the amount of data (but I I'm sure it's nothing a cloud-based system can't handle). Or you can share some fake data, reasonably which are similar to your real data, if you're concerned about publicly sharing data. But to answer we need to have a look at something. $\endgroup$
    – DeltaIV
    Commented Nov 28, 2017 at 21:34
  • $\begingroup$ thanks everyone for your replies. Unfortunately, I am still preparing my data- so I don't have it yet ( I am working with file that are 4Gb, so it takes ages do anything on them, so now I am in process of compiling all the data together). i am now trying to test the code on teh following data set: dataset(airquality). i am just not familiar with how to construct the model cause I never had to program the multiple response variable in one model. fmla= cbind(Day, Month)~Ozone + Wind + Temp $\endgroup$
    – yuliaUU
    Commented Nov 28, 2017 at 21:38
  • $\begingroup$ I think you have the model the wrong way round don't you: you want cbind(Ozone, Wind, Temp) ~ s(Day) + s(Month) say. (I can't see why you'd want to predict the day or Month from the air quality measurements. $\endgroup$ Commented Nov 28, 2017 at 21:40

1 Answer 1

2
$\begingroup$

You'll need to make some assumptions about the nature of the response, but one option is to fit a multivariate normal model, which is possible for example in mgcv.

Using the airquality dataset mentioned in the question, we might have

data(airquality)
aq <- transform(airquality,
                date = as.Date(paste('1973', Month, Day, sep = '-')))
aq <- transform(aq, DoY = as.numeric(format(date, '%j')))

and we might assume (probably naively) that OzoneandTemp` are multivariate normal. In which case we can fit the model using

m <- gam(list(Ozone ~ s(DoY),
              Temp  ~ s(DoY)),
         data = aq, family = mvn(d=2))

where we specify the linear predictors for the two, in this instance, response variables. I chose to model them as smooth functions of the day of year and implicit in this model is the estimation of a covariance matrix.

> summary(m)

Family: Multivariate normal 
Link function: 

Formula:
Ozone ~ s(DoY)
Temp ~ s(DoY)

Parametric coefficients:
              Estimate Std. Error z value Pr(>|z|)    
(Intercept)    42.1293     2.6470   15.92   <2e-16 ***
(Intercept).1  77.8707     0.5704  136.53   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Approximate significance of smooth terms:
           edf Ref.df Chi.sq  p-value    
s(DoY)   3.546  4.385  34.42 1.37e-06 ***
s.1(DoY) 5.711  6.832 149.04  < 2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Deviance explained = 41.9%
-REML =  708.4  Scale est. = 1         n = 116

That covariance matrix can be extracted via

solve(crossprod(m$family$data$R))

which results in

> solve(crossprod(m$family$data$R))
         [,1]      [,2]
[1,] 812.7657 104.67443
[2,] 104.6744  37.73835

or as a correlation matrix

> cov2cor(solve(crossprod(m$family$data$R)))
          [,1]      [,2]
[1,] 1.0000000 0.5976769
[2,] 0.5976769 1.0000000

If your response is a count or similar abundance measure, you'll need to transform them if you are going to try the multivariate normal as abundances tend to be skewed and exhibit heterogeneous variance.

Alternatively, if the response matrix $Y$ contains counts from a total, you might use the multinomial response model. This can be done in mgcv also via the multinom family.

There's nothing stopping you from using ns() or bs() terms in the linear model example you had found — you just won't have smoothness selection so you'll need to tune the degrees of freedom/wiggliness of the fitted smooths yourself. bs() and ns() are in the splines package, which comes with R.

Related models could be estimated using a multivariate adaptive regression spline approach, with an R implementation in the earth package, which can now fit these models as GLMs — which might be appropriate given the nature of your response data (counts?)

Alternatively, joint species distribution models (JSDMs) are currently quite popular in ecology and in active development. The idea often involves stacking the columns of your matrix $Y$ and then adding factor variables for site and species which are then introduced into the model via random effects for site:species or latent factor variables.

A recent JSDM overview can be found in Warton et al (2015).

Warton DI, Blanchet FG, O’Hara RB et al. So Many Variables: Joint Modeling in Community Ecology. Trends in ecology & evolution [Internet] 2015;Available from: http://dx.doi.org/10.1016/j.tree.2015.09.007

$\endgroup$
6
  • $\begingroup$ thank you so much for this detailed answer. How does it change if I cant combine together my response variables? For example, I have Abundance of species 1 and 2 as my response and my independent variables are Temperature, salinity, and depth? $\endgroup$
    – yuliaUU
    Commented Nov 28, 2017 at 22:26
  • $\begingroup$ You can combine the responses. Abundances of spp1 and spp2 would be in the response side of the model, and the covariates (Temperature etc) would be on the right hand side of ~ --- in the gam() model I show at least. You'll need to look at the implementation details however for earth if you want to try that. For lm, you use cbind() on the species to form a matrix - I'm not sure if that linear model is estimating the covariances between responses (species). For JSDMs I suggest you read that paper for directions on how to proceed. $\endgroup$ Commented Nov 28, 2017 at 22:30
  • $\begingroup$ What you need to decide is how to model the species. The multivariate normal treats them as is correlated Gaussian random variables and abundances tend not to be Gaussian (they can't be negative for example) so you might consider log transforming the abundances. The multinomial model would consider your response as counts from a total - like you count 100 individuals and assign each individual to one of the species - then you have a model that is similar to a logit regression but for more than 2 classes/species. You should give some more info on the actual nature of your species abundances. $\endgroup$ Commented Nov 28, 2017 at 22:33
  • $\begingroup$ thanks so much for the directions! i already downloaded a paper for further reading. yes I will definitely log transform the abundance values and also add 1 (eg log(abund)+1). my abundances are usually reported either counts per m^2 or per m^3 $\endgroup$
    – yuliaUU
    Commented Nov 28, 2017 at 22:41
  • $\begingroup$ I think you mean to use the transformation log(abund + 1), right? $\endgroup$ Commented Nov 29, 2017 at 5:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.