RDX2 X  calc.ct source ;function(df=fumig, times=c(5,10,30,60,90,120), ctcols=3:8){ ' usualfac <- c(7.5,12.5,25,30,30,15)  modfac <- c(20,25,30,30,15)  modtimes <- c(15,30,60,120)  require(splines)  m <- dim(df)[1]  x1 <- times[-1]  conc15 <- numeric(m)  usualct <- numeric(m)  modct <- numeric(m)  for(i in 1:m){ y <- unlist(df[i, ctcols])  y1 <- y[-1] ! ct.lm <- lm(y1 ~ ns(x1,4)) ) xy = data.frame(x1=c(15,30,60,120)) ' hat <- predict(ct.lm, newdata=xy)  conc15[i] <- hat[1] & usualct[i] <- sum(usualfac*y)/60 # modct[i] <- sum(modfac*y1)/60  } ; df <- cbind(usualct=usualct, modct=modct, df[,-ctcols], ! estconc15=conc15)  df  } df fumig times c@@$@>@N@V@^ ctcols :@@  { <- usualfac@@)@9@>@>@.  modfac@4@9@>@>@.  modtimes@.@>@N@^ require splines  m [ dim?  x1 -?  conc15 numeric  usualct  modct for i?   y unlist  y1?  ct.lm lm ~ ns@ = xy data.frame@.@>@N@^  hat predict newdata# %?  / sum * @N ()* @N  cbind estconc15 cdsDeltaV  levels 0-9 10-24 25-39 40-54 55+ class factor . airbag none/ factor . seatbelt none/ factor@@@@H@U@x@@J@@`@ @@,@(@@B@@A PAK).A'@~@1AA;PA&@@؆@gA!_A @x@K@:@A1`A!h@o@@?*??g^?.C=?:Trht?@?+{%^?n1ϓ/?}Ib?BG?qV2 ?k+?H ?y Iw col=c("darkblue","turquoise"))), 9 xlab=list("Average reduction: 30 min vs 0 min",  cex=1.0),  scales=list(cex=1.0), " panel=function(x,y,...){ $ panel.stripplot(x,y,...) ? ltext(x,y,paste(c(3,9,15,7,22,12)), pos=1, cex=0.8) < }, auto.key=list(columns=2, points=TRUE, cex=1.0)) ) ;## plot(rep(c(30, 90, 150),6), unlist(gaba[c(2,5,8), 2:7]), ,## pch=rep(c(16,15,1,0,16,15),rep(3,6)), +## col=rep(c("gray","black"), c(12,6)), +## xlab="Reduction in VAS pain rating") ;## text(rep(c(30, 90, 150),6), unlist(gaba[c(2,5,8), 2:7]), @## labels=rep(c(paste(c(3,15,9,7)),12,22), rep(3,6)), pos=4) if(device!="")dev.off() gabalong } min@> device   if !=4  trellis.device pdf width@  height@ffffff file $~/courses/dm/dmcourse/Art/gaba30.pdf  gabalong stack gaba paste3 select3  $< sexA< ind .A< sex rep all female maleC@@ A<B factorA< sex A< treatmentA< ind .A< treatmentC Baclofen No baclofen@ print stripplot B values groupsE data< par.settings list superpose.symbolL cex?? pch@0@0 col darkblue turquoise xlabL "Average reduction: 30 min vs 0 minN? scalesLN? panel function$ x$ ...  panel.stripplotUV ltextU?@@"@.@@6@( pos?N?陙 function(x,y,...){ $ panel.stripplot(x,y,...) ? ltext(x,y,paste(c(3,9,15,7,22,12)), pos=1, cex=0.8) } auto.keyL columns@ points N?564  dev.off< cricket . 1 2/ factor . A B/ factor@D@n@Q@I@@@?@$@D@,@I0 Innings Bowler runs wickets rw1 1 2 3 4/ data.frame errorsINx 9function(mu = 20, n = 100, a = 15, b = 2.5, sigma = 12.5, ! timesSigma=(1:5)/2.5){ 7 mat <- matrix(0, nrow=n, ncol=length(timesSigma)+2) ! x0 <- mu*exp(rnorm(n,1,0.15)) " y <- a + b*x0+rnorm(n,0,sigma) $ mat[, length(timesSigma)+2] <- y  mat[,1] <- x0  sx <- sd(x0) k <- 1  for(i in timesSigma){  k <- k+1 x1 <- x0+rnorm(n, 0, sx*i)  mat[, k] <- x1  }  mat  } mu@4 n@Y a@. b@ sigma@) timesSigma( (?@@   mat matrix nrowa ncol + lengthe@  x0*` exp rnorma??333333 kkb*cmoad gkle@ g?m  sx sdm  k?e  rkr? kmoa*p grg florida C XI |&ksc9&t !6C%]v U % 7HjM9 X hg@c(B#Sn $/;LW1% Ww{' C% 9[t0 *j RE1@  0 iwNGyo# +$ \_H>@K LfhU _4ID&/^N A&/w CIA:ZzY1$S!' GcDLif !1C'3l/Z + O:|71rl.xX C 5<Tv'b2xK Ua8V'Kg[L6 3B) @' {X3;  ] C  )<4   t3P{(J\ ii?9|5mr'55 D C*'"w $Q#AR; ^&!  C 1X$#   -( && C #$ .  C%L{  |)    ` 1 -!gM$ ;F; CHJ E9n B " !) F. +  o CP!Uz6EBgHL u:i8 Z}d3? Y91 cV\&~Ej-yf]0mtTV0V!GZC ALACHUA BAKER BAY BRADFORD BREVARD BROWARD CALHOUN CHARLOTTE CITRUS CLAY COLLIER COLUMBIA DADE DE.SOTO DIXIE DUVAL ESCAMBIA FLAGLER FRANKLIN GADSDEN GILCHRIST GLADES GULF HAMILTON HARDEE HENDRY HERNANDO HIGHLANDS HILLSBOROUGH HOLMES INDIAN.RIVER JACKSON JEFFERSON LAFAYETTE LAKE LEE LEON LEVY LIBERTY MADISON MANATEE MARION MARTIN MONROE NASSAU OKALOOSA OKEECHOBEE ORANGE OSCEOLA PALM.BEACH PASCO PINELLAS POLK PUTNAM ST.JOHNS ST.LUCIE SANTA.ROSA SARASOTA SEMINOLE SUMTER SUWANNEE TAYLOR UNION VOLUSIA WAKULLA WALTON WASHINGTON0 GORE BUSH BUCHANAN NADER BROWNE HAGELIN HARRIS MCREYNOLDS MOOREHEAD PHILLIPS Total County1C ALACHUA BAKER BAY BRADFORD BREVARD BROWARD CALHOUN CHARLOTTE CITRUS CLAY COLLIER COLUMBIA DADE DE.SOTO DIXIE DUVAL ESCAMBIA FLAGLER FRANKLIN GADSDEN GILCHRIST GLADES GULF HAMILTON HARDEE HENDRY HERNANDO HIGHLANDS HILLSBOROUGH HOLMES INDIAN.RIVER JACKSON JEFFERSON LAFAYETTE LAKE LEE LEON LEVY LIBERTY MADISON MANATEE MARION MARTIN MONROE NASSAU OKALOOSA OKEECHOBEE ORANGE OSCEOLA PALM.BEACH PASCO PINELLAS POLK PUTNAM ST.JOHNS ST.LUCIE SANTA.ROSA SARASOTA SEMINOLE SUMTER SUWANNEE TAYLOR UNION VOLUSIA WAKULLA WALTON WASHINGTON/ data.frame  . Applied Test 1 Applied Test 2 Applied Test 3 Confirmation Test Query Applied Test 4 Applied Test Applied Test 5 Applied Test 6/ factor . Bogapple Chewton Pear/ factor@6@5@;@9@8@6fffff@8fffff@8@4@533333@:@8ffffff@6@6@7@7L@2@1@7@6@4@5@6fffff@5@333333@233333@5ffffff@4@4@4@4333333@3@3@0fffff@5L@333333@233333@2@5@2ffffff@2L@1ffffff@4@3333333@1@1fffff@3L@20 testnam Cultivar X5 X10 X30 X60 X90 X1201 1 2 3 4 5 6 7 8/ data.frame> @$@>@I@Q@V@[@`@@b@e@ ?<<<<<;??ЬЬI$I$+t+s55ZZZZZ[ ?<<<<<;?ZZZZZ[?::"k"k"k"kvQvQz1z2mm ЬЬ @z1z2@ @ &&@3X3Y@Ь?? V W?<<<<<;? @oݔoݕ@ @ OO@gBgB?\\?Ճ::?::?3X3Y?ؽOO @4X4Y@@V V@gCgD?lHlG??>?ee? 0 0?EE @@??+t+v\\ ||ƿk"k"V V 0 min mbac mpl fbac fpl avbac avplac1 10 30 50 70 90 110 130 150 170/ data.frame hardcopy' 5function(width=3.75, height=3.75, color=F, trellis=F, = device=c("","pdf","ps"), path="~/r-book/ed2/Art/", & pointsize=c(8,4), horiz=F){  ## 1 x 1: 2.25" x 2.25"  ## 2 x 2: 2.75" x 2.75" D ## 3 x 3: 3.75" x 3.75" or 3.25" x 3.25" for simple scatterplots  ## 1 x 2: 4" x 2.25"  ## 2 x 3: 4" x 2.8"  ## 3 x 4: 4.5" x 3.25 ) if(!trellis)pointsize <- pointsize[1]  funtxt <- sys.call(1) @ fnam <- strsplit(as.character(funtxt), "(", fixed=T)[[1]][1] * dotsplit <- strsplit(fnam, "\\.")[[1]] , dotsplit[1] <- substring(dotsplit[1], 2) G prefix1 <- paste(if(nchar(dotsplit[1])==1)"0" else "", dotsplit[1],  sep="") G prefix2 <- paste(if(nchar(dotsplit[2])==1)"0" else "", dotsplit[2],  sep="") 3 suffix <- switch(device, ps=".eps", pdf=".pdf") = fnam <- paste(path, prefix1,"-", prefix2, suffix, sep="")  print(fnam)  dev.out <- device[1] 6 dev.fun <- switch(dev.out, pdf=pdf, ps=postscript)  if(trellis){  library(lattice) / trellis.device(file=fnam, device=dev.fun, # color = color, = width=width, height=height, horiz=horiz) R trellis.par.set(list(fontsize=list(text=pointsize[1], points=pointsize[2])))  } else  if (dev.out!=""){  print(c(width, height)) + dev.fun(file=fnam, paper="special",  horiz=horiz, C width=width, height=height, pointsize=pointsize[1])  }  }$9@$:@ color F trellisv$4  pdf ps path ~/r-book/ed2/Art/$ pointsize@ @ horizv 5 !w yy?  funtxt sys.call?  fnam [[ strsplit as.character| ( fixed T??  dotsplit~ \.? ? substring?@  prefix1?5 == nchar?? 0 ? sep   prefix2?5@? 0 @   suffix switch4 ps .eps8 .pdf ~?x - F~  dev.out4?  dev.fun88 postscript5w  library lattice7;~4uu99::zz trellis.par.setL fontsizeL texty?\y@56  F9:;~ paper specialzz99::yy? intersalt4?bM?hr!?9XbM?$/?tj?\(?ؓtj~?1&x?և+ I?Z1'?A7Kƨ?\(?ӶE?Q?+?؃nP?lC?tj?׮zG?ԋC%?܋C%?A7Kƨ?+?&x?Ƨ-?˅Q?C$?bM?1&x?\(?ى7KƧ?ם-V?S?^5?|?dZ1?M?zG?\(\?|hr?\(?ҏ\(?zG{?I^5?}?\(?`A7?GzH?Ƨ-?Gz?1&?333333?dZ1? =p 4@R@S@Ry@Nٙ@N33333@RY@S@Pfffff@Tfffff@R@S`@SY@S@Q@Q@Ry@Sfffff@Qy@S@R9@Q@P@R`@P@SL@R&fffff@S@Os33333@Pfffff@Pٙ@Q@R@Sy@S@Qٙ@Rfffff@R,@Q@R@R@RFfffff@Q@R@Q@S@R@RL@TY@S @R@RFfffff@Rfffff4@b@`@a33333@333333?ə@b@g @hC33333@`33333@aVfffff@d33333@b @gfffff@`33333@hL@c&fffff@e@e<@e@@dS33333@d33333@effffff@i&fffff@Ifffff@d33333@`33333@bL@:@h@c33333@nC33333@g@e33333@e@i,@d9@d@efffff@afffff@[33333@b@b@b@`@W@_y@`I@a33333@`@d@@e@`6fffff44 Argentina Belgium Belgium Brazil Brazil Canada Canada Colombia Denmark East Germany Finland Finland Hungary Iceland India India Italy Italy Italy Italy Japan Japan Japan Kenya Malta Mexico Netherlands PNG PRC PRC PRC Poland Poland Portugal South Korea SovietUnion Spain Spain Taiwan Trinidad UK UK UK US USBlack US Hawaii USBlack US West Germany West Germany Zimbabwe14 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52/ data.frame0 b bp na V4 country last.warning0 Jcannot open compressed file '/Users/johnm/r/courses/r-courses/fumig.RData' plot.gaba1 function (confound = TRUE) { $ figno <- as.numeric(confound) + 21 = oldpar <- par(cex = 1.1, mex = 1.2, mgp = c(2.25, 0.5, 0), 5 mar = par()$mar + c(4.5, 0, -3.5, 0))  on.exit(par(oldpar))  mr <- range(gaba$min) 5 tran <- range(gaba[, c("mbac","mpl","fbac","fpl")]) ^ plot(mr, tran, xlab = "Time post pentazocine (min)", ylab = "Reduction in VAS pain rating", 7 type = "n", xlim = c(0, 170), ylim = c(-3.5, 7)) B points(gaba$min, gaba$fbac, pch = 1, col = 8, lwd = 2, lty = 2,  type = "b") A points(gaba$min, gaba$fpl, pch = 0, col = 8, lwd = 2, lty = 2,  type = "b") E points(gaba$min, gaba$mbac, pch = 16, col = 8, lty = 2, type = "b") D points(gaba$min, gaba$mpl, pch = 15, col = 8, lty = 2, type = "b")  points(0, 0, pch = 0)  points(0, 0, pch = 1)  cwh <- par()$cxy 6 xy <- par()$usr[c(1, 4)] + c(cwh[1], -0.05 * cwh[2])  xy[2] <- xy[2] - 0.1 * cwh[2]  if (confound) ! legend("topright", ncol = 2, M pch = c(1, 16, 16, 0, 15, 15), lty=c(2,2,1,2,2,1), F col = c(8, 8, 1, 8, 8, 1), legend = c("females, baclofen", e "males, baclofen", "combined, baclofen", "females, placebo", O "males, placebo", "combined, placebo")) # else legend("topleft", ncol = 2, 6 pch = c(1, 16, 0, 15), col = c(8, 6, 8, ^ 6), legend = c("females, baclofen", "males, baclofen", S "females, placebo", "males, placebo"))  if (confound) { . bac <- (15 * gaba$fbac + 3 * gaba$mbac)/18 , plac <- (7 * gaba$fpl + 9 * gaba$mpl)/16 @ points(gaba$min, plac, pch = 15, lty = 1, col=1, type = "b") ? points(gaba$min, bac, pch = 16, lty = 1, col=1, type = "b") box()  } ! figtxt <- paste("Fig. ", figno, ? ": The effect of pentazocine on post-operative pain,\n", ? "with (circles) and without (squares) preoperatively\n", * "administered baclofen.", sep = "")  if (confound)  figtxt <- paste(figtxt, 9 " Also shown (solid black circles \n", P "& squares) is the combined result, obtained by averaging \n", ' "over all patients.") : mtext(side = 1, line = 7, figtxt, adj = -0.1, cex = 1.1) } confound    fignok as.numeric@5  oldpar parN?񙙙 mex?333333 mgp@? markA mar@@  on.exit  mr rangeA> min  tran> mbac mpl fbac fpl plotQ Time post pentazocine (min) ylab Reduction in VAS pain rating type n xlim@e@ ylim@ @\A> minA> fbacO?P@  lwd@ lty@ b\A> minA> fplOP@ @@ b\A> minA> mbacO@0P@ @ b\A> minA> mplO@.P@ @ b\O\O?  cwhA cxy #kA usr?@?*?@ #@#@*?@5 legend toprightj@O?@0@0@.@.@@?@@?P@ @ ?@ @ ? females, baclofen males, baclofen combined, baclofen females, placebo males, placebo combined, placebo topleftj@O?@0@.P@ @@ @ females, baclofen males, baclofen females, placebo males, placebo5   bac(fk*@.A> fbac*@A> mbac@2  plac(fk*@A> fpl*@"A> mpl@0\A> minO@.?P? b\A> minO@0?P? b box  figtxt? Fig.  4: The effect of pentazocine on post-operative pain,  4with (circles) and without (squares) preoperatively  administered baclofen. 5 ? # Also shown (solid black circles  :& squares) is the combined result, obtained by averaging  over all patients. mtext side? line@ adj?N?񙙙 plot.intersalt dset intersalt1@   oma@A mar@   lowna@@@8@<A naA bpO@.@I@U@Q #Median sodium excretion (mmol/24hr) Median diastolic BP (mm Hg) n\A naA bpO@0\A naA bpO?@  u  bp naJ ablineA coef?A coef@ ? Fig.  +: Plot of median blood pressure versus salt -\n(measured by sodium excretion) for 52 human 2\npopulations. Four results (open circles) are for 9\nnon-industrialised societies with very low salt intake, 7\nwhile other results are for industrialised societies. ?@N?񙙙 at4 simulateSampDist? >function(rpop=rnorm, numsamp=100, numINsamp=c(4,16), FUN=mean, * graph=c("density", "qq"), ...){ ! nDists <- length(numINsamp)+1 & funtxt <- deparse(substitute(FUN)) 2 values <- matrix(0, nrow=numsamp, ncol=nDists)  if(!is.function(rpop)) {  x <- rpop 6 rpop <- function(n)sample(x, n, replace=TRUE)  }  values[,1] <- rpop(numsamp)  for(j in 2:nDists){  n <- numINsamp[j-1] 5 for(i in 1:numsamp)values[i, j] <- FUN(rpop(n))  } K if(length(graph)==2)oldpar <- par(mfrow=c(1,2), mar=c(5.1,4.1,2.1,1.1), oma=c(0,0,1.5,0)) if(match("density", graph)){ ) popdens <- density(values[,1], ...) - avdens <- vector("list", length=nDists)  maxht <- max(popdens$y) B ## For each sample size specified in numINsamp, calculate mean @ ## (or other statistic specified by FUN) for numsamp samples  for(j in 1:nDists){  av <- values[, j] ' avdens[[j]] <- density(av, ...) * maxht <- max(maxht, avdens[[j]]$y)  }  }  if(length(graph)>0)  for(graphtype in graph){  if(graphtype=="density"){ A plot(popdens, ylim=c(0, 1.025*maxht), type="l", yaxs="i",  main="") 3 for(j in 2:nDists)lines(avdens[[j]], col=j)  legend("topleft", G legend=c("Population", paste("Sample size", numINsamp)), / col=1:nDists, lty=rep(1,nDists))  }  if(graphtype=="qq"){ # qqnorm(values[,1], main="")  for(j in 2:nDists){ 4 qqav <- qqnorm(values[, j], plot.it=FALSE) $ points(qqav, col=j, pch=j) 0 legend("topleft", legend=c("Population", = paste("Sample size", numINsamp)), * col=1:nDists, pch=1:nDists) }  }  }  if(par()$oma[3]>0){  outer <- TRUE line=0 } else  {  outer <- FALSE  line <- 1.5  }  mtext(side=3, line=line, E paste("Empirical sampling distributions of the", funtxt), " cex=1.25, outer=outer) " if(length(graph)>1)par(oldpar)  invisible(values)  } rpopo numsamp@Y numINsamp@@0 FUN mean graph density qqV   nDistskl? | deparse substitute Hhij5{ is.function  U Ta sampleUa replace  %function(n)sample(x, n, replace=TRUE) H? j@  a?? Ha5l@  mfrow?@@ffffff@ffffff@?񙙙?5 match density   popdens densityH?V  avdens vector listl  maxht maxA y?   avH V A y5 >l graphtype 5 density *?ffffff l yaxs i main @ linesP topleft Population? Sample sizeP?C?5 qq  qqnormH? @   qqavH plot.it \PO topleft Population? Sample sizeP?O?5A oma@   outer "    ?@? 'Empirical sampling distributions of the|N?5l? invisibleH travelbooks?@333333?333333@?333333?@&@*333333@4@5@9@*333333@7fffff@233333@;@<@B@7ffffff H&P _- . Guide Roadmaps/ factor0 thickness width height weight volume type/ data.frame1 Aird's Guide to Sydney Moon's Australia handbook Explore Australia Road Atlas Australian Motoring Guide Penguin Touring Atlas Canberra - The Guide