################################################################################ # APC_workshop_prep.R # # Created: 2010-04-07 by Caroline D # Updated: 2010-04-19 by Caroline D # # Uses: breast_i_6206.txt # # Package: Epi (apc.fit, apc.frame, apc.lines) # # Software: R # # Aim: Exercise used ahead of APC workshop # ################################################################################ # Set working directory - change to your own! # setwd("Z:/APC_workshop_2010/Data/Breast") # Install and load the Epi-package, if not installed on your local computer # install.packages("Epi", dependencies = TRUE) library(Epi) ################################ # Breast cancer incidence # for women in the Nordic # countries, ages 30-74 ################################ ########## # DENMARK ########## # Read in data t1 <- subset( read.table( "http://staff.pubhealth.ku.dk/~bxc/APC/data/breast_i_6206.txt", header = TRUE ), cou=="Denmark" & sex==2 & (A>=30 & A<=74) ) # Import t1 variables to R attach(t1) # Run apc.fit from the Epi package, for help type ?apc.fit in Console window ex.t1 <- apc.fit( t1, # Data dr.extr="Holford", # How drift is extracted using Holford method parm="APC", # What estimates to present [rates, RR, ...] # and also which effect to put to zero slope npar=c(5,6,10), # Number of parameters (age,period,cohort) scale=10^5 ) # Scale to display rates # Display rates print(ex.t1) ########## # FINLAND ########## # Read in data t2 <- subset( read.table( "http://staff.pubhealth.ku.dk/~bxc/APC/data/breast_i_6206.txt", header = TRUE ), cou=="Finland" & sex==2 & (A>=30 & A<=74) ) # Import t2 variables to R attach(t2) # Run apc.fit from the Epi package, for help type ?apc.fit in Console window ex.t2 <- apc.fit( t2, # Data dr.extr="Holford", # How drift is extracted using Holford method parm="APC", # What estimates to present [rates, RR, ...] # and also which effect to put to zero slope npar=c(5,6,10), # Number of parameters (age,period,cohort) scale=10^5 ) # Scale to display rates # Display rates print(ex.t2) ########## # NORWAY ########## # Read in data t3 <- subset( read.table( "http://staff.pubhealth.ku.dk/~bxc/APC/data/breast_i_6206.txt", header = TRUE ), cou=="Norway" & sex==2 & (A>=30 & A<=74) ) # Import t3 data to R attach(t3) # Run apc.fit from the Epi package, for help type ?apc.fit in Console window ex.t3 <- apc.fit( t3, # Data dr.extr="Holford", # How drift is extracted using Holford method parm="APC", # What estimates to present [rates, RR, ...] # and also which effect to put to zero slope npar=c(5,6,10), # Number of parameters (age,period,cohort) scale=10^5 ) # Scale to display rates # Display rates print(ex.t3) ########## # SWEDEN ########## # Read in data t4 <- subset( read.table ( "http://staff.pubhealth.ku.dk/~bxc/APC/data/breast_i_6206.txt", header = TRUE ), cou=="Sweden" & sex==2 & (A>=30 & A<=74)) # Import t4 data to R attach(t4) # Run apc.fit from the Epi package, for help type ?apc.fit in Console window ex.t4 <- apc.fit( t4, # Data dr.extr="Holford", # How drift is extracted using Holford method parm="APC", # What estimates to present [rates, RR, ...] # and also which effect to put to zero slope npar=c(5,6,10), # Number of parameters (age,period,cohort) scale=10^5 ) # Scale to display rates ################################ # Plot the effects ################################ # Frame for graphical display, see ?par for help par( mfrow=c(2,2) ) ########## # DENMARK ########## # Create APC frame for the graph, type ?apc.frame for help res <- apc.frame( a.lab=c(30,45,60,75), # Num vector of labels for age axis cp.lab=c(seq(1885,2005,10)), # Num vector of labels for cohort-period axis r.lab=c(1,2,5,10,20,50,100), # Num vector of labels for rate axis a.tic=seq(30,75,5), # Location of add tick marks on age scale r.tic=c(1:10,1:5*10), # Location of add tick marks on rate scale gap=15, # Gap between age scale and cohort-period scale a.txt="Denmark", # Text for age axis r.txt="", # Text for rate axis cp.txt="cohort slope set to zero") # Text for cohort-period axis # Create actual graph apc.lines( ex.t1, frame.par=res, col="blue", lwd=3) ########## # FINLAND ########## # Create APC frame for the graph, type ?apc.frame for help res <- apc.frame( a.lab=c(30,45,60,75), # Num vector of labels for age axis cp.lab=c(seq(1885,2005,10)), # Num vector of labels for cohort-period axis r.lab=c(1,2,5,10,20,50,100), # Num vector of labels for rate axis a.tic=seq(30,75,5), # Location of add tick marks on age scale r.tic=c(1:10,1:5*10), # Location of add tick marks on rate scale gap=15, # Gap between age scale and cohort-period scale a.txt="Finland", # Text for age axis r.txt="", # Text for rate axis cp.txt="cohort slope set to zero") # Text for cohort-period axis # Create actual graph apc.lines( ex.t2, # Data frame.par=res, # Use frame created above col="red", # Line color lwd=3) # Line width ########## # NORWAY ########## # Create APC frame for the graph, type ?apc.frame for help res <- apc.frame( a.lab=c(30,45,60,75), # Num vector of labels for age axis cp.lab=c(seq(1885,2005,10)), # Num vector of labels for cohort-period axis r.lab=c(1,2,5,10,20,50,100), # Num vector of labels for rate axis a.tic=seq(30,75,5), # Location of add tick marks on age scale r.tic=c(1:10,1:5*10), # Location of add tick marks on rate scale gap=15, # Gap between age scale and cohort-period scale a.txt="Norway", # Text for age axis r.txt="", # Text for rate axis cp.txt="cohort slope set to zero") # Text for cohort-period axis # Create actual graph apc.lines( ex.t3, # Data frame.par=res, # Use frame created above col="green", # Line color lwd=3) # Line width ########## # SWEDEN ########## # Create APC frame for the graph, type ?apc.frame for help res <- apc.frame( a.lab=c(30,45,60,75), # Num vector of labels for age axis cp.lab=c(seq(1885,2005,10)), # Num vector of labels for cohort-period axis r.lab=c(1,2,5,10,20,50,100), # Num vector of labels for rate axis a.tic=seq(30,75,5), # Location of add tick marks on age scale r.tic=c(1:10,1:5*10), # Location of add tick marks on rate scale gap=15, # Gap between age scale and cohort-period scale a.txt="Sweden", # Text for age axis r.txt="", # Text for rate axis cp.txt="cohort slope set to zero") # Text for cohort-period axis # Create actual graph apc.lines( ex.t4, # Data frame.par=res, # Use frame created above col="black", # Line color lwd=3) # Line width