6
$\begingroup$

Below is my code with sample data as in screen shot ; in that i got response for only 21 to 33. My requirement is to get response for 34, 35 , 36, 37

Sample Data

enter image description here

Below is R code

linearCurve<-lm(Month ~ Value, data = data) CurveResponse<-cbind(predict(linearCurve,type="response"))

$\endgroup$
2
  • 1
    $\begingroup$ Where is your Month variable in the sample data? $\endgroup$ May 29, 2015 at 11:00
  • $\begingroup$ First column is "Month" i.e. 21 to 33 and Second column is "Value" i.e. 6591.35 to 8575.81 $\endgroup$
    – Sajal Goel
    May 29, 2015 at 12:24

1 Answer 1

7
$\begingroup$

You can do this in R using the predict function. For ease I used Month as predictor and Value as outcome. In the vector new are the predicted values as a function of Month. Please see also the plot that shows the projected values on the regression line.

data=data.frame(Month=c(21:33), Value=c(6591.69, 6579.62, 7133.84, 6955.89, 7573.27, 7556.87, 7751.17, 8001.76, 8399.5, 8560.36, 8517.53, 8602.57, 8575.81))

attach(data)

fit1<-lm(Value~Month, data=data)

new<-predict(fit1, data.frame(Month=(c(34,35,36))))

plot(Value~Month, data, col="red", xlim=c(20,36), ylim=c(6000,10000))
abline(fit1, col="orange", lwd=2)
abline(v=c(34,35,36), lty=6)
points(34, new[1], col="blue")
points(35, new[2], col="blue")
points(36, new[3], col="blue")

enter image description here

$\endgroup$
1
  • $\begingroup$ Hi thanks for the solution , it's work for me. but i need dynamic variable in that. Below code doesn't work for me , i don't know why ? [code] data = read.csv("c:/curve.csv", header=TRUE) attach(data) fit1<-lm(data[,2]~data[,1], data=data) predict(fit1, data.frame(MONTH_=(c(34,35,36,37)))) [/code] $\endgroup$
    – Sajal Goel
    May 30, 2015 at 7:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.