如何在多元线性回归模型中找到预测数?

时间:2019-01-27 03:39:52

标签: r linear-regression prediction

问题要求我找到平均船舶预计的乘客人数

我已经使用矩阵运算和R中的lm函数计算出β,以估计模型。但是,如何计算平均船舶的预测数量呢?谢谢

cship <- read.csv("C:/Users/Yuxi Liu/Desktop/cruise_ship.dat.csv")
colnames(cship)=c("ShipName","CruiseLine","Age","Tonnage","passengers","Length","Cabins","pdensity","crew")
cship_model = lm(passengers ~ Age + Tonnage + Length, data = cship)
coef(cship_model)
n = nrow(cship)
p = length(coef(cship_model))
X = cbind(rep(1, n), cship$Age, cship$Tonnage, cship$Length)
y = cship$passengers

t(X) %*% X
t(X) %*% y

(beta_hat = solve(t(X) %*% X) %*% t(X) %*% y)

cship_model = lm(passengers ~ Age + Tonnage + Length, data = cship)
cship_model

0 个答案:

没有答案