Skip to content

Instantly share code, notes, and snippets.

@isomorphisms
Last active December 11, 2015 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save isomorphisms/4632691 to your computer and use it in GitHub Desktop.
Save isomorphisms/4632691 to your computer and use it in GitHub Desktop.
magnitude (β) & significance (p) in regression analysis
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment