Difference between revisions of "OR1Expt.R"

From Organic Design wiki
m
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{perl}} {{#security: Sven,Goldfinger}}
+
#{{R}} {{#security: Sven,Goldfinger}}
 
# ------------------------- OR1 dataset analysis ------------------------------ #
 
# ------------------------- OR1 dataset analysis ------------------------------ #
  
Line 5: Line 5:
 
   sourceDir <- "/Volumes/HD2/Clinton/Data"
 
   sourceDir <- "/Volumes/HD2/Clinton/Data"
 
} else {
 
} else {
   sourceDir <- "C:/DATA/2007"
+
   sourceDir <- "H:\\AllRealtime\\Concentrationsexpts\\Stats"
 
}
 
}
 
filename  <- dir(sourceDir, pattern="OR1.+\.txt")
 
filename  <- dir(sourceDir, pattern="OR1.+\.txt")
  
 
# Check file path
 
# Check file path
cat("Filename is:" ,sep="\n")
+
cat("Filename is:", filename, "\n")
cat(filename, sep="\n")
+
cat("Full path is:", file.path(sourceDir, filename), "\n")
cat("Full path is:", sep="\n")
 
cat(file.path(sourceDir, filename), sep="\n")
 
  
  
Line 22: Line 20:
  
 
# ----------------------------- Dataset variables ----------------------------- #
 
# ----------------------------- Dataset variables ----------------------------- #
# Amount = 1,2,5 mu/g ingestion/injection
+
# Amount = 1,2,5 mu/g ingestion/injection (3)
# Timepoint = 1,2,3,4 days
+
# Timepoint = 1,2,3,4 days (4)
# Treatment OR1 gene/Sucrose control
+
# Treatment OR1 gene/Sucrose control (2)
# AM = Administration method; feeding or injection
+
# AM = Administration method; feeding or injection (2)
 
# Response = RE (relative expression)
 
# Response = RE (relative expression)
  
Line 54: Line 52:
  
 
# Anova example
 
# Anova example
# help(aov), help(summary)
+
# help(aov), help(summary), help(formula)
aovobj <- aov(RE ~ AM*Treatment, data=dset)
+
# Formulas
 +
# y ~ x
 +
# y ~ x * z
 +
# y ~ x/z conditional should example to y ~ x + x:z
 +
# y ~ x %in%z  is the same as y ~ x:z
 +
# see also  terms(formula(y~x/z)) etc
 +
 
 +
dset2 <- dset
 +
dset2$Amount <- factor(dset2$Amount)
 +
dset2$Timepoint <- factor(dset2$Timepoint)
 +
dset2$Treatment <- factor(dset2$Treatment)
 +
dset2$AM <- factor(dset2$AM)
 +
# Df wrong for Timepoint need to se factors
 +
aovobj <- aov(RE ~ Treatment * Timepoint, data=dset2)
 +
summary(aovobj)
 +
 
 +
aovobj <- aov(RE ~ Treatment %in% Timepoint, data=dset)
 
summary(aovobj)
 
summary(aovobj)

Latest revision as of 00:43, 6 June 2007

Code snipits and programs written in R, S or S-PLUS {{#security: Sven,Goldfinger}}

  1. ------------------------- OR1 dataset analysis ------------------------------ #

if (.Platform$OS.type == 'unix' ) {

 sourceDir <- "/Volumes/HD2/Clinton/Data"

} else {

 sourceDir <- "H:\\AllRealtime\\Concentrationsexpts\\Stats"

} filename <- dir(sourceDir, pattern="OR1.+\.txt")

  1. Check file path

cat("Filename is:", filename, "\n") cat("Full path is:", file.path(sourceDir, filename), "\n")


dset <- read.table(file.path(sourceDir, filename), sep="\t", header=TRUE)

dim(dset) summary(dset)

  1. ----------------------------- Dataset variables ----------------------------- #
  2. Amount = 1,2,5 mu/g ingestion/injection (3)
  3. Timepoint = 1,2,3,4 days (4)
  4. Treatment OR1 gene/Sucrose control (2)
  5. AM = Administration method; feeding or injection (2)
  6. Response = RE (relative expression)
  1. Took each treatment, prescribed an amount and feed/injected catapillars at
  2. time 0. Adult moths were distructively assessed 1,2,3,4 days after emergence.
  3. No catapillars were harmed during this experiment!
  4. ~.~.~ Note: Sucrose control was only administered at Amount=1 ~.~.~
  1. Convert names

colnames(dset)[4:5] <- c("AM","RE")

library(lattice)

  1. Formulas
  2. y ~ x
  3. y ~ x | z
  4. y ~ x | (z * w)
  1. help(xyplot), help(panel.superpose)

xyplot( RE ~ AM, data=dset)#, key=mykey)

  1. help(simpleKey)

mykey <- simpleKey(text=paste("Amount =",unique(dset$Amount)), space="top", columns=3) xyplot( RE ~ Timepoint| Treatment * AM, data=dset, panel.superpose=dset$Amount, groups=Amount, key=mykey)

  1. An example

xyplot( RE ~ Treatment| Timepoint , data=dset, panel.superpose=dset$Amount, groups=Amount, key=mykey, layout=c(4,1), between=list(x=0.3), aspect=1)

  1. Anova example
  2. help(aov), help(summary), help(formula)
  3. Formulas
  4. y ~ x
  5. y ~ x * z
  6. y ~ x/z conditional should example to y ~ x + x:z
  7. y ~ x %in%z is the same as y ~ x:z
  8. see also terms(formula(y~x/z)) etc

dset2 <- dset dset2$Amount <- factor(dset2$Amount) dset2$Timepoint <- factor(dset2$Timepoint) dset2$Treatment <- factor(dset2$Treatment) dset2$AM <- factor(dset2$AM)

  1. Df wrong for Timepoint need to se factors

aovobj <- aov(RE ~ Treatment * Timepoint, data=dset2) summary(aovobj)

aovobj <- aov(RE ~ Treatment %in% Timepoint, data=dset) summary(aovobj)