我正在尝试使用 Christof Neumann 包的 socialindices 来计算男女之间的 DSI 分数。我有三个数据帧:一个包含行为观察,一个包含观察时间,另一个包含存在文件。以下是它们的结构:
> str(observations)
tibble [476 × 6] (S3: tbl_df/tbl/data.frame)
$ date : Date[1:476], format: "2022-10-20" "2022-10-14" "2022-10-14" "2022-09-20" ...
$ focal : chr [1:476] "Sho" "Sho" "Sho" "Buk" ...
$ actor : chr [1:476] "Ginq" "Sho" "Ndaw" "Ginq" ...
$ receiver: chr [1:476] "Sho" "Ndaw" "Sho" "Buk" ...
$ beh : chr [1:476] "Approach" "Approach" "Groom.focal" "Contact.focal" ...
$ dur : int [1:476] NA NA 128 661 223 899 434 NA 19 NA ...
> str(ot)
'data.frame': 209 obs. of 3 variables:
$ focal: chr "Buk" "Buk" "Buk" "Buk" ...
$ date : chr "2022-06-07" "2022-06-11" "2022-06-15" "2022-06-17" ...
$ OT : int 1204 1212 1212 1200 1200 1202 1205 635 1204 963 ...
> str(pres)
'data.frame': 374 obs. of 5 variables:
$ date: chr "2022-01-03" "2022-01-04" "2022-01-05" "2022-01-06" ...
$ Buk : int 1 1 1 0 1 1 1 1 1 1 ...
$ Ginq: int 1 1 1 1 1 1 1 1 1 1 ...
$ Ndaw: int 1 1 1 1 1 1 1 1 1 1 ...
$ Sho : int 1 1 1 1 1 1 1 1 1 1 ...
因为我有兴趣了解男女关系如何随着时间的推移而演变,所以我选择让我的男性作为我的焦点个体。这意味着在这个特定的群体中,我有两个焦点个人(Buk 和 Sho),每个人都有三个潜在的合作伙伴。
这是我要运行的代码:
scores <- DSI(observations, ot.source = ot, presence = pres, onlyfocaldyads = F, limit2focalnonfocal = T, duration.NA.treatm = "count")
但我不断收到此错误:
Error in strptime(xx, ff, tz = "GMT") : input string is too long
我所有的日期列都是日期,它们的范围是相同的。当我使用所有观察结果时,之前的相同计算也有效,但这并不能真正达到我的目的。如果有人知道为什么这不起作用,我将非常感激!
DSI()
仅接受data.frame()
对象,并且您的观察对象是tibble()
。下面是一个生成错误的 reprex,后面是一个可行的解决方案:
# install.packages("remotes")
remotes::install_github("gobbios/socialindices")
library(socialindices2)
# Load sample data
data(dataset3)
# Create representative dataframes
observations <- tibble(dataset3[[1]])
ot <- data.frame(dataset3[[2]])
pres <- data.frame(dataset3[[3]])
# Caculate dyadic CSI
scores <- DSI(observations,
ot.source = ot,
presence = pres,
onlyfocaldyads = F,
limit2focalnonfocal = T,
duration.NA.treatm = "count")
# Error in strptime(xx, ff, tz = "GMT") : input string is too long
# Convert observations to df
observations <- data.frame(observations)
# Caculate dyadic CSI again
scores <- DSI(observations,
ot.source = ot,
presence = pres,
onlyfocaldyads = F,
limit2focalnonfocal = T,
duration.NA.treatm = "count")
scores
# i1 i2 type dyad dot cores appr gro prox supp appr.rt gro.rt prox.rt supp.rt DSI zDSI
# 1 a d FNF a_@_d 3877 119 1 2190 1805 1 0.6675996 5.2571514 4.3288838 0.7880743 2.76043 1.17610
# 2 a n FNF a_@_n 3208 98 0 325 192 0 0.0000000 0.9428686 0.5564952 0.0000000 0.37484 -0.56118
# 3 a v FNF a_@_v 3877 119 0 117 67 2 0.0000000 0.2808615 0.1606843 1.5761486 0.50442 -0.38591
# 4 d f FNF d_@_f 6658 200 2 87 195 3 0.7774958 0.1216123 0.2723236 1.3767035 0.63703 -0.24598
# 5 f n FNF f_@_n 6026 179 2 580 421 2 0.8590387 0.8957793 0.6496022 1.0140604 0.85462 -0.11512
# 6 f v FNF f_@_v 6658 200 7 342 569 0 2.7212355 0.4780623 0.7946264 0.0000000 0.99848 0.07002
# 7 d j FNF d_@_j 4162 119 0 92 459 1 0.0000000 0.2057254 1.0254279 0.7341096 0.49132 -0.41839
# 8 j n FNF j_@_n 3481 98 2 96 345 4 1.4870920 0.2566666 0.9215303 3.5109037 1.54405 0.55217
# 9 j v FNF j_@_v 4162 119 4 251 130 0 2.4875384 0.5612726 0.2904262 0.0000000 0.83481 -0.07171