TrevR
June 19, 2019, 1:47am
1
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) %>%
summary(lm(aDOT ~ yac_per_rec))
```

Then I'll get the error

```
> airyards %>%
+ summarise(aDOT = airyards$air_yards / airyards$tar) %>%
+ summarise(yac_per_rec = airyards$yac / airyards$rec) %>%
+ summary(lm(aDOT ~ yac_per_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)) %>%
summary(lm(aDOT ~ yac_per_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)) %>%
+ summary(lm(aDOT ~ yac_per_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 repr oducible ex ample (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

A minimal reproducible example consists of the following items:
A minimal dataset, necessary to reproduce the issue
The minimal runnable code necessary to reproduce the issue, which can be run
on the given dataset, and including the necessary information on the used packages.
Let's quickly go over each one of these with examples:
Minimal Dataset (Sample Data)
You need to provide a data frame that is small enough to be (reasonably) pasted on a post, but big enough to reproduce your issue.
Let's say, as an example, that you are working with the iris data frame
head(iris)
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> 1 5.1 3.5 1.4 0.…
EDIT: I think this example with built-in data is very close to what you are trying to do

```
library(dplyr)
library(magrittr)
iris %>%
mutate(aDOT = Sepal.Length / Sepal.Width,
yac_per_rec = Petal.Length / Petal.Width) %$%
lm(aDOT ~ yac_per_rec) %>%
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

system
Closed
July 10, 2019, 2:04am
3
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.