Load packages

Make sure you have installed these first

Input your data

Here we will create two vectors with our data (note ours is noisy so I’ve changed it a bit to make it easier to start with):

We have created two vectors and merged them in a data frame called “df”:

load<-c(50, 80, 100, 130)
velocity<-c(1.5, 1.23,1.00, 0.75)

df = data.frame(load,velocity)

If a linear prediction is going to work then the data needs to have a strong linear relationship - we can test this through a basic Pearson’s correlation and a plot - if r is close to 1 then the prediction should work well:

cor.test(velocity,load,  method = "pearson")
## 
##  Pearson's product-moment correlation
## 
## data:  velocity and load
## t = -25.417, df = 2, p-value = 0.001544
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.9999693 -0.9250268
## sample estimates:
##        cor 
## -0.9984556

So here we have an r value of -0.998 with CI from -.93 to -1.0 - therefore a strong linear relationship, which we can plot:

ggscatter(df, x = "velocity", y = "load")+
  geom_smooth(method= lm)
## `geom_smooth()` using formula = 'y ~ x'

So this is great but we want to use this plot what the load will be at our minimal velocity threshold e.g., 0.3 m /s: so we can use the following code to do this, and we get a predicted 1RM of 176 kg. Here we run a linear model using the code lm() . We then use predict to make a prediction using this model:

model <- lm(load ~ velocity, data = df)
prediction <- predict(model, data.frame(velocity = 0.3))
prediction
##        1 
## 176.0494

Lets plot this. Here I have added some more to the graph above geom_point is adding a point at 0.3 m/s on the x-axis and at 176 on the y (prediction) we’ve made it red and change the color as well as adding some text to indicate 1 RM.

NOTE: this graph did not work the first time as the point was being plotted “off the graph” so I’ve set the y axis to run from zero to the maximum load + 60 kg using xlim.

ggscatter(df, x = "velocity", y = "load")+
  geom_smooth(method= lm) +
  geom_point(x = 0.3, y = prediction, color = "red", size = 2) +
  geom_text(x = 0.3, y = prediction, label = paste("Predicted 1RM:", round(prediction, 0)), hjust = 1, vjust = 3)+
  xlim(0, max(df$velocity)) +
  ylim(0, max(df$load) + 60)
## `geom_smooth()` using formula = 'y ~ x'

Great but how accurate is this? We might want to compute confidence intervals around our prediction:

prediction <- predict(model, data.frame(velocity = 0.3), interval = "confidence", level = 0.95)
prediction
##        fit      lwr      upr
## 1 176.0494 160.6715 191.4273

So now we know the predicted 1RM could be between 160 and 191 (that’s a fair bit of error isn’t it!) - we might want a couple more data points here and some of these data points closer to our 1RM velocity, maybe at 0.6 m/s?

We can plot the 95% CI as error bars but need to turn prediction into a data frame first. We also need to increase the upper limit on the y-axis so the upper CI will fit so I’ve changed ylim to +80, I also changed vjust here to 4 to drop the text down below the error bar:

prediction_data <- data.frame(x = 0.3, y = prediction[1], ymin = prediction[2], ymax = prediction[3])

ggscatter(df, x = "velocity", y = "load") +
  geom_smooth(method = lm) +
  geom_point(x = 0.3, y = prediction[1], color = "red", size = 2) +
  geom_text(x = 0.3, y = prediction[1], label = paste("Predicted 1RM:", round(prediction[1], 0)), hjust = 1, vjust = 4) +
  geom_errorbar(data = prediction_data, aes(x, y, ymin = ymin, ymax = ymax), color = "red") +
  xlim(0, max(df$velocity)) +
  ylim(0, max(df$load) + 80)
## `geom_smooth()` using formula = 'y ~ x'