Adding a covariate to a dsm

69 views
Skip to first unread message

chaona phiri

unread,
Feb 21, 2023, 8:10:58 AM2/21/23
to distance...@googlegroups.com
Hai guys,

I have been following the mexico dolphins example to develop dsm for some parrot species here in Zambia. I finally fitted two models and am now trying to add a covariate of Transect type (I had walking and driving transects) but am stuck with this error;
dsm.obj.T_Type <- dsm(count~s(X,Y,k=10) + s(T_Type,k=20), detfc.hr.null, segment.data = segment.data_new, observation.data = obsdata,method = "REML")
Error in names(dat) <- object$term :
  'names' attribute [1] must be the same length as the vector [0]

The Data:  I have segmented my transects into 0.5km which is 4860 rows of segments (segment.data) and I had 192 rows of observations (observation.data) - i used the same sample labelling in both, with the 192 of course not having each of the 4860 rows, only those with presence records - could this be the problem? and how can i get around it?

Chaona

Eric Rexstad

unread,
Feb 21, 2023, 8:33:14 AM2/21/23
to chaona phiri, distance...@googlegroups.com
Chaona

Without seeing more details about your data and analysis, I can only comment literally about the error message. From your note, you suggest you were able to successfully fit dsm models without the transect type covariate. Check whether the transect type field exists in both the segment.data and the observation.data and check that the field name "T_Type" is applied consistently in segment.data, observation.data and in the data that went into the detection function model fitting.

From: distance...@googlegroups.com <distance...@googlegroups.com> on behalf of chaona phiri <chaon...@gmail.com>
Sent: 21 February 2023 13:10
To: distance...@googlegroups.com <distance...@googlegroups.com>
Subject: [distance-sampling] Adding a covariate to a dsm
 
--
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 distance-sampl...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/distance-sampling/CANxq-ETu2csGchdOrOjAE-Gyg0YD80JF%2B%2B4Co3-MMe1ZTcK8kA%40mail.gmail.com.

chaona phiri

unread,
Feb 21, 2023, 8:42:41 AM2/21/23
to Eric Rexstad, distance...@googlegroups.com
Hai Eric, this is how many data looks;
1.Distdata was used to fit the detection function; it goes on for 4860 rows
image.png

2. The segment.data also goes on for 4860 rows
image.png
3. Observation.data which has the rows of the 192 presence records but follows the same sample labelling as the two above;
image.png

Eric Rexstad

unread,
Feb 21, 2023, 8:59:52 AM2/21/23
to chaona phiri, distance...@googlegroups.com
Your T_Type is a factor covariate (only taking on two possible values). You can't fit a smooth to that. You could add a term "as.factor(T_Type)" to your model. Have a read through some of the mgcv​ documentation.

Sent: 21 February 2023 13:42
To: Eric Rexstad <Eric.R...@st-andrews.ac.uk>
Cc: distance...@googlegroups.com <distance...@googlegroups.com>
Subject: Re: [distance-sampling] Adding a covariate to a dsm
 

Eric Rexstad

unread,
Feb 21, 2023, 9:07:13 AM2/21/23
to chaona phiri, Eric Rexstad, distance...@googlegroups.com
Chaona

Having transect type in your dsm model doesn't make sense. Remember, you will use the covariates in your dsm model to predict to places you didn't visit in your study area. Transect type is undefined for areas not sampled.

From: 'Eric Rexstad' via distance-sampling <distance...@googlegroups.com>
Sent: 21 February 2023 13:59
To: chaona phiri <chaon...@gmail.com>

chaona phiri

unread,
Feb 21, 2023, 9:11:10 AM2/21/23
to Eric Rexstad, distance...@googlegroups.com
This makes sense. Thank you, let me try with habitat although this wasn’t considered as a factor in fitting a detection function.

Thanks Eric, I will probably be back 😅.

Cheers

Chaona 
Reply all
Reply to author
Forward
0 new messages