 # Help with linear model

So I'm trying to create a linear model between aDOT (average depth of target) and YAC/rec (yards after the catch per reception). Neither of the variables aDOT or YAC/rec are in my data frame so I was wondering how I could create a model between the two?
I tried:

``````airyards %>%
summarise(aDOT = airyards\$air_yards / airyards\$tar) %>%
summarise(yac_per_rec = airyards\$yac / airyards\$rec) %>%
``````

Then I'll get the error

``````> airyards %>%
+   summarise(aDOT = airyards\$air_yards / airyards\$tar) %>%
+   summarise(yac_per_rec = airyards\$yac / airyards\$rec) %>%
Error: Column `aDOT` must be length 1 (a summary value), not 16757
``````

So then I wasn't sure what to do so I did the sum of the variables

``````airyards %>%
summarise(aDOT = sum(airyards\$air_yards) / sum(airyards\$tar) %>%
summarise(yac_per_rec = sum(airyards\$yac) / sum(airyards\$rec)) %>%
``````

And literally nothing happened. This is all I got in the console

``````> airyards %>%
+   summarise(aDOT = sum(airyards\$air_yards) / sum(airyards\$tar) %>%
+   summarise(yac_per_rec = sum(airyards\$yac) / sum(airyards\$rec)) %>%
+
``````

I'm very new to this and I'd really appreciate any help

I think you are confusing `summarise()` with `mutate()` function, to help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

EDIT: I think this example with built-in data is very close to what you are trying to do

``````library(dplyr)
library(magrittr)

iris %>%
yac_per_rec = Petal.Length / Petal.Width) %\$%
summary()
#>
#> Call:
#> lm(formula = aDOT ~ yac_per_rec)
#>
#> Residuals:
#>      Min       1Q   Median       3Q      Max
#> -0.71340 -0.17850 -0.00652  0.15870  0.87885
#>
#> Coefficients:
#>             Estimate Std. Error t value Pr(>|t|)
#> (Intercept)  2.37802    0.05201  45.722   <2e-16 ***
#> yac_per_rec -0.09844    0.01046  -9.414   <2e-16 ***
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#>
#> Residual standard error: 0.3178 on 148 degrees of freedom
#> Multiple R-squared:  0.3745, Adjusted R-squared:  0.3703
#> F-statistic: 88.62 on 1 and 148 DF,  p-value: < 2.2e-16
``````
1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.