#read data
data=read.csv("edited_life_history_data.csv")
head(data)
life.history <- read.csv("edited_life_history_data.csv")
dose <- factor(c("1 Gy", "2 Gy", "4 Gy", "5.5 Gy", "Sham"))
dose <- relevel(dose, "Sham")
head(life.history)
colnames(life.history)[1]="Group"
life.history$dose = relevel(life.history$Group,"Sham")
lh <- data.frame(life.history$Average.Egg.Size..LxW.,
life.history$Early.Life.Hatching.Success....hatched., life.history$Early.Life.Hatchling.vigor..days.survived. without.food.,
life.history$Total.Reproductive.Rate)
log.lh <- log(lh)
lh.dose <- life.history[, "Group"]
lh.pca <-prcomp(na.omit(log.lh,
center =TRUE,
scale. =TRUE))
summary(lh.pca)
Importance of components:
PC1 PC2 PC3 PC4
Standard deviation 0.7780 0.25380 0.19543 0.11532
Proportion of Variance 0.8393 0.08932 0.05296 0.01844
Cumulative Proportion 0.8393 0.92860 0.98156 1.00000
plot(lh.pca, type ="l")
predict(lh.pca,
newdata =tail(na.omit(log.lh,2)))
PC1 PC2 PC3 PC4
450 -0.4271374 0.32820602 -0.36821424 0.003225707
458 -2.2396492 -0.45685837 -0.15879184 0.195294075
466 -0.3954699 0.17690207 0.11668851 -0.061863425
475 -0.9588797 -0.02340739 0.07678242 -0.186083713
484 -0.9275021 -0.32335662 0.26334138 -0.183940408
493 -1.5313185 0.46210774 -0.41899155 -0.045873086
biplot(lh.pca)
画出一个类似于下图的图,横坐标是response variable,纵坐标是Principal Com ponent。
pp=prcomp(na.omit(log.lh))
x=lh.dose[as.numeric(names(predict(lh.pca,
newdata =na.omit(log.lh,2) )[,1]))]
y=predict(lh.pca,
newdata =na.omit(log.lh,2) )[,1]
data=data.frame(x,y)
aggregate(y ~x, data = data, mean)
x y
1 1 Gy 0.46637350
2 2 Gy 0.63214810
3 4 Gy -0.05234262
4 5.
5 Gy -0.92889378
5 Sham 0.35652766
aggregate(y ~x, data = data, sd)
x y
1 1 Gy 0.2975531
2 2 Gy 0.3364273
3 4 Gy 0.5905769
4 5.
5 Gy 0.6876904
5 Sham 0.4407832
require(plotrix)
Loading required package: plotrix plotCI(1:5, F, ui=U, li=L,xaxt="n") abline(h=0)
axis(1, 1:5, levels(x))
lines(1:5,F)