尝试对一种连续预测变量和一种因子预测变量进行回归。
下面的代码在使用abline时有效(但会收到以下警告消息: 在abline(models [[i]],col = labelColors [i],lty = 2:4)中: 仅使用3个回归系数中的前两个)),并为logit和loglog模型画出一串线。
如何绘制此表面或以某种方式伪造?
f<-function() {
set.seed(123)
colors<-c("red","green")
labelColors<-c("black","cyan","magenta")
x<-runif(100,0,1)
f<-round(runif(100,0,.75))
noise<-rnorm(length(x),0,.5)
y<-(1+3*x+f/2+noise)/6
plot(x,y,xlab="",ylab="")
title("test")
plot(x[f==0],y[f==0],ylim=c(0,1),col=colors[1])
points(x[f==1],y[f==1], ylim=c(0.,1.),col=colors[2])
title("test",sub="factor")
m<-lm(y~x+factor(f),na.action=na.omit)
logit<-betareg(y~x+factor(f),na.action=na.omit)
loglog<-betareg(y~x+factor(f),na.action=na.omit,link="loglog")
models<-list(m,logit,loglog)
for(i in 1:length(models)) {
if(is(models[[i]],"lm")) {
if(F) lines(x,predict(models[[i]]),col=labelColors[i],lty=2:4)
else abline(models[[i]],col=labelColors[i],lty=2:4)
}
else lines(x,predict(models[[i]]),col=labelColors[i],lty=2:4)
}
for(i in 1:length(models))
print(models[[i]])
}
f()