From what it seemed to me in the comments and the link you posted, your goal is to make an adjunct linear regression of a forecast. Here’s the solution:
to) analyzing
df <- data.frame(
y = c(81.7, 73.3, 89.5, 79.8, 69.9),
x1 = c(38, 46, 39, 43, 32),
x2 = c(4, 0, 5, 2, 4)
)
reg <- lm(
y ~ x1 + x2, data = df
)
summary(reg)
#Call:
#lm(formula = y ~ x1 + x2, data = df)
#Residuals:
# 1 2 3 4 5
# 0.02182 -0.16295 -0.11476 0.26851 -0.01263
#Coefficients:
# Estimate Std. Error t value Pr(>|t|)
#(Intercept) -16.73960 1.62926 -10.27 0.009341 **
#x1 1.96092 0.03529 55.56 0.000324 ***
#x2 5.97566 0.09388 63.65 0.000247 ***
#---
#Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#Residual standard error: 0.2371 on 2 degrees of freedom
#Multiple R-squared: 0.9995, Adjusted R-squared: 0.999
#F-statistic: 2074 on 2 and 2 DF, p-value: 0.0004819
b) forecasting
forec <- data.frame(x1 = 39, x2 = 4)
predict(reg, newdata = forec, interval = 'confidence', level = .95)
# fit lwr upr
# 1 83.6391 83.07115 84.20706
You want to do a linear regression, is that it? I didn’t edit the title to question it here in the comment.
– neves
Yes, I’d like to do a multiple linear regression, but I don’t know how to get R to give me the equation that fits these data.
– Magliari
Possible duplicate of Multiple Linear Regression in R. See also this question to see if it helps.
– neves
I took a look at the link and I believe my doubt is different. I don’t know how to ask R to give me the Regression equation
– Magliari
What do you mean "the way"? And, what do you expect to have to answer? Try to edit the question. It’s unclear.
– neves
I was able to do it by Excel, but I need it by R. The answer would be this: Y = -16739.60122 + 1960.924952 * X1 + 5975,657713 * X2
– Magliari
It takes the vector
Y
, otherwise we cannot adjust the model. The coefficients will be given bycoef(lm(Y ~ X1 + X2))
.– Rui Barradas
Is in the link, @Rui.
– neves
@After getting the coefficients,?
– Magliari