在线性拟合中使用矩阵列

时间:2019-03-24 04:25:33

标签: r

如何将数值矩阵的一列用作目标变量,而其余列用作预测变量?

这不起作用

# read matrix with 14 columns
d <- read.table("myfile.txt")

# target variable is last column
y <- d[,14]
x <- d[,-14]
my.fit <- y~x

1 个答案:

答案 0 :(得分:0)

您可以这样做:

data(mtcars) #get some preinstalled data


model <- lm(mpg ~ ., data = mtcars) #fit the model

summary(model) #get the summary

这对所有其他变量进行了mpg的线性回归。无需进一步处理。

相关问题