R Gurus,
I have the following data frame (Df) that establishes the relationship between the X and Y variables:
X Y
1 25 2457524
2 25 2391693
3 25 2450828
4 25 2391252
5 25 2444638
6 25 2360293
7 50 4693194
8 50 4844527
9 50 4835596
10 50 4878092
11 50 4809226
12 50 4722253
13 75 7142763
14 75 7182769
15 75 7135550
16 75 7173920
17 75 7216871
18 75 7076359
19 100 9496553
20 100 9537788
21 100 9405825
22 100 9439201
23 100 9609870
24 100 9707734
25 125 12031958
26 125 12027037
27 125 11935594
28 125 11930086
29 125 12154132
30 125 12096462
31 150 14298064
32 150 14396607
33 150 13964716
34 150 14221039
35 150 14283992
36 150 14042220
(Note that we have 7 levels for variable X with 6 points on each level)
If we fit a 2nd degree polynomial model for this data, we will obtain the following model:
Model<-lm(formula = Y ~ X + I(X^2))
print(Model)
Call:
lm(formula = Y ~ X + I(X^2))
Coefficients:
(Intercept) X I(X^2)
-26588.12 97310.61 -14.02
The graphic representation of this model, which looks more like a straight line, is as follows:
Ifwewanttousethemodeltopredictthevaluesof"Y" from the values of the "X" variable, just execute this line of code:
>predicted.intervals <- predict(Model,data.frame(x=X),interval='confidence',
+ level=0.95)
>predicted.intervals
fit lwr upr
1 2397413 2315346 2479481
2 2397413 2315346 2479481
3 2397413 2315346 2479481
4 2397413 2315346 2479481
5 2397413 2315346 2479481
6 2397413 2315346 2479481
7 4803887 4753705 4854070
8 4803887 4753705 4854070
9 4803887 4753705 4854070
10 4803887 4753705 4854070
11 4803887 4753705 4854070
12 4803887 4753705 4854070
13 7192834 7137649 7248019
14 7192834 7137649 7248019
15 7192834 7137649 7248019
16 7192834 7137649 7248019
17 7192834 7137649 7248019
18 7192834 7137649 7248019
19 9564252 9509067 9619438
20 9564252 9509067 9619438
21 9564252 9509067 9619438
22 9564252 9509067 9619438
23 9564252 9509067 9619438
24 9564252 9509067 9619438
25 11918144 11867961 11968326
26 11918144 11867961 11968326
27 11918144 11867961 11968326
28 11918144 11867961 11968326
29 11918144 11867961 11968326
30 11918144 11867961 11968326
31 14254507 14172440 14336574
32 14254507 14172440 14336574
33 14254507 14172440 14336574
34 14254507 14172440 14336574
35 14254507 14172440 14336574
36 14254507 14172440 14336574
The question you do not want to shut up:
What would be the line (s) of code to do the inverse prediction, ie in this model, predict "X" from the data of variable "Y"? Searching in google already tried several packages and specific functions but unfortunately I did not succeed (perhaps for lack of familiarity with the functions). Could any of you help me unravel this mystery? Big hug to all.