0

I have a some data and I draw them on a plot, using R. After that, I draw the loess function about that data. Here is the code:

data <- read.table("D:/data.csv", header=TRUE, sep=",", na.strings="NA", dec=".", strip.white=TRUE)
ur <- subset(data, select = c(users,responseTime))
ur <- ur[with(ur, order(users, responseTime)), ]

plot(ur, xlab="Users", ylab="Response Time (ms)")
lines(ur)
loess_fit <- loess(responseTime ~ users, ur)
lines(ur$users, predict(loess_fit), col = "blue")

Here's my plot's image: http://tinypic.com/r/2ziqa2x/8

How can I get the function of this regression? For example: responseTime = 68 + 45 * users.

Thanks.

Karsten W.
  • 17,826
  • 11
  • 69
  • 103
Abraham
  • 5
  • 8
  • 4
    There is no simple "loess function". It's a local piecewise fit. If you use `loess` you are implicitly saying "I don't have any theory about the form of the result". – IRTFM Mar 16 '14 at 21:42
  • What I want, is to create a function that I could predict the responseTime when i know how many users I have. Maybe it is wrong to use loess, but it looks like fitting to my data. – Abraham Mar 16 '14 at 21:52
  • Well `loess` is fitting to data, but maybe what you want is a polynomial or spline fit? – IRTFM Mar 16 '14 at 22:02
  • Do you know how can R help me to create that function, to predict the response time? – Abraham Mar 16 '14 at 22:08

2 Answers2

1

You can use the loess_fit object from your code to predict the response time. If you want to estimate the average response time for 230 users, you could do:

predict(loess_fit, newdata=data.frame(users=230))

Here is an interesting blog post on this subject.

EDIT: If you want to make predictions for values outside your data, you need a theory or further assumptions. The most simple assumption would be a linear fit,

lm_fit <- lm(responseTime ~ users, data=ur)
predict(lm_fit, newdata=data.frame(users=400))

However, your data may show heteroscedacity (non-constant variance) and may show non-normal residuals. You might want to check if that is the case. If it is, then a robust linear fitting procedure such as rlm from the package MASS, or a generalized linear model glm might be worth a try. I am not an expert for that, maybe someone else or at Cross Validated can provide better help.

Community
  • 1
  • 1
Karsten W.
  • 17,826
  • 11
  • 69
  • 103
  • Thank you for the answer. This work for users until 250 that I have data. If I want more? for example 400 users. – Abraham Mar 16 '14 at 22:57
0

The loess.demo function in the TeachingDemos package shows the logic underlying the loess fit. This can help you understand what is going on and why there is not a simple prediction function. However, for predicting, there is a predict function that works with loess fits to create the prediction. You can also find the linear equation that will predict for a specific value of x (but it will be different for each value of x you may want to predict for).

Greg Snow
  • 48,497
  • 6
  • 83
  • 110