- ここのところ、James-Stein推定とか、Shrinkageとか、スプラインとかをいじっていて(こちら)、それらの根は同じなのだが、たとえば、ggplot2の回帰曲線なんかも同じ枠組みらしい
- Local (polynomial) regressionで、その中で、「近傍」をk-nearest neighborで採用するなどしているらしい
- 実験
- 多人数、多観測マーカー
- 観測値はマーカーごとに特性が異なるけれど、年齢影響を受ける
- 表示
- 個人ごとに、観測値の高低でソートしなおして、プロット
- ggplot2の使い方の参考サイト(こちら)
- 回帰曲線の引き方に関する参考サイトはこちらやこちら
library(ggplot2)
n <- 300
age <- runif(n)
n.gene <- 1000
X <- matrix(0,n,n.gene)
for(i in 1:n.gene){
X[,i] <- (rnorm(1)+runif(1)*4)*3*(age+3)^2 + rnorm(n,runif(1),
runif(1)*300)*age
もある
}
X.sorted <- t(apply(X,1,sort))
n.qs <- 30
qs <- round(seq(from=1,to=n.gene,length=n.qs))
matplot(age,X.sorted[,qs],type="p",cex=1,pch=20)
mydat <-data.frame(age = rep(age,n.qs),gs=c((X.sorted[,qs])),qs=rep(qs,
each=n))
r <- ggplot(data = mydat, aes(x = age, y = gs, color = qs, group = qs))
r + geom_smooth()
- 同じサンプルセットに2つの観察があったら、その2つが作る2曲線を比べたくなる
n.f <- 100
n.m <- 100
age.f <- rnorm(n.f,0.7,2)
age.m <- rnorm(n.m,0.7,3)
k.f <- runif(1)
k.m <- runif(1)
g.f <- age.f*k.m + apply(matrix(mean(age.f)-age.f,ncol=1),1,max,0)*k.f+rnorm(n.f)
g.m <- age.m*k.m + rnorm(n.m)
mydat <- data.frame(age=c(age.f,age.m),sex=c(rep(1,n.f),rep(2,n.m)),g=c(g.f,g.m))
r <- ggplot(data = mydat, aes(x = age, y = g, color = sex, group = sex))
r + geom_smooth()
g.f.2 <- age.f*k.m + apply(matrix(mean(age.f)-age.f,ncol=1),1,max,0)*k.f+rnorm(n.f)
g.m.2 <- age.m*k.m + rnorm(n.m)
mydat <- data.frame(age=c(age.f,age.m,age.f,age.m),sex=c(c(rep(1,n.f),rep(2,n.m)),c(rep(3,n.f),rep(4,n.m))),g=c(g.f,g.m,g.f.2,g.m.2))
r.2 <- ggplot(data = mydat, aes(x = age, y = g, color = sex, group = sex))
r.2 + geom_smooth()
mydat <- data.frame(age=c(age.f,age.f),gene=c(rep(1,n.f),rep(2,n.f)),g=c(g.f,g.f.2))
r.3 <- ggplot(data = mydat, aes(x = age, y = g, color = gene, group = gene))
r.3 + geom_smooth()