# 狭義遺伝率は線形回帰

• 狭義遺伝率を観測データから考えるのであれば、単純な多座位の線形回帰をして、全座位の分散の和から計算できる
• Rでやってみる
```# No. loci
n.marker <- 100
# population size
N <- 10^5
# Genotype matrix
g <- matrix(0,N,n.marker)
# allele freq of markers
f <- 0.1 + runif(n.marker) * 0.4
# HWE and random genotype generation
for(i in 1:n.marker){
g[,i] <- sample(0:2,N,replace=TRUE,prob=c(f[i]^2,2*f[i]*(1-f[i]),(1-f[i])^2))
}
# Risk of each marker's allele
r <- rnorm(n.marker)
r <- rep(1,n.marker)
# Total genetic risk when addtive model
R <- rep(0,N)
for(i in 1:n.marker){
R[which(g[,i]==1)] <- R[which(g[,i]==1)] + r[i]
R[which(g[,i]==2)] <- R[which(g[,i]==2)] + r[i]*2

}
# narrow-sense heritability
h <- 0.7
# environmental variance
eV <- (1-h)/h * var(R)
# sum of genetic and environmental risks
R. <- R + rnorm(N,0,sqrt(eV))
# phenotype is R. itself
pheno <- R.
# linear regression
lm.out <- lm(pheno~g)
# phenotype value that is expected by genetic factors only
pheno. <- lm.out\$fitted
# narrow-sense heritability
h1 <- var(pheno.)/var(pheno)
h1
```
```> h1
[1] 0.6997852
```