dataframe - Extract R^2 from lm summary into data.frame -


i have large data set of genetic , environmental variables using linear regression on. need obtain r.squared, adj.r.squared, , p-value. have no problem running regression portions , can summary of each regression. have approximately 20,000 models need compare , extracting each value individual seems tedious. imagine there has relatively straight forward way accomplish this.

here code extracting values data.frame (b1 stored summary of first model):

df=data.frame(r.squared=numeric(),adj.r.squared=numeric(),fstatvalue=numeric(),fstatnumdf=numeric(),fstatdendf=numeric()) for(i in 1:10) { df[iter,]=c(b1$r.squared, b1$adj.r.squared, b1$fstatistic) } 

this code creates data.frame , extracts data same model (b1) 10 times. have tried several ways try model identifier change each iteration no luck. have suggestion?

like @roland says, objects list first, easy. assuming have ~20,000 objects in workspace (!!!) called e.g. b1, b2 ,...b20000, can stick them in list, extract summary stats , return data.frame this:

# stick objects in list x <- mget( ls( pattern = "^b[0-9]+$" ) )  # extract summary statistics out <- lapply( x , function(x) c(x$r.squared, x$adj.r.squared, x$fstatistic) )  # turn data.frame as.data.frame( out ) 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

inno setup - TLabel or TNewStaticText - change .Font.Style on Focus like Cursor changes with .Cursor -