Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. require(msm) #used for truncated normal distribution "rtnorm()"
  2. require(viopoints) #used for viopoints plot"
  3.  
  4.  
  5. # Group Names
  6. groups=c("F1.acetophenone","F1.propanol")
  7.  
  8. # Treatment Names
  9. treatments=c("acetophenone","propanol")
  10.  
  11. # Days experiments were run
  12. days=c(1,2)
  13.  
  14. # Sample size (both groups)
  15. n=12
  16.  
  17. # Mean of baseline "startle" amount (Day 1, no scent, "leader trial")
  18. startle.baseline=10
  19.  
  20. # SD of baseline "startle" amount
  21. startle.sd=1.5
  22.  
  23. # Habituation effect (Add to startle.baseline if day= 2)
  24. day.effect=-5
  25.  
  26. # Scent effect (Add to startle.baseline for trials including scent)
  27. scent.effect=2
  28.  
  29.  
  30. out=NULL
  31. # Cycle through Days
  32. for(d in days){
  33. # Cycle through Groups
  34. for(g in groups){
  35.  
  36. # "Counterbalanced design"
  37. #On day 1: Group 1 <-treatment 2; Group 2 <-treatment 1
  38. #On day 2: Group 1 <-treatment 1; Group 2 <-treatment 2
  39. if(d==1 & g==groups[1]){treatment=treatments[2]}
  40. if(d==1 & g==groups[2]){treatment=treatments[1]}
  41. if(d==2 & g==groups[1]){treatment=treatments[1]}
  42. if(d==2 & g==groups[2]){treatment=treatments[2]}
  43.  
  44. # If day 1 add zero to baseline mean, if day 2 then add day effect
  45. if(d==1){adj=0}
  46. if(d==2){adj=day.effect}
  47.  
  48. # Simulate "leader" results (no scent)
  49. leader<-rtnorm(n,startle.baseline+adj,startle.sd, lower=0)
  50.  
  51. # Simulate "test" results (with scent)
  52. test<-rtnorm(n,startle.baseline+adj+scent.effect,startle.sd, lower=0)
  53.  
  54. # Calculate "OPS.scores" using normalization strategy described in paper
  55. OPS.scores<-100*(test-leader)/leader
  56.  
  57. out<-rbind(out,cbind(d,treatment,g,OPS.scores))
  58. }
  59. }
  60.  
  61. # Format output
  62. out=as.data.frame(out, stringsAsFactors = F)
  63. out[,4]<-as.numeric(out[,4])
  64.  
  65.  
  66. # Plot by treatment and Group
  67. par(mfrow=c(1,2))
  68. for(j in 1:length(treatments)){
  69. sub<-out[which(out[,2]==treatments[j]),]
  70. viopoints(sub[,4]~sub[,3], pch=c(15,16), col="Black",
  71. ylim=c(min(out[,4]),max(out[,4])),
  72. ylab=paste("Percentage OPS to", treatments[j]))
  73. boxplot(sub[,4]~sub[,3], add=T, outline=F)
  74. abline(h=0, lty=3)
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement