• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

[公共数据库] NHANES

武飞扬头像
CodeMed
帮助1


title: “[公共数据库] NHANES”
draft: false
tags: [“公共数据库”,“NHANES”]
toc: true
autoCollapseToc: true

主页

分析数据时的建议

数据初次尝试

# NHANES 2017-2018 示例
library(foreign)
demo1<-read.xport("BPX_J.XPT")  # 血压系列数据
names(demo1)
demo1[1:5,]
table(demo1[,"BPAARM"])
demo2<-read.xport("body.XPT")  # BMI系列数据
demo3<-read.xport("Cardiovascular.XPT") # 心血管临床症状数据

table(demo1$SEQN %in% demo2$SEQN)
table(demo1$SEQN %in% demo3$SEQN)
table(demo2$SEQN %in% demo3$SEQN)
AllData <- Reduce(dplyr::full_join,list(demo1,demo2,demo3))

爬取下载

# 下载爬取
# 膳食数据为例 共14份
# 获取网站的url
url <- "https://wwwn.cdc.gov/nchs/nhanes/search/datapage.aspx?Component=Dietary&CycleBeginYear=2017"
# 实验室数据特点 #  只需要改下【数据类型】和【日期】
#     https://wwwn.cdc.gov/nchs/nhanes/search/datapage.aspx?Component=Laboratory&CycleBeginYear=2017
a=as.data.frame(readLines(url,encoding="UTF-8"))
names(a)[1] <- "wenzi"
row=grep(pattern=".XPT",a$wenzi);row_1
(a2=a[row,])
a3=stringr::str_extract(a2,"(?<=href).*(?=.XPT\">)");a3
(a3=gsub(pattern = "=\"/",replacement = "",a3))
a3name <- stringr::str_replace_all(a3, ".*?d{0,4}/", "")
a4=paste0("https://wwwn.cdc.gov/",a3,".XPT");a4
# 下载
getwd()
if(dir.exists("Ndata")==FALSE){dir.create("Ndata")}
setwd("Ndata")
getwd()
#
for (i in seq_along(a4)) {
    download.file(a4[i],destfile = a3name[i],
                  method = "curl", #"libcurl", "wget" and "curl"
                  quiet=FALSE)
}

# purrr::map2(.x=a4,.y=a3name,~ download.file(.x,.y,method = "curl",quiet=FALSE))

# 【-----并行下载-----】
downloadfun <- function(x) {
  print(x)
  for (i in x) {
    download.file(a4[i],a3name[i],method = "curl",quiet=FALSE)
  }
}
library(foreach)   #for循环的提速包
library(doParallel)
#用Window的是i5或i7处理器,获得实际的物理核心数量
detectCores(logical = F)
detectCores()
cl<- makeCluster(8)      
# 登记
registerDoParallel(cl)
foreach(.combine = list,i = 1:14) %dopar% downloadfun(i)

stopCluster(cl) #终止并行运算
学新通

数据下载规律寻找

https://wwwn.cdc.gov/Nchs/Nhanes/2017-2018/CDQ_J.XPT
https://wwwn.cdc.gov/Nchs/Nhanes/2017-2018/DEMO_J.XPT
https://wwwn.cdc.gov/Nchs/Nhanes/1999-2000/DEMO.XPT
https://wwwn.cdc.gov/Nchs/Nhanes/2017-2018/P_DEMO.XPT

帮助文档链接测试, 后续强化搜索功能

https://wwwn.cdc.gov/Nchs/Nhanes/2017-2018/DEMO_J.htm

下载页网站

https://wwwn.cdc.gov/Nchs/Nhanes/search/datapage.aspx?Component=Demographics&CycleBeginYear=1999

https://wwwn.cdc.gov/Nchs/Nhanes/search/datapage.aspx?Component=Demographics&CycleBeginYear=2017

https://wwwn.cdc.gov/Nchs/Nhanes/search/datapage.aspx?Component=Demographics&CycleBeginYear=2018

https://wwwn.cdc.gov/Nchs/Nhanes/search/datapage.aspx?Component=Demographics&CycleBeginYear=2019 [无]

学新通

施工中ing…

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhggjfaf
系列文章
更多 icon
同类精品
更多 icon
继续加载