2

I am trying to run the gls function but I keep getting this error message:

"Error in model.frame.default(formula = ~var + FS, data = list(MINBIO15 = c(37L, : object is not a matrix"

My data looks like this:

                        MINBIO15  MAXBIO15  FS
Achyranthes_aspera         37      117      0
Achyropsis_avicularis      28      86       0
Alternanthera_adscendens  -999    -999      -999
Alternanthera_brasiliana   33      119      0
Alternanthera_caracasana   35      109      1
Alternanthera_cinerella    105     120      1
...

My script is:

>tree<-read.tree ("tree.phy")
>clima<-read.table("mydata.txt",header=TRUE,na.strings=-999)
>clima<-na.omit(clima)
>match.phylo.data(tree, clima)
>var=(clima$MINBIO15)
> result.br <- gls(var ~ FS, clima, correlation=corBrownian(phy=tree),method="REML") 

Data and tree tips match perfectly, and my data is a dataframe

Perhaps you could give some advice on it?

Julia
  • 21
  • 2
  • Welcome to Stack Overflow! (1) you might try `gls(MINBIO15 ~ FS, clima, ...)` (2) Can you please include data that will provide us with a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) ? – Ben Bolker Oct 03 '16 at 16:19

1 Answers1

0

It looks like gls needs all of its data values to be referenced within the data argument. You haven't given a fully reproducible example, but apparently it doesn't matter. If I read in your abbreviated data set above, use na.omit(), define var, and then

gls(var~FS,clima)

I get the same error you did. If I use the name of the variable within the data frame (MINBIO15) instead:

gls(MINBIO15~FS,clima)

I get apparently sensible results.

Anticipating your next question: if you want to run the same regression with different response variables, you can use something like

varname <- "MINBIO15"
form <- reformulate("FS",response=varname)
gls(form,clima, ...)
Ben Bolker
  • 211,554
  • 25
  • 370
  • 453