public
Last active

magnitude (β) & significance (p) in regression analysis

  • Download Gist
significance.R
R
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
par(col="#333333", lwd=3, pch=20, ylim=c(0,25), ylab="", xlab="",bty="n") #ylim,ylab,xlab won't run here; just reminders
 
 
#low β and confident in it
x <- runif(20,max=20)
y <- x + rnorm(20,0,.5)
plot(x,y, xlab="", ylab="", col=rgb(.1,.1,.5,.5), ylim=c(0,25), main="very confident (low p) and large response (high β)")
abline(coef(lm(y~x)), col="blue", lwd=2)
rug(x, col=rgb(.1,.1,.5)); rug(y, col=rgb(.1,.1,.5),side=2)
 
#high β and confident in it
x1 <- runif(20,max=20)
y1 <- x1/6 + rnorm(20,0,.5)
plot(x1,y1, xlab="", ylab="", col=rgb(.5,.1,.1,.5), ylim=c(0,25), main="very confident (low p) and small response (low β)")
abline(coef(lm(y1~x1)), col="red", lwd=2)
rug(x1, col=rgb(.5,.1,.1)); rug(y1, col=rgb(.5,.1,.1),side=2)
 
 
#unconfident BUT SIGNIFICANT <--- the case I'm drawing attention to
x2 <- runif(20,max=20)
y2 <- x2 + exp(rnorm(20,1,1))
plot(x2,y2, xlab="", ylab="", col=rgb(.1,.1,.1,.5), ylim=c(0,25), main="not confident (high p) BUT a LARGE response (high β)")
rug(x2, col=rgb(.1,.1,.1)); rug(y2, rgb(.1,.1,.1), side=2)
abline(a=2,b=1.5,col=rgb(1,0,0,.5))
lm(y2 ~ x2)
abline(a=3.8,b=1.1,col=rgb(1,0,0,.5))
rlm(y2 ~ x2)
abline(a=2.3,b=1.2,col=rgb(1,0,0,.5))
qplot(data = as.data.frame(cbind(x2,y2)), x = x2, y = y2, size=I(3)) + geom_smooth(col="red") + labs(x="",y="",title="not confident (high p) BUT a LARGE response (high β)") + theme_bw()
 
 
 
#the really irrelevant case: no pattern
x3 <- runif(20,max=20)
y3 <- runif(20,max=20)
plot(x3,y3, xlab="", ylab="", col=rgb(.4,.1,.5,.5), ylim=c(0,25), main="not confident (high p) and small response (low β)")
abline(coef(rlm(y3~x3)),col="purple", lwd=2)
rug(x2, col=rgb(.4,.1,.5)); rug(y2, rgb(.4,.1,.5), side=2)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.