Wednesday, October 29, 2014

10 29 2014 Growth Rate with Slope and P-Value Calculations

growthratecomparison.R
require(ggplot2)
## Loading required package: ggplot2
require(scales)
## Loading required package: scales
require(plyr)
## Loading required package: plyr
require(splitstackshape)
## Loading required package: splitstackshape
## Loading required package: data.table
picsize7=read.csv('imagejsizefixed1.csv')
picsize8<-concat.split.multiple(picsize7, "Tray", " ")
mansize<-subset(picsize8, Site %in% c("Manchester","manchester"))
mansize$Date<-as.Date(mansize$Date, "%m/%d/%Y")
ggplot(mansize, aes(Date,Length.mm, group=Tray_1, color=Tray_1))+
  geom_point()+geom_smooth(method=lm)+
  scale_colour_manual(values=c("#3366CC","#CC66CC","#FF9900"))

plot of chunk unnamed-chunk-1

mods<-dlply(mansize,.(Tray_1),function(x)lm(Length.mm~Date,data=x))
slope<-function(x)coef(x)[2]
pval<-function(x)anova(x)$'Pr(>F)'[1]
s1<-ldply(mods,slope)
s2<-ldply(mods,pval)
ds_outman<-join(s1,s2)
## Joining by: Tray_1
names(ds_outman)[3]<-"pvalue"
ds_outman$slab<-sprintf('Slope:%7.5f',ds_outman$Date)
ds_outman$plab<-sprintf('p-value:%7.5f',ds_outman$pvalue)
print(ds_outman)
##   Tray_1    Date    pvalue          slab            plab
## 1     4H 0.03183 8.371e-53 Slope:0.03183 p-value:0.00000
## 2     4N 0.03443 4.414e-34 Slope:0.03443 p-value:0.00000
## 3     4S 0.03942 1.914e-77 Slope:0.03942 p-value:0.00000
mods<-dlply(oyssize,.(Tray_1),function(x)lm(Length.mm~Date,data=x))
slope<-function(x)coef(x)[2]
pval<-function(x)anova(x)$'Pr(>F)'[1]
s1<-ldply(mods,slope)
s2<-ldply(mods,pval)
ds_outoys<-join(s1,s2)
## Joining by: Tray_1
names(ds_outoys)[3]<-"pvalue"
ds_outoys$slab<-sprintf('Slope:%7.5f',ds_outoys$Date)
ds_outoys$plab<-sprintf('p-value:%7.5f',ds_outoys$pvalue)
print(ds_outoys)
##   Tray_1 Date5/1/2014    pvalue          slab            plab
## 1     1H        1.545 8.119e-68 Slope:1.54481 p-value:0.00000
## 2     1N        2.025 3.019e-92 Slope:2.02485 p-value:0.00000
## 3     1S        1.614 1.270e-27 Slope:1.61403 p-value:0.00000
mods<-dlply(fidsize,.(Tray_1),function(x)lm(Length.mm~Date,data=x))
slope<-function(x)coef(x)[2]
pval<-function(x)anova(x)$'Pr(>F)'[1]
s1<-ldply(mods,slope)
s2<-ldply(mods,pval)
ds_outfid<-join(s1,s2)
## Joining by: Tray_1
names(ds_outfid)[3]<-"pvalue"
ds_outfid$slab<-sprintf('Slope:%7.5f',ds_outfid$Date)
ds_outfid$plab<-sprintf('p-value:%7.5f',ds_outfid$pvalue)
print(ds_outfid)
##   Tray_1 Date5/2/2014     pvalue           slab            plab
## 1     2H     -0.03446 1.450e-114 Slope:-0.03446 p-value:0.00000
## 2     2N     -0.32543  5.246e-75 Slope:-0.32543 p-value:0.00000
## 3     2S      1.44133  1.861e-92  Slope:1.44133 p-value:0.00000

No comments:

Post a Comment