Skip to content

Commit

Permalink
version 0.0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
wzhang27 authored and cran-robot committed Jul 14, 2020
1 parent a124835 commit a2e22e8
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 48 deletions.
12 changes: 6 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
Package: rSPARCS
Type: Package
Title: Statistical Package for Analysis Related Cleaning Support
Version: 0.0.7
Author: Wangjian Zhang, Bo Ye, Zhicheng Du, Ziqiang Lin, Jijin Yao, Yanan Jin, Wayne R. Lawrence, Yuantao Hao
Title: Sites, Polulation, and Records Cleaning Skills
Version: 0.0.8
Author: Wangjian Zhang, Bo Ye, Zhicheng Du, Ziqiang Lin, Jijin Yao, Yanan Jin, Wayne R. Lawrence
Maintainer: Wangjian Zhang <wzhang27@albany.edu>
Description: To clean and analyze hospital data, and generate sets for statistical modeling.
Description: Data cleaning including 1) generating datasets for time-series and case-crossover analyses based on raw hospital records, 2)linking individuals to a areal map, 3)picking out cases living within a certain distance from a site, etc. For more information, please refer to Zhang W,etc. (2018) <doi: 10.1016/j.envpol.2018.08.030>.
License: GPL-3
Encoding: UTF-8
LazyData: true
Imports: data.table,spatialEco,geosphere,tigris,raster,sp,plyr
NeedsCompilation: no
Packaged: 2019-11-06 14:21:34 UTC; wz913947
Packaged: 2020-07-14 15:29:50 UTC; LinLabAdmin
Repository: CRAN
Date/Publication: 2019-11-06 14:40:06 UTC
Date/Publication: 2020-07-14 17:10:02 UTC
16 changes: 8 additions & 8 deletions MD5
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
ceca8fcf826be6cb6e71c58dc7f41e64 *DESCRIPTION
c52f0fa0f63b35f33a7f1733ef8e6b09 *DESCRIPTION
7fab5dacbcfdafd1c826ac1e1602cfd1 *NAMESPACE
13f2d2c5342634658764c01e0c7182d5 *R/CXover.data.R
023f717b8e8d521fddf6a3a8ada6cb5f *R/CXover.data.R
ec506cc6ec38b021541e24ea28c2d779 *R/DBFgeocode.R
0b30da704f908b452c6df3f0a47ae00d *R/FIPS.name.R
fd64ea5de86896e7e58319411744c988 *R/FIPS.name.R
ab216426bc16c71407a1ab610681ce5a *R/case.series.R
90f75890fc9bf8a732db1cedc5f1b978 *R/desc.comp.R
0ad93862fdb1744d2a96ee6e2cae2e85 *R/dupl.readm.R
94753389fe82ef1c40c73e23ae5ac8ba *R/dupl.readm.R
57ad157b748a96f666592f99f952a0b1 *R/mediationking.R
ebfee48932401739b07fb0bc2e862341 *R/pick.cases.R
9c36851e2d19505224c38383b214d726 *R/raster_extract.R
b44de1dbcae35d27e6d2b507737cd2c7 *man/CXover.data.Rd
053eececad5859ba1b6c0072297289e3 *man/CXover.data.Rd
6e2eabbd39cd03cc539e3c9e5d92d069 *man/DBFgeocode.Rd
d9b501f6c9f77bfdcde482dfbece54f0 *man/FIPS.name.Rd
f959d33d6b112cd0ea7eee7960d59da1 *man/FIPS.name.Rd
01f074bdab28ca2eb634ed0f5a6008c6 *man/case.series.Rd
d55ad0b449e3eb41daa18d5e6ef3116e *man/desc.comp.Rd
4009cbd66cbf6593cc938c954f2c8c32 *man/dupl.readm.Rd
be9336e4ae1312de123a8bd20d8bf21a *man/mediationking.Rd
84f439996a3b6cd9e09a8d17189ab3c2 *man/mediationking.Rd
5dc0e3ba22311779a46f89d380e748e1 *man/pick.cases.Rd
5b974a7f23c47e6042083c5da98705d6 *man/raster_extract.Rd
f94537c9268a551cc054a61d5d3b9144 *man/raster_extract.Rd
4 changes: 2 additions & 2 deletions R/CXover.data.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CXover.data=function(data,date,ID=NULL,direction="pre4"){
CXover.data=function(data,date,ID=NULL,direction="month4"){
name=names(data)
if(length(ID)==0) data$ID=1:nrow(data) else data$ID=factor(data[,ID],levels=unique(data[,ID]))
test=as.character(data[,date])
Expand All @@ -21,6 +21,7 @@ CXover.data=function(data,date,ID=NULL,direction="pre4"){
data$date7_1=substr(data$date7,6,7)
data$date8_1=substr(data$date8,6,7)
if(direction=="pre4") data$date5=data$date6=data$date7=data$date8=NA
if(direction=="after4") data$date1=data$date2=data$date3=data$date4=NA
if(direction=="month4"){
data$d1_1=substr(data$d1,6,7)
data$date1=ifelse(data$date1_1==data$d1_1,data$date1,NA)
Expand All @@ -32,7 +33,6 @@ CXover.data=function(data,date,ID=NULL,direction="pre4"){
data$date7=ifelse(data$date7_1==data$d1_1,data$date7,NA)
data$date8=ifelse(data$date8_1==data$d1_1,data$date8,NA)
}
if(direction!="pre4"&direction!="month4") print("You may contact author (wzhang27@albany.edu) to add more options")
output=data[,c("ID","d1",name)]
names(output)[2]="Date"
output$status=1
Expand Down
8 changes: 4 additions & 4 deletions R/FIPS.name.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FIPS.name<-function(data,ID.case,long.case,lat.case,map="wz",state.map,level.map="wz",areaID="GEOID"){
FIPS.name<-function(data,ID.case,long.case,lat.case,map=NULL,state.map,level.map="wz",areaID="GEOID"){
name=names(data)
data$ID=data[,ID.case]
data$long.case=data[,long.case]
Expand All @@ -8,10 +8,10 @@ FIPS.name<-function(data,ID.case,long.case,lat.case,map="wz",state.map,level.map
a=ncol(data)
data1=data[which(!is.na(data$long.case)&!is.na(data$lat.case)),]
sp::coordinates(data1)=~long.case+lat.case
if(length(map)==0&level.map=="county") NYSmap=tigris::counties(state=state.map) else NYSmap=map
if(length(map)==0&level.map=="tract") NYSmap=tigris::tracts(state=state.map) else NYSmap=map
if(is.null(map)&level.map=="county") NYSmap=tigris::counties(state=state.map) else NYSmap=map
if(is.null(map)&level.map=="tract") NYSmap=tigris::tracts(state=state.map) else NYSmap=map
raster::crs(data1)=raster::crs(NYSmap)
data1=point.in.poly(data1,NYSmap)
data1=spatialEco::point.in.poly(data1,NYSmap)
data1=as.data.frame(data1)
data1=cbind(data1[,1:(a-2)],data1[,areaID])
names(data1)[ncol(data1)]="areaID"
Expand Down
11 changes: 5 additions & 6 deletions R/dupl.readm.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@ dupl.readm=function(data,UniqueID,date,period=365){
test=as.character(data[,date])
test=test[test!=""&!is.na(test)]
if(any(!is.na(grep("/",test[1])),!is.na(grep("-",test[1])))) data[,date]=as.Date(as.character(data[,date])) else data[,date]=as.Date(paste(substr(data[,date],1,4),"/",substr(data[,date],5,6),"/",substr(data[,date],7,8),sep=""))

test=which(duplicated(data[,c(UniqueID,date)]))
data$id.dupl=0
data$id.dupl[test]=1
data0=data[data$id.dup==0,]
data1=data[data$id.dup==1,]#save
data1=data[data$id.dup==1,]
if(nrow(data1)>0) data1$onlyone=0
test=which(data0[,UniqueID]%in%data0[which(duplicated(data0[,UniqueID])),UniqueID])
data0$onlyone=1
data0$onlyone[test]=0

test=unique(data0[data0$onlyone==0,UniqueID])

# admission time

for(i in 1:length(test)){
med=data0[data0[,UniqueID]==test[i],]
med=med[order(med[,date]),]
Expand All @@ -29,7 +28,7 @@ dupl.readm=function(data,UniqueID,date,period=365){
med$d3=med1$y
data0[data0[,UniqueID]==test[i],]=med
}

data=rbind(data0,data1)
names(data)[names(data)=="d3"]="Nadmission"
names(data)[names(data)=="d2"]="Period"
Expand Down
4 changes: 2 additions & 2 deletions man/CXover.data.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
\item{data}{a data.frame containing the date of each case.}
\item{date}{the name of the variable in the data indicating the date of each case reported to the database.}
\item{ID}{the name of the variable in the data indicating case ID, if not specified, it will automatically generated starting from 1.}
\item{direction}{"pre4"or"month4". With "pre4", each case day will be matched with same weekdays in previous 4 weeks. With "month4", each case day will be matched with same weekdays in the same month.}
\item{direction}{"month4" (default),"pre4" or "after4". With "pre4" (or "after4"), each case day will be matched with same weekdays in previous (or subsequent) 4 weeks. With "month4", each case day will be matched with same weekdays in the same month, which is the most common in literature.}
}
\details{Not limited to hospital data, but also applicable to other surveillance data.}
\value{
Expand All @@ -32,6 +32,6 @@ dataset=data.frame(
sex=sample(c("M","F"),1000,replace=TRUE),
county=sample(c("Albany","New York"),1000,replace=TRUE))

out.data=CXover.data(data=dataset,date="onset",ID="patient",direction="pre4")
out.data=CXover.data(data=dataset,date="onset",ID="patient",direction="month4")
head(out.data)
}
7 changes: 3 additions & 4 deletions man/FIPS.name.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ Wang-Jian Zhang (wzhang27@albany.edu)
}
\examples{
set.seed(2018)
dataset=data.frame(Patient=1:10,lat=rnorm(10,42,0.5),long=rnorm(10,-76,1))
#data.out=FIPS.name(data=dataset,ID.case="Patient",long.case="long",lat.case="lat",
#state.map="36",level.map="tract",areaID="GEOID")
#head(data.out)
dataset=data.frame(Patient=1:2,lat=rnorm(2,42,0.5),long=rnorm(2,-76,1))
#data.out=FIPS.name(data=dataset,ID.case="Patient",long.case="long",
#lat.case="lat",state.map="36",level.map="tract",areaID="GEOID")
}
7 changes: 4 additions & 3 deletions man/mediationking.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
Bo Ye (bye2@albany.edu)
}
\examples{
exposure<-rnorm(1000,0,1)
mediator<-rnorm(1000,10,3)
outcome<-rnorm(1000,10,4)
set.seed(1)
exposure<-rnorm(20,0,1)
mediator<-rnorm(20,10,1)
outcome<-rnorm(20,10,1)
dataset<-data.frame(outcome,mediator,exposure)
#mediationking(dataset,"outcome","mediator","exposure")
}
26 changes: 13 additions & 13 deletions man/raster_extract.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@
Wang-Jian Zhang (wzhang27@albany.edu)
}
\examples{
#library(raster)
#set.seed(4715)
#rast=raster(matrix(rnorm(500),100,100))
#extent(rast)=c(50,100,10,60)
#crs(rast)=CRS("+proj=longlat +datum=WGS84")
library(raster)
set.seed(4715)
rast=raster(matrix(rnorm(500),100,100))
extent(rast)=c(50,100,10,60)
crs(rast)=CRS("+proj=longlat +datum=WGS84")
#ref=cbind(x=c(60,80,80,70), y=c(20,25,40,30))
#p=Polygon(ref)
#ps=Polygons(list(p),ID="ID")
#ref=SpatialPolygons(list(ps))
#data=data.frame(value=1, ID="10086",row.names="ID")
#ref=SpatialPolygonsDataFrame(ref,data)
#proj4string(ref)=CRS("+proj=longlat +datum=WGS84")
ref=cbind(x=c(60,80,80,70), y=c(20,25,40,30))
p=Polygon(ref)
ps=Polygons(list(p),ID="ID")
ref=SpatialPolygons(list(ps))
data=data.frame(value=1, ID="10086",row.names="ID")
ref=SpatialPolygonsDataFrame(ref,data)
proj4string(ref)=CRS("+proj=longlat +datum=WGS84")
#raster_extract(rastermap=rast,refmap=SPDF,ID.var="ID",ID.code="ALL",cutpoint=0.5)
raster_extract(rastermap=rast,refmap=ref,ID.var="ID",ID.code="ALL",cutpoint=0.5)
}

0 comments on commit a2e22e8

Please sign in to comment.