r - Create regression coefficient table -


There are a total of 46 retrograde models for which I want to summarize into a data table. Here is a dummy example that I have made to explain my method.

  # dummy data data 1 & lt; - data.frame (flow = c (8,8.5,6,7.1,9), SP_elev = c (20, 11, 5, 25, 50)) data 2 & lt; - data.frame (flow = c (7, 7, 6, 6, 8, 8, 8, 8), SP_elev = c (13,15,18,25,19)) data 3 and lt; - Data.frame (flow = c (2,3,5,7,9), SP_elev = c (20,25,28,30,35)) data 4 & lt; - Data.frame (flow = c) (1,4,6,8,9), SP_elev = c (13,15,18,25,19)) data 5 & lt; - Data.frame (flow = c (1,4,6,8,9), SP_elev = c (13,15,18,25,19)) data 6 & lt; - data.frame (flow = c (1,4,6,8,9), SP_elev = c (22, 23, 25, 27, 2) # desired column name tmp and lt; - data.fr (matrix (enero = 0, NXL = 9)) Name (TMP) & lt; -c ("site_name", "int", "coffin #Create vector list dataframe = list (" data1 "= data1," data2 "= data 2, "Data 3" = "1", "Data 3" = "", "Data2" Data3, "Data4" = Data 4, "Data 5" = Data 5, "Data 6" = Data 6) For # data in the datafire) #Plot {#Create regression model fit2 & lt; -lm (SP_elev ~ flow + I (flow ^ 2), data = i) with regression model for L2 and Lt; - Function (x) Fit 2 coefficient [3] * x ^ 2 + fit 2 coefficient [2] * x + fit 2 coefficient [1] # Make variables for each coefficient site site_name & lt ; - i int & lt; - signif (summary (fit 2) $ coefficient [1], 4) coffin end lie; - signf (summary (fit 2) $ multiplier [2], 4) coffsdd & lt; - signf ( Summary (Fit 2) $ multiplier [3], 4) & lt; - signif (summary2) $ fstatistic, 4) ldf & lt; signif (summary2) $ fstatistic [2], 2) udf & lt ; - signif (summary (fit2) $ fstatistic [3], 2) cod and lieutenant; - sign (summary (Fit 2) $ xdscoreword, 3) pival & lieutenant; -  

{0} Input Dummy Data

  • Create empty data frames
  • List of dummy data created vector
  • Run for loop to perform regression analysis on each data set Format the data related to additional data related to an data frame tmp

    b. Data frame tmp (I line per dummy data set)

    As above can be seen, I do not know about adding variables in the data frame tmp .

    If you change your loop in the form of a counter form instead of the actual data frame objects, then It becomes very straightforward:

      tmp <- data.frame (matrix (nro = length of dataframe, niacal = 9)) name (tmp) & lt; -c ( "site_name", "int", "coflin", "cofsqd", "f stat "," ldf "," udf "," code "," pval ") (seq_along (dataframes) in j) {i & lt; - Data Frame [[J]] # The rest of your code goes here. Down & lt; - c (name (dataframe) [[j]], int, coflin, ..., code, pval] tmp [j,]   

    Note that you can not use i as an ID of data frame, but you can use the same name Also, we started the result data frame for the correct size in the number of rows.

    One thing is that modifying data frames is slow, so you usually do not want to do this as long as your loop is not repeated multiple times. If this happens, then a simple solution first uses a matrix, and after looping it is converted to the data frame.

  • Comments

    Popular posts from this blog

    Verilog Error: output or inout port "Q" must be connected to a structural net expression -

    jasper reports - How to center align barcode using jasperreports and barcode4j -

    c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -