title: How to run piecewise linear regression for multiple different responses and predictors, where responses start at different times?
body: <p>My data frame looks like this</p>
  <pre><code>df = structure(list(Date_Time_GMT_3 = structure(c(1622552400, 1622552400, 
                                                    1622552400, 1622552400, 1622552400, 1622552400, 1622552400, 1622552400, 
                                                    1622553300, 1622553300, 1622553300, 1622553300, 1622553300, 1622553300, 
                                                    1622553300, 1622553300, 1622554200, 1622554200, 1622554200, 1622554200
  ), tzone = &quot;EST&quot;, class = c(&quot;POSIXct&quot;, &quot;POSIXt&quot;)), response = c(&quot;20817727_F8AR_U&quot;, 
                                                                  &quot;20817727_F8AR_U&quot;, &quot;20817727_F8AR_U&quot;, &quot;20817727_F8AR_U&quot;, &quot;20819742_X1AR_U&quot;, 
                                                                  &quot;20819742_X1AR_U&quot;, &quot;20819742_X1AR_U&quot;, &quot;20819742_X1AR_U&quot;, &quot;20817727_F8AR_U&quot;, 
                                                                  &quot;20817727_F8AR_U&quot;, &quot;20817727_F8AR_U&quot;, &quot;20817727_F8AR_U&quot;, &quot;20819742_X1AR_U&quot;, 
                                                                  &quot;20819742_X1AR_U&quot;, &quot;20819742_X1AR_U&quot;, &quot;20819742_X1AR_U&quot;, &quot;20817727_F8AR_U&quot;, 
                                                                  &quot;20817727_F8AR_U&quot;, &quot;20817727_F8AR_U&quot;, &quot;20817727_F8AR_U&quot;), 
  y = c(NA_real_, 14.421, 14.421, 14.421, 14.996, 14.996, 14.996, 14.996, 14.421, 14.421, 14.421, 14.421, NA_real_, NA_real_, 14.996, 14.996, NA_real_, 
        NA_real_, 14.421, 14.421), predictor = c(&quot;20819830_R1AR_U_Stationary&quot;, &quot;20822215_R3AR_U_Stationary&quot;, &quot;20874235_R4AR_U_Stationary&quot;, &quot;20874311_F1AR_U_Stationary&quot;,
                                                 &quot;20819830_R1AR_U_Stationary&quot;, &quot;20822215_R3AR_U_Stationary&quot;, &quot;20874235_R4AR_U_Stationary&quot;, &quot;20874311_F1AR_U_Stationary&quot;, 
                                                 &quot;20819830_R1AR_U_Stationary&quot;, &quot;20822215_R3AR_U_Stationary&quot;,  &quot;20874235_R4AR_U_Stationary&quot;, &quot;20874311_F1AR_U_Stationary&quot;, 
                                                 &quot;20819830_R1AR_U_Stationary&quot;,  &quot;20822215_R3AR_U_Stationary&quot;, &quot;20874235_R4AR_U_Stationary&quot;, &quot;20874311_F1AR_U_Stationary&quot;, 
                                                 &quot;20819830_R1AR_U_Stationary&quot;, &quot;20822215_R3AR_U_Stationary&quot;, &quot;20874235_R4AR_U_Stationary&quot;, &quot;20874311_F1AR_U_Stationary&quot;), 
  x = c(16.903, 13.942, 14.23, 15.282,  16.903, 13.942, 14.23, 15.282, 16.808, 13.942, 14.23, 15.187,  16.808, 13.942, 14.23, 15.187, 16.808, 13.942, 14.134, 15.187)), 
  class = c(&quot;grouped_df&quot;, &quot;tbl_df&quot;, &quot;tbl&quot;, &quot;data.frame&quot;), row.names = c(NA,  -20L), groups = structure(list(response = c(&quot;20817727_F8AR_U&quot;, &quot;20817727_F8AR_U&quot;, &quot;20817727_F8AR_U&quot;, 
                                                                                                                         &quot;20817727_F8AR_U&quot;, &quot;20819742_X1AR_U&quot;, &quot;20819742_X1AR_U&quot;, &quot;20819742_X1AR_U&quot;, &quot;20819742_X1AR_U&quot;), 
                                                                                                            predictor = c(&quot;20819830_R1AR_U_Stationary&quot;,  &quot;20822215_R3AR_U_Stationary&quot;, &quot;20874235_R4AR_U_Stationary&quot;, 
                                                                                                                          &quot;20874311_F1AR_U_Stationary&quot;, &quot;20819830_R1AR_U_Stationary&quot;, &quot;20822215_R3AR_U_Stationary&quot;, 
                                                                                                                          &quot;20874235_R4AR_U_Stationary&quot;, &quot;20874311_F1AR_U_Stationary&quot;), 
                                                                                                            .rows = structure(list(c(1L, 9L,  17L), c(2L, 10L, 18L), c(3L, 11L, 19L), c(4L, 12L, 20L), 
                                                                                                                                   c(5L, 13L), c(6L, 14L), c(7L, 15L), c(8L, 16L)), 
                                                                                                                              ptype = integer(0), class = c(&quot;vctrs_list_of&quot;, &quot;vctrs_vctr&quot;, &quot;list&quot;))), 
                                                                                                       class = c(&quot;tbl_df&quot;, &quot;tbl&quot;, &quot;data.frame&quot;), row.names = c(NA, -8L), .drop = TRUE))
  </code></pre>
  <p>I want to run all the different combinations of predictors against response to get an output that will tell me the R squared value of piecewise regression model between each group of response and predictor. I tried using this code</p>
  <pre><code>#create the linear regression model with above out put
  df = lm(y~x, data = results)
  
  
  
  segmented.fit &lt;- segmented(df, seg.Z = ~x)
  summary(segmented.fit)
  </code></pre>
  <p>but it only gives me 1 R squared value for the entire dataframe, instead of grouping by each response and predictor.</p>
  <p>Any idea how to group the response and predictors before I run the model?</p>