模型Ⅱ回归适用于在回归方程中两个变量都是随机时,即不由研究人员控制时,应使用该回归,其具体包括:ordinaryleast squares (OLS), major axis(MA), standard major axis (SMA), and ranged major axis (RMA),我们这里说的RMA实为SMA。
r <- cor(height,weight)
n <- length(height)
r*sqrt((n-2)/(1-r^2))
# 数值上等于下面的t值
cor.test(height,weight)
> r <- cor(height,weight)
> n <- length(height)
> r*sqrt((n-2)/(1-r^2))
[1] 7.203034
>
> cor.test(height,weight)
Pearson's product-moment correlation
data: height and weight
t = 7.203, df = 62, p-value = 9.567e-10
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
0.5145285 0.7897492
sample estimates:
cor
0.6749703
https://wap.sciencenet.cn/home.php?mod=space&do=blog&id=1063689
# MAR反应两者关系
attach(pdt)
y=height
x=sitting.height
d <- var(y)-var(x)
b=(d+sqrt(d^2+4*cov(x,y)^2))/(2*cov(x,y))
a=mean(y)-b*mean(x)
lm(y~x)
# install.packages('smatr')
library(smatr)
sma(y~x,method='MA')
plot(x,y)
plot(x,y,pch=16)
abline(lm(y~x))
abline(sma(y~x,method='MA'),col='red',lty=2)
attach(plants)
lm(weight~height)
# weight=height*1.078-122
range(height)
summary(lm(weight~height))
summary(lm(weight~I(height^3)))
# 非线性关系
mdt <- read.csv('E:/mistletoe.csv')
attach(mdt)
par(mfrow=c(2,2))
plot(age,mistletoe,pch=16)
summary(lm(mistletoe~age))
abline(lm(mistletoe~age))
plot(log(age),mistletoe,pch=16)
summary(lm(mistletoe~log(age)))
# 半致死量,概率累积致死率不取得1
ldt <- read.csv('E:/LD50.csv')
attach(ldt)
plot(dose,deathrate,pch=16)
abline(lm(deathrate~dose))
summary(lm(deathrate~dose))
lm50 <- lm(deathrate~dose)
a <- lm50$coefficeients[1]
b <- lm50$coefficeients[2]
(100-a)/b