|
|
Line 19: |
Line 19: |
| ==Rationale== | | ==Rationale== |
|
| |
|
| An rcode for managing the data into a more easily usable format. The produced csv file was then converted to zip and uploaded to [[:File:Monica.zip]]. | | An rcode for managing the data into a more easily usable format. The produced csv file was then converted to zip and uploaded to [[:File:Monica.zip]]. The code that produced the data file is documented on [[:File:Monica.zip]] |
| | |
| | |
| {{hidden|
| |
| <pre>
| |
| #File: http://www.tilastotiede.fi/ReplicaX/example_MONICA.r
| |
| #Author: Juha Karvanen (juha.karvanen at iki.fi)
| |
| #
| |
| #Summary: This code demonstrates the creation of data replicas with ReplicaX R functions.
| |
| #The R functions needed are available as http://www.tilastotiede.fi/ReplicaX/ReplicaX_functions.r
| |
| #For information see http://www.tilastotiede.fi/ReplicaX/ReplicaX_esitys.pdf (in Finnish)
| |
| #
| |
| #The data used is a published sample of WHO MONICA data.
| |
| #Before running the code, you should download the data from
| |
| #http://www.thl.fi/publications/monica/monograph_cd/data/form04_3.zip
| |
| #
| |
| #The data documentation can be found at
| |
| #http://www.thl.fi/publications/monica/monograph_cd/formats/form048.htm
| |
| #http://www.thl.fi/publications/monica/monograph_cd/formats/survey.htm
| |
| #
| |
| #For more information on the MONICA project see http://www.thl.fi/monica/
| |
| | |
| | |
| print("ReplicaX demonstration with the MONICA data. Running the code takes a couple minutes.")
| |
| | |
| #rm(list=ls())
| |
| set.seed(20131103) #to reproduce the results
| |
| #path <- "/home/jutakarv/Documents/replica_gen/"
| |
| #path <- "/home/q/tiede/replica_gen/"
| |
| #path <- paste(getwd(),"/",sep="")
| |
| #source(paste(path,"ReplicaX_functions.r",sep=""))
| |
| | |
| path <- "//cesium/jtue$/_Downloads/form04_3/" # This was the temporary file on my own computer when doing the conversion.
| |
| if(!file.exists(paste(path,"form04_3.txt",sep="")))
| |
| {
| |
| stop("Data file form04_3.txt does not exist in the current path.
| |
| Please download it from http://www.thl.fi/publications/monica/monograph_cd/data/form04_3.zip
| |
| or change the path definition")
| |
| }
| |
| widths <- c(
| |
| 2,1,2,2,6,1,3,8,8,1,1,1,1,2,1,3,1,1,4,1,3,2,1,3,1,3,2,1,1,1,1,1,1,1,1,1,2,1,1,3,3,2,3,3,2,1,2,2,4,2,3,3,8,3,3,8,3,4,2,3,4,
| |
| 4,4,2,1,2,1,1,1,1,1,4,4,4,4
| |
| )
| |
| | |
| colnames <- c(
| |
| "form","versn","centre","runit","serial","numsur","samunit","dexam","mbirth","agegr","sex","marit","edlevel",
| |
| "school","cigs","numcigs","daycigs","evercig","stop","iflyear","maxcigs","cigage","cigarsm","cigar","pipesm","pipe",
| |
| "othersm","hibp","drugs","bprecd","hich","chdt","chrx","chrecd","asp","menop","agem","horm","pill","syst1",
| |
| "diast1","rz1","syst2","diast2","rz2","cuff","arm","bpcoder","timebp","rtemp","chol","choldl","dchol","hdl",
| |
| "hdldl","dhdl","scn","cotin","carbmon","height","weight","waist","hip","whcoder","oversion","eage","eageg",
| |
| "cohort1","cohort2","edtert1","edtert2","systm","diastm","chola","hdla"
| |
| )
| |
| | |
| monica <- read.fwf(file=paste(path,"form04_3.txt",sep=""),widths=widths,col.names=colnames)
| |
| | |
| selectedcolnames <- c("marit","edlevel","school","height","weight","waist","hip")
| |
| monica2 <- monica[,selectedcolnames]
| |
| vartype <- c("discrete","discrete","discrete","continuous","continuous","continuous","continuous")
| |
| | |
| #decoding missing values
| |
| monica2$height[monica2$height==999] <- NA
| |
| monica2$weight[monica2$weight==9999] <- NA
| |
| monica2$waist[monica2$waist==9999] <- NA
| |
| monica2$hip[monica2$hip==9999] <- NA
| |
| monica2$school[monica2$school == 99] <- NA
| |
| | |
| #unit transformations
| |
| monica2$weight <- monica2$weight/10 #transform to kg
| |
| monica2$waist <- monica2$waist/10 #transform to cm
| |
| monica2$hip <- monica2$hip/10 #transform to cm
| |
| | |
| write.csv(monica, "//cesium/jtue$/_Documents/Monica.csv")
| |
| | |
| # This csv file was then zipped and uploaded to [[:File:Monica.zip]]
| |
| </pre>
| |
| }}
| |
|
| |
|
| ==See also== | | ==See also== |