Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Appendix S1 Example script to run replications of the quantile count model in R #Script to perform m replications of dithering of count data on multiple taus #based on Machado and Santos Silva (2005 JASA) #Results stored in matrix count.model3.rep50t98 #Confidence intervals can be turned off with rq(ci=F) and then reducing the #dimensions of the count.model3.rep50t98 matrix to ncol=6. #Data frame used was csss with column variables BC (raw counts), #WDAVGCM (water depth in cm),and ILAGBC (categorical factors for lag 1 counts #= 0, 1, 2, >=3. #Note that undefined weights based on ci=T,iid=F may cause estimation failure #for some random samples at some taus and require restarting estimation for #a subset of taus. taus<-c(0.50,0.60,0.70,0.75,0.80,0.85,0.90,0.91,0.92,0.93,0.94,0.95, 0.96,0.97,0.98) m <- 100 numtaus<- length(taus) count.model3.rep50t98<-matrix(0,nrow=m*numtaus,ncol=16) colnames(count.model3.rep50t98)<-c("tau","b0I0","lwr95b0I0","upr95b0I0", "b1I0","lwr95b1I0","upr95b1I0","difb0I1","lwr95difb0I1", "upr95difb0I1","difb0I2","lwr95difb0I2","upr95difb0I2", "difb0I3","lwr95difb0I3","upr95difb0I3") for(i in 1:m){ csss$DBC<-(csss$BC + runif(length(csss$BC[!is.na(csss$BC)]),min=0,max=1)) for (j in 1:numtaus){ csss$LOGDBC<-csss$DBC - taus[j] csss$LOGDBC[csss$LOGDBC<=0.0]<-0.00001 csss$LOGDBC<-log(csss$LOGDBC) rqfit<- rq(LOGDBC ~ WDAVGCM + ILAGBC,data=csss,tau=taus[j], ci=T,iid=F,alpha=0.05,contrasts=list(ILAGBC="contr.treatment")) count.model3.rep50t98[j + (i-1)*numtaus,]<-c(rqfit$tau,rqfit$coef[1,], rqfit$coef[2,],rqfit$coef[3,],rqfit$coef[4,],rqfit$coef[5,],use.names=F) } } ### ### ### ### Return quantile regression estimates to y counts for graphing, where simplified data set with one value for each 1 cm of water depth. Example for prior year counts = 0, where parameters come from averaging across m simulated values x <- matrix(seq(0,90,by=1),nrow=91,ncol=1) cssslag0<-data.frame(wdavgcm=x) cssslag0$qrq50<-ceiling(0.50+exp(-2.93014743-0.08969231*cssslag0$wdavgcm)-1) cssslag0$qrq60<-ceiling(0.60+exp(-2.72949536-0.09616953*cssslag0$wdavgcm)-1) cssslag0$qrq75<-ceiling(0.75+exp(-2.5123068-0.1003238*cssslag0$wdavgcm)-1) cssslag0$qrq90<-ceiling(0.90+exp(-2.33264227-0.09125396*cssslag0$wdavgcm)-1) cssslag0$qrq91<-ceiling(0.91+exp(-1.70786210-0.10857259*cssslag0$wdavgcm)-1) cssslag0$qrq95<-ceiling(0.95+exp(-0.07856737-0.13185230*cssslag0$wdavgcm)-1) cssslag0$qrq98<-ceiling(0.98+exp(0.7037903-0.1189377*cssslag0$wdavgcm)-1) ### Graph results for prior year counts = 0 in step function. plot(cssslag0$wdavgcm,cssslag0$qrq98,type="s",col="red",ylim=c(0,7),bty="l",xl im=c(0,90),xaxs="i",yaxs="i",yaxt="n",xaxt="n") axis(1,at=c(0,10,20,30,40,50,60,70,80,90),tcl=0.5) axis(2,at=c(0,1,2,3,4,5,6,7),tcl=0.5) lines(cssslag0$wdavgcm,cssslag0$qrq95,type="s",col="blue",bty="l",xaxs="i",yax s="i",xaxt="n",yaxt="n") lines(cssslag0$wdavgcm,cssslag0$qrq91,type="s",col="brown",bty="l",xaxs="i",ya xs="i",xaxt="n",yaxt="n")