Error warning in DSM with smooth terms

Skip to first unread message

Daniel Medina

Sep 24, 2021, 9:10:43 PM9/24/21
Hello distance enthusiasts,

This is my first active participation on the list, so I hope to be clear in explaining my problem.
I'm performing a DSM with multiple smooth terms (covariates), but when I ran the model it throws this error message:

Error in names(dat) <- object$term :
  'names' attribute [1] must be the same length as the vector [0]

In my google search (couldn't find any example particularly about DSM), people say this could be due to NA values present in data, so I filled in these but the same warning appeared. Others say that could be due to different numbers of columns between data frames (or that both didn't match specific columns), but looking at the spermwhale exercise of DSM, segment data and observation data don't have the exact number of columns nor they have to be duplicated. Anyway, I tried to duplicate both data frames, and the error still appeared.

So, I'm writing to you in case any have faced the same problem before, or if you have some thoughts on how to deal with it.

PS: when I ran the simple DSM model with s(x,y), using the same observation and segment data, nothing of this happened and I managed to get a model with which to predict abundance.

Daniel Ignacio Medina Oviedo
 M.V., Dipl. Universidad de Chile - UACH
        MSc Imperial College London

David Lawrence Miller

Sep 28, 2021, 5:22:38 AM9/28/21
to Daniel Medina,
Hi Daniel, hi listfolk,

I had a bit of chat off-list with Daniel and it looks like this issue
was caused by importing data with commas as the decimal separator rather
than periods (e.g., "0,3" rather than "0.3"). In this case R interprets
these variables as characters rather than numbers, which you can't
smooth over (with most smoothers). The best way to check for this is to
use the str() function in R on your data and it will tell you what the
type of each column is. Generally speaking, you'd want your variables
you're smoothing over to be numeric.

To correct this, you can run something like this, if your "bad" variable
is in column var1 of data.frame dat:

dat$var1 <- as.numeric(sub(",", ".", dat$var1))

Hope this helps,
> *Daniel Ignacio Medina Oviedo*
>  M.V., Dipl. Universidad de Chile - UACH
>         MSc Imperial College London
> --
> You received this message because you are subscribed to the Google
> Groups "distance-sampling" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to
> <>.
> To view this discussion on the web visit
> <>.

Daniel Medina

Sep 28, 2021, 12:47:54 PM9/28/21
to David Lawrence Miller,
Many thanks for your help on this matter Dave, I wouldn't have imagined that could be the cause of the problem from the cryptic message I got haha.

Daniel Ignacio Medina Oviedo
Reply all
Reply to author
0 new messages