# File: in98adjwts_arm.txt # Purpose: 1998 survey design for Upper Wabash Basin adjust weights # using DesignFile, frame information, and Site Evaluation file # Programmer: Tony Olsen # Date: January 2006 # #Example updated for R 2.2.1 and psurvey.analysis 2.9 # # Frame Stream length from RF3. Length includes all Strahler orders and possibly # both perennial and Non-perennial streams # The design documentation has 7663.497 km of stream; with 305.347 km in 5th-7th order framelen <- c('Upper Wabash'=7358.150) # Read Design File for 1998 Upper Wabash Basin # file is in sub folder named Original Data DesignFile <- read.delim('original_data\\inrb98.txt') head(DesignFile) # What are the MDcaty and StrahlerOrder present? table(DesignFile$MDCaty) table(DesignFile$StrahlerOrder) table(DesignFile$StrahlerOrder,DesignFile$MDCaty) # Import 1998 Site Evaluation file from Indiana SiteEval <- read.delim('original_data\\siteevaluation98.txt') head(SiteEval) # Check codes for StatusB - Biological Site Evaluation status table(SiteEval$StatusB) # Note on code meanings # TS - target and sampled site # NT - site was non-target (dry, non-wadeable,...) # LD - landowner denied access to site # PB - physical barrier - unable to reach site # OT - target site for which a sample was not collected # UK - Unknown whether site is target or non-target (shouldn't happen) # SCNB - target site Sampled for Chemistry but Not Biology (sampled fewer biology sites) # Create designstatus file designstatus <- merge(SiteEval, DesignFile, by.x='SiteIDF', by.y='SiteID') head(designstatus) nrow(designstatus) # Add equal area x,y coordinates to be used in variance estimation # Note that longitude must be changed to be negative tmp <- marinus(designstatus$Lat.dd,-designstatus$Long.dd) designstatus$xmarinus <- tmp[,'x'] designstatus$ymarinus <- tmp[,'y'] # Adjust weights to match frame length # Determine which sites to include in weight adjustment. # All 100 sites were evaluated so all should be used. # Note that original design weights assumed sample size of 50; # now have sample size of 100 sites <- rep(TRUE, nrow(designstatus) ) designstatus$final.wt <- adjwgt(sites,designstatus$Weight , designstatus$Basin, framelen) # Check out weights. sum of final weights must equal framelen. sum(designstatus$Weight) sum(designstatus$final.wt) # Write out Design Status File write.table(designstatus, file="designstatus.csv",sep=",",row.names=FALSE)