Syntax error How to find the point estimate using regression model in R?

How to find the point estimate using regression model in R?



To find the point estimate using regression model in R, we can follow the below steps −

  • First of all, create a data frame.
  • Then, create the regression model.
  • After that, define the value for which we want to find the point estimate and use predict function to find the estimate.

Create the data frame

Let's create a data frame as shown below −

 Live Demo

x1<-rnorm(20)
y1<-rnorm(20)
df<-data.frame(x1,y1)
df

On executing, the above script generates the below output(this output will vary on your system due to randomization) −

      x1          y1
1 0.53233256 -0.17433578
2 0.53362706 1.73778811
3 1.21038775 -1.02142344
4 -1.50504650 0.01770948
5 -0.55570505 0.91796585
6 1.01597916 0.88380869
7 0.21911440 1.34088517
8 1.21258700 1.14469629
9 -0.98170554 -1.04790911
10 -0.67748759 -1.16909492
11 0.00801995 -0.35320938
12 -1.04972030 1.35817346
13 -1.35385333 0.87222670
14 1.09276537 0.70046753
15 0.10064662 0.27685523
16 0.12231502 -0.26659197
17 0.83791912 -0.80416436
18 1.56681559 0.43084296
19 -1.13942633 1.19649376
20 0.84196501 0.28244014

Create the regression model

Using lm function to create the regression model between x1 and y1 −

 Live Demo

x1<-rnorm(20)
y1<-rnorm(20)
df<-data.frame(x1,y1)
Model<-lm(y1~x1)
Model

Output

Call:
lm(formula = y1 ~ x1)
Coefficients:
(Intercept)    x1
0.317061    -0.008665

Find the point estimate

Using predict function to find the point estimate of y1 when x1 is 1.08 −

 Live Demo

x1<-rnorm(20)
y1<-rnorm(20)
df<-data.frame(x1,y1)
Model<-lm(y1~x1)
new_data<-data.frame(x1=0.08)
predict(Model,new_data)

Output

   1
0.3163682
Updated on: 2021-08-13T11:18:10+05:30

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements