NAs are not allowed in subscripted assignments

25 views
Skip to first unread message

Lyndon Brooks

unread,
Mar 19, 2024, 4:17:20 AMMar 19
to distance-sampling
Hi,
We're very early in the analysis of our data from a shipboard dual observer line transect survey for dolphins. We're working with the R package mrds.
We've inserted rows in the data for transects on which there were no detections to provide the information aboutwhere this occurred and how much effort was expended. There are blanks for object, observer, detected, size and distance. R puts NAs in the blanks.
When we try to run this, for example
ta.fi.mr.dist<-ddf(method="io.fi", mrmodel=~glm(link="logit", formula=~distance), data=gbr.ta.effort,meta.data=list(width=800
we get the error
Error in data$timesdetected[data$observer == 1] <- timesdetected :
NAs are not allowed in subscripted assignments
Can anyone help with this please? Thank you for any help you can offer.

Eric Rexstad

unread,
Mar 19, 2024, 5:50:58 AMMar 19
to Lyndon Brooks, distance-sampling
Lyndon

Welcome to the group. I'm fairly certain, based on the error message, that observer​ and detected​ need to be included even for transects on which there are no detections. Provide "1" and "2" in two rows  for the empty transects along with "0" in the detected field for each observer.

From: distance...@googlegroups.com <distance...@googlegroups.com> on behalf of Lyndon Brooks <lyndon....@gmail.com>
Sent: 19 March 2024 02:40
To: distance-sampling <distance...@googlegroups.com>
Subject: [distance-sampling] NAs are not allowed in subscripted assignments
 
--
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/52af72ff-5620-4363-af33-29b655608b4bn%40googlegroups.com.

Lyndon Brooks

unread,
Mar 19, 2024, 8:34:34 PMMar 19
to distance-sampling
Thank you, Eric.
I'm afraid that didn't work.
I now get this error message:
following objects were never detected:1000,1001,1002,1003,1004,1005,1006,1007,1008,1009,1010,1011,1012,1013,1014,1015,1016,1017,1018,1019,1020,1021,1022,1023,1024,1025,1026,1027,1028,1029,1030,1031,1032,1033,1034,1035,1036,1037,1038,1039,1040,1041,1042,1043,1044,1045,1046,1047,1048,1049,1050,1051,1052,1053,1054,1055,1056,1057,1058,1059,1060,1061,1062,1063,1064,1065,1066,1067,1068,1069,1070,1071,1072,1073,1074,1075,1076,1077,1078,1079,1080
I'm going to select only the detected objects (objects<1000) to fit a detection function. I'll then select them all and see if I can get an estimate of abundance. Lyndon.

Eric Rexstad

unread,
Mar 20, 2024, 2:47:34 AMMar 20
to Lyndon Brooks, distance-sampling
Sorry for the poor advice Lyndon.

I'll continue to investigate; afraid I've not encountered this previously.

Sent: 20 March 2024 00:34
To: distance-sampling <distance...@googlegroups.com>
Subject: Re: [distance-sampling] NAs are not allowed in subscripted assignments
 

Lyndon Brooks

unread,
May 21, 2024, 11:32:40 PMMay 21
to distance-sampling
Eric wrote back to me with the following advice:

"I've given your question some more thought and here is my revised answer to your original question:
I think when using the mrds​ R package, you cannot simply use the flatfile​ data format (as you can when using the Distance​ R package.  Instead you need to provide 4 data files
  • data frame containing observations (this is sent to ddf​ for detection function modelling). It cannot contain empty transects
  • information about the survey design comes from
    • region.table (strata and their size)
    • sample.table (transect lengths and the strata to which they belong)
    • obs.table (detection number and the transect and stratum to which they belong)
These last 3 are used by dht​. Separating information about the design from information about the detections means that "empty" transects do not need to be accounted for in the data frame  used for detection function modelling by the ddf​ function.
Read the ?ddf​ and ?dht​ documentation."

I'm pleased to report that this worked beatifully.
For anyone who's been waiting with bated breath, our project went in search of other priorities which are now satisfied, and we're now back on track.
B.T.W. This is a very efficient way to get these estimates; it aviods a lot of replication and the same region and sample files can be used for several species.

Thank you for your help, Eric!
Lyndon.


Reply all
Reply to author
Forward
0 new messages