Skip to content

Instantly share code, notes, and snippets.

@Oreotrephes
Last active August 29, 2015 14:10
Show Gist options
  • Select an option

  • Save Oreotrephes/578ff38669a579ced2cb to your computer and use it in GitHub Desktop.

Select an option

Save Oreotrephes/578ff38669a579ced2cb to your computer and use it in GitHub Desktop.
At-a-glance coefficient table
#looks familiar
summaryfunction2<-function(x,y){
signs<-substr(as.character(sign(x)),1,1)
signs[signs=="1"]<-"+"
significance<-cut(abs(y), c(0, 0.001, 0.01, 0.05, Inf), labels=c("***", "**", "*", ""), right=FALSE)
paste(signs, significance)
}
#use that function in a function
process<-function(lm){
coef<-data.frame(summary(lm)$coefficients)[-1,-c(2,3)]
coef$comb<-summaryfunction2(coef$Estimate,coef$Pr...t..)
vec<-t(coef[3])
vec<-data.frame(vec)
vec$dependent<-as.character(lm$terms[[2]])
vec
}
lm1<-lm(Sepal.Length~Petal.Length+Petal.Width,data=iris)
lm2<-lm(Sepal.Width~Petal.Length,data=iris)
lm3<-lm(Petal.Length~Sepal.Width+I(Sepal.Width^2),data=iris)
a<-process(lm1)
b<-process(lm2)
full<-merge(a,b,all=T,sort=F) #ugly recursive step
b<-process(lm3)
full<-merge(full,b,all=T,sort=F) #ugly recursive step again
#(etc.)
full
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment