w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How to draw my function to plot with data in R

If you know the equation of the line that you want to draw, then just define a variable for your prediction:

predictedResponseTime <- 30 * users ^ 2
lines(users, predictedResponseTime)

If the problem is that you want to fit a line, then you need to call a modelling function.

Since loess is a non-parametric model, is isn't appropriate to use it to make predictions outside of the range of your data.

In this case, a simple (ordinary least squares) linear regression using lm provides a reasonable fit.

model <- lm(responseTime ~ users)

prediction <- data.frame(users = 1:500)
prediction$responseTime <- predict(model, prediction)
with(prediction, lines(users, responseTime))

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.