Math model

1
Y = a1*X1 + a2*X2 + a3*X3 + ... + an*Xn + b

Y and X are known, a and b will be calculated.


Data processing

Input Y and X to Rstudio.

1
2
3
4
5
6
7
8
# build multiple regression model
library("readxl", lib.loc="~/R/win-library/3.5")
df = read_excel("yourdata.xlsx")

# explore the data structure
str(df)
summary(df$GRDP)
hist(df$GRDP)

Build the model. lm() take thes the known Y and X as arguments, lm(Y ~ X1 + X2 + ... + Xn).

1
2
3
4
model = lm(GRDP~LANDU_21+LANDU_22+LANDU_23+LANDU_24, data = df)

# check the model
summary(model)

Model application.

1
2
3
test = read_excel("your_test_data.xlsx")
pred = predict(model, newdata = test)
pred