使用WHO Anthro计算z评分时出错

7hiiyaii  于 2023-03-05  发布在  其他
关注(0)|答案(1)|浏览(196)

当我尝试使用WHO Anthro计算除第一个时间点(即基线)以外的所有时间点的z得分时,我得到了以下误差,当我使用不同的年龄变量作为基线时,它工作得很好。

df <- structure(list(adm_sex = c(2L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 
1L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 
2L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 
1L, 2L), age_days_wk3 = c(531, 584, 667, NA, NA, NA, NA, 206, 
267, 310, 228, 222, 544, 558, 405, NA, NA, NA, NA, NA, 363, 393, 
328, 308, 434, 342, 325, 264, NA, 264, NA, NA, NA, NA, NA, NA, 
250, -240, NA, NA, NA, NA, NA), wkly_weightwk3 = c(7.23, 8.55, 
7.44, NA, NA, NA, NA, 4.2, 6.52, 5.87, 4.22, 5.79, 7.95, 6.25, 
7.06, NA, NA, NA, NA, NA, 6.68, 6.42, 7.86, 6.16, 7.1, 5.44, 
7.4, 5.76, NA, 5.22, NA, NA, NA, NA, NA, NA, 6.83, 7.67, NA, 
NA, NA, NA, NA), ht_fwk3 = c(70.95, 79.2, 74.35, NA, NA, NA, 
NA, 59.45, 66.65, 65.25, 57.3, 61.75, 73.35, 71.9, 67.65, NA, 
NA, NA, NA, NA, 67.5, 68.45, 75.15, 68, 72, 63.2, 70.2, 62.55, 
NA, 59.45, NA, NA, NA, NA, NA, NA, 66.55, 73.05, NA, NA, NA, 
NA, NA)), row.names = c(NA, 43L), class = "data.frame")

library(anthro)

with(merge_dt_1, 
     anthro_zscores(sex = adm_sex, 
                    age = age_days_wk3,
                    weight = wkly_weightwk3,
                    lenhei = ht_fwk3))

向上舍入(res)时出错(_U):所有(x〉= 0,na.rm =真)不为真

8ljdwjyq

8ljdwjyq1#

在问题后面的注解中(以及代码中)注明信息,这将起作用。

library(anthro)
library(tidyverse)

as_tibble(df) %>% 
  drop_na() %>% # needs to have no NA values
  filter(age_days_wk3 > 0) %>% # one of the `age_days_wk3` values is below zero.
  mutate(wkly_weightwk3 = anthro_zscores(sex = adm_sex,
                                         age = age_days_wk3,
                                         weight = wkly_weightwk3,
                                         lenhei = ht_fwk3))

输出:

相关问题