optimum-mbp
fish <- telemetR::fish
receivers <- telemetR::receivers
detects <- telemetR::filtered_detections
local_tz <- "America/Los_Angeles"
fish <- format_org(fish,
var_Id = "TagCode",
var_release = "Release_Date",
var_tag_life = "TagLife",
var_ping_rate = "PRI",
local_time_zone = local_tz,
time_format = "%Y-%m-%d %H:%M:%S")
receivers <- format_receivers(receivers,
var_receiver_serial = "receiver_serial_number",
var_receiver_make = "receiver_make",
var_receiver_deploy = "receiver_start",
var_receiver_retrieve = "receiver_end",
local_time_zone = local_tz,
time_format = "%m/%d/%Y %H:%M:%S")
detects <- format_detects(detects,
var_Id = "Tag_Code",
var_datetime_local = "DateTime_Local",
var_receiver_serial = "ReceiverSN",
local_time_zone = local_tz,
time_format = "%Y-%m-%d %H:%M:%S")
# Build a new df which uses a range of blanking times to reprocess the original
# detection data (this is a slow process, especially for large datasets or
# large sequences of n)
blanked <- blanking_event(detects,
#Each general location is distinct enough to be a site
var_site = "receiver_general_location",
#Group the data by species, run, and origin (optional)
var_groups = "fish_type",
var_Id = "Tag_Code",
var_datetime = "DateTime_Local",
var_ping_rate = "tag_pulse_rate_interval_nominal",
n_val = seq(1,1000,5),
#Pulse rates for these tags are in seconds
time_unit = "secs"
)
head(blanked)
#> # A tibble: 6 × 9
#> fish_type Tag_Code mbp_n event_change receiver_general_location
#> <chr> <chr> <dbl> <int> <chr>
#> 1 MRH Steelhead 70A3 3 0 Grant_Line_DS
#> 2 MRH Steelhead 70A3 3 1 Grant_Line_DS
#> 3 MRH Steelhead 70A3 3 2 Grant_Line_DS
#> 4 MRH Steelhead 70A3 3 3 Grant_Line_DS
#> 5 MRH Steelhead 70A3 3 4 Grant_Line_DS
#> 6 MRH Steelhead 70A3 3 5 Grant_Line_DS
#> # ℹ 4 more variables: start_time <dttm>, end_time <dttm>, n_det <int>,
#> # duration <dbl>
# This function compares the durations of the events created above. The function
# collects all the events for each given blanking period and compares each
# event duration to a sequence of given times. It then calculates the proportion
# of events which are longer than each given time for each blanking period for
# each organism group
compared <- duration_compare(blanked,
var_groups = "fish_type",
time_seq = seq(1,10000,10))
#> t = 1t = 11t = 21t = 31t = 41t = 51t = 61t = 71t = 81t = 91t = 101t = 111t = 121t = 131t = 141t = 151t = 161t = 171t = 181t = 191t = 201t = 211t = 221t = 231t = 241t = 251t = 261t = 271t = 281t = 291t = 301t = 311t = 321t = 331t = 341t = 351t = 361t = 371t = 381t = 391t = 401t = 411t = 421t = 431t = 441t = 451t = 461t = 471t = 481t = 491t = 501t = 511t = 521t = 531t = 541t = 551t = 561t = 571t = 581t = 591t = 601t = 611t = 621t = 631t = 641t = 651t = 661t = 671t = 681t = 691t = 701t = 711t = 721t = 731t = 741t = 751t = 761t = 771t = 781t = 791t = 801t = 811t = 821t = 831t = 841t = 851t = 861t = 871t = 881t = 891t = 901t = 911t = 921t = 931t = 941t = 951t = 961t = 971t = 981t = 991t = 1001t = 1011t = 1021t = 1031t = 1041t = 1051t = 1061t = 1071t = 1081t = 1091t = 1101t = 1111t = 1121t = 1131t = 1141t = 1151t = 1161t = 1171t = 1181t = 1191t = 1201t = 1211t = 1221t = 1231t = 1241t = 1251t = 1261t = 1271t = 1281t = 1291t = 1301t = 1311t = 1321t = 1331t = 1341t = 1351t = 1361t = 1371t = 1381t = 1391t = 1401t = 1411t = 1421t = 1431t = 1441t = 1451t = 1461t = 1471t = 1481t = 1491t = 1501t = 1511t = 1521t = 1531t = 1541t = 1551t = 1561t = 1571t = 1581t = 1591t = 1601t = 1611t = 1621t = 1631t = 1641t = 1651t = 1661t = 1671t = 1681t = 1691t = 1701t = 1711t = 1721t = 1731t = 1741t = 1751t = 1761t = 1771t = 1781t = 1791t = 1801t = 1811t = 1821t = 1831t = 1841t = 1851t = 1861t = 1871t = 1881t = 1891t = 1901t = 1911t = 1921t = 1931t = 1941t = 1951t = 1961t = 1971t = 1981t = 1991t = 2001t = 2011t = 2021t = 2031t = 2041t = 2051t = 2061t = 2071t = 2081t = 2091t = 2101t = 2111t = 2121t = 2131t = 2141t = 2151t = 2161t = 2171t = 2181t = 2191t = 2201t = 2211t = 2221t = 2231t = 2241t = 2251t = 2261t = 2271t = 2281t = 2291t = 2301t = 2311t = 2321t = 2331t = 2341t = 2351t = 2361t = 2371t = 2381t = 2391t = 2401t = 2411t = 2421t = 2431t = 2441t = 2451t = 2461t = 2471t = 2481t = 2491t = 2501t = 2511t = 2521t = 2531t = 2541t = 2551t = 2561t = 2571t = 2581t = 2591t = 2601t = 2611t = 2621t = 2631t = 2641t = 2651t = 2661t = 2671t = 2681t = 2691t = 2701t = 2711t = 2721t = 2731t = 2741t = 2751t = 2761t = 2771t = 2781t = 2791t = 2801t = 2811t = 2821t = 2831t = 2841t = 2851t = 2861t = 2871t = 2881t = 2891t = 2901t = 2911t = 2921t = 2931t = 2941t = 2951t = 2961t = 2971t = 2981t = 2991t = 3001t = 3011t = 3021t = 3031t = 3041t = 3051t = 3061t = 3071t = 3081t = 3091t = 3101t = 3111t = 3121t = 3131t = 3141t = 3151t = 3161t = 3171t = 3181t = 3191t = 3201t = 3211t = 3221t = 3231t = 3241t = 3251t = 3261t = 3271t = 3281t = 3291t = 3301t = 3311t = 3321t = 3331t = 3341t = 3351t = 3361t = 3371t = 3381t = 3391t = 3401t = 3411t = 3421t = 3431t = 3441t = 3451t = 3461t = 3471t = 3481t = 3491t = 3501t = 3511t = 3521t = 3531t = 3541t = 3551t = 3561t = 3571t = 3581t = 3591t = 3601t = 3611t = 3621t = 3631t = 3641t = 3651t = 3661t = 3671t = 3681t = 3691t = 3701t = 3711t = 3721t = 3731t = 3741t = 3751t = 3761t = 3771t = 3781t = 3791t = 3801t = 3811t = 3821t = 3831t = 3841t = 3851t = 3861t = 3871t = 3881t = 3891t = 3901t = 3911t = 3921t = 3931t = 3941t = 3951t = 3961t = 3971t = 3981t = 3991t = 4001t = 4011t = 4021t = 4031t = 4041t = 4051t = 4061t = 4071t = 4081t = 4091t = 4101t = 4111t = 4121t = 4131t = 4141t = 4151t = 4161t = 4171t = 4181t = 4191t = 4201t = 4211t = 4221t = 4231t = 4241t = 4251t = 4261t = 4271t = 4281t = 4291t = 4301t = 4311t = 4321t = 4331t = 4341t = 4351t = 4361t = 4371t = 4381t = 4391t = 4401t = 4411t = 4421t = 4431t = 4441t = 4451t = 4461t = 4471t = 4481t = 4491t = 4501t = 4511t = 4521t = 4531t = 4541t = 4551t = 4561t = 4571t = 4581t = 4591t = 4601t = 4611t = 4621t = 4631t = 4641t = 4651t = 4661t = 4671t = 4681t = 4691t = 4701t = 4711t = 4721t = 4731t = 4741t = 4751t = 4761t = 4771t = 4781t = 4791t = 4801t = 4811t = 4821t = 4831t = 4841t = 4851t = 4861t = 4871t = 4881t = 4891t = 4901t = 4911t = 4921t = 4931t = 4941t = 4951t = 4961t = 4971t = 4981t = 4991t = 5001t = 5011t = 5021t = 5031t = 5041t = 5051t = 5061t = 5071t = 5081t = 5091t = 5101t = 5111t = 5121t = 5131t = 5141t = 5151t = 5161t = 5171t = 5181t = 5191t = 5201t = 5211t = 5221t = 5231t = 5241t = 5251t = 5261t = 5271t = 5281t = 5291t = 5301t = 5311t = 5321t = 5331t = 5341t = 5351t = 5361t = 5371t = 5381t = 5391t = 5401t = 5411t = 5421t = 5431t = 5441t = 5451t = 5461t = 5471t = 5481t = 5491t = 5501t = 5511t = 5521t = 5531t = 5541t = 5551t = 5561t = 5571t = 5581t = 5591t = 5601t = 5611t = 5621t = 5631t = 5641t = 5651t = 5661t = 5671t = 5681t = 5691t = 5701t = 5711t = 5721t = 5731t = 5741t = 5751t = 5761t = 5771t = 5781t = 5791t = 5801t = 5811t = 5821t = 5831t = 5841t = 5851t = 5861t = 5871t = 5881t = 5891t = 5901t = 5911t = 5921t = 5931t = 5941t = 5951t = 5961t = 5971t = 5981t = 5991t = 6001t = 6011t = 6021t = 6031t = 6041t = 6051t = 6061t = 6071t = 6081t = 6091t = 6101t = 6111t = 6121t = 6131t = 6141t = 6151t = 6161t = 6171t = 6181t = 6191t = 6201t = 6211t = 6221t = 6231t = 6241t = 6251t = 6261t = 6271t = 6281t = 6291t = 6301t = 6311t = 6321t = 6331t = 6341t = 6351t = 6361t = 6371t = 6381t = 6391t = 6401t = 6411t = 6421t = 6431t = 6441t = 6451t = 6461t = 6471t = 6481t = 6491t = 6501t = 6511t = 6521t = 6531t = 6541t = 6551t = 6561t = 6571t = 6581t = 6591t = 6601t = 6611t = 6621t = 6631t = 6641t = 6651t = 6661t = 6671t = 6681t = 6691t = 6701t = 6711t = 6721t = 6731t = 6741t = 6751t = 6761t = 6771t = 6781t = 6791t = 6801t = 6811t = 6821t = 6831t = 6841t = 6851t = 6861t = 6871t = 6881t = 6891t = 6901t = 6911t = 6921t = 6931t = 6941t = 6951t = 6961t = 6971t = 6981t = 6991t = 7001t = 7011t = 7021t = 7031t = 7041t = 7051t = 7061t = 7071t = 7081t = 7091t = 7101t = 7111t = 7121t = 7131t = 7141t = 7151t = 7161t = 7171t = 7181t = 7191t = 7201t = 7211t = 7221t = 7231t = 7241t = 7251t = 7261t = 7271t = 7281t = 7291t = 7301t = 7311t = 7321t = 7331t = 7341t = 7351t = 7361t = 7371t = 7381t = 7391t = 7401t = 7411t = 7421t = 7431t = 7441t = 7451t = 7461t = 7471t = 7481t = 7491t = 7501t = 7511t = 7521t = 7531t = 7541t = 7551t = 7561t = 7571t = 7581t = 7591t = 7601t = 7611t = 7621t = 7631t = 7641t = 7651t = 7661t = 7671t = 7681t = 7691t = 7701t = 7711t = 7721t = 7731t = 7741t = 7751t = 7761t = 7771t = 7781t = 7791t = 7801t = 7811t = 7821t = 7831t = 7841t = 7851t = 7861t = 7871t = 7881t = 7891t = 7901t = 7911t = 7921t = 7931t = 7941t = 7951t = 7961t = 7971t = 7981t = 7991t = 8001t = 8011t = 8021t = 8031t = 8041t = 8051t = 8061t = 8071t = 8081t = 8091t = 8101t = 8111t = 8121t = 8131t = 8141t = 8151t = 8161t = 8171t = 8181t = 8191t = 8201t = 8211t = 8221t = 8231t = 8241t = 8251t = 8261t = 8271t = 8281t = 8291t = 8301t = 8311t = 8321t = 8331t = 8341t = 8351t = 8361t = 8371t = 8381t = 8391t = 8401t = 8411t = 8421t = 8431t = 8441t = 8451t = 8461t = 8471t = 8481t = 8491t = 8501t = 8511t = 8521t = 8531t = 8541t = 8551t = 8561t = 8571t = 8581t = 8591t = 8601t = 8611t = 8621t = 8631t = 8641t = 8651t = 8661t = 8671t = 8681t = 8691t = 8701t = 8711t = 8721t = 8731t = 8741t = 8751t = 8761t = 8771t = 8781t = 8791t = 8801t = 8811t = 8821t = 8831t = 8841t = 8851t = 8861t = 8871t = 8881t = 8891t = 8901t = 8911t = 8921t = 8931t = 8941t = 8951t = 8961t = 8971t = 8981t = 8991t = 9001t = 9011t = 9021t = 9031t = 9041t = 9051t = 9061t = 9071t = 9081t = 9091t = 9101t = 9111t = 9121t = 9131t = 9141t = 9151t = 9161t = 9171t = 9181t = 9191t = 9201t = 9211t = 9221t = 9231t = 9241t = 9251t = 9261t = 9271t = 9281t = 9291t = 9301t = 9311t = 9321t = 9331t = 9341t = 9351t = 9361t = 9371t = 9381t = 9391t = 9401t = 9411t = 9421t = 9431t = 9441t = 9451t = 9461t = 9471t = 9481t = 9491t = 9501t = 9511t = 9521t = 9531t = 9541t = 9551t = 9561t = 9571t = 9581t = 9591t = 9601t = 9611t = 9621t = 9631t = 9641t = 9651t = 9661t = 9671t = 9681t = 9691t = 9701t = 9711t = 9721t = 9731t = 9741t = 9751t = 9761t = 9771t = 9781t = 9791t = 9801t = 9811t = 9821t = 9831t = 9841t = 9851t = 9861t = 9871t = 9881t = 9891t = 9901t = 9911t = 9921t = 9931t = 9941t = 9951t = 9961t = 9971t = 9981t = 9991
head(compared)
#> # A tibble: 6 × 4
#> # Groups: fish_type [1]
#> t fish_type mbp_n prop_res
#> <dbl> <chr> <dbl> <dbl>
#> 1 1 MRH Steelhead 3 0.266
#> 2 1 MRH Steelhead 18 0.721
#> 3 1 MRH Steelhead 33 0.801
#> 4 1 MRH Steelhead 48 0.830
#> 5 1 MRH Steelhead 63 0.824
#> 6 1 MRH Steelhead 78 0.823
residence_plot(compared, var_groups = "fish_type", time_unit = "secs")
#> Warning in scale_y_log10(): log-10 transformation introduced infinite values.

# NOTE: The curves last longer than the longest time! This should indicate we
# should add more times to test, and may need shorter intervals of n.
# Renormalized Sum of Squares
rSSR <- renorm_SSR(compared, var_groups = "fish_type")
head(rSSR)
#> # A tibble: 6 × 5
#> # Groups: fish_type [1]
#> fish_type mbp_n SSR n rSSR
#> <chr> <dbl> <dbl> <int> <dbl>
#> 1 MRH Steelhead 3 1.17 1000 0.00117
#> 2 MRH Steelhead 18 0.457 1000 0.000457
#> 3 MRH Steelhead 33 0.148 1000 0.000148
#> 4 MRH Steelhead 48 0.0108 1000 0.0000108
#> 5 MRH Steelhead 63 0.0635 1000 0.0000635
#> 6 MRH Steelhead 78 0.0741 1000 0.0000741
# Thresholds for 99% and 99.5% of total range
thresh <- telemetR::conv_thresholds(rSSR, var_groups = "fish_type",
thresh_levels = c(0.01,0.005))
optimums <- opt_mbp(rSSR, thresh)
rSSR_plot(rSSR, optimums, var_groups = "fish_type")
#> Warning: Removed 6 rows containing missing values or values outside the scale range
#> (`geom_line()`).

#> Warning in scale_y_log10(): log-10 transformation introduced infinite values.
#> Warning in scale_y_log10(): log-10 transformation introduced infinite values.
#> log-10 transformation introduced infinite values.
#> `geom_smooth()` using formula = 'y ~ x'
#> Warning: Removed 99 rows containing non-finite outside the scale range
#> (`stat_smooth()`).

# Note: This would be a bad choice of maximum blanking period. We have not yet
# reached convergence