The predict()-function is returning unexpected output

时间:2019-04-08 13:56:17

标签: r linear-regression predict

Problem

i have a linear regression model created with some dataset (i.d. logAnalysis <- lm(log(wage) ~ female+exper+school) ) everything works fine and looks as expected.

I now got a matrix of new data:

students <- matrix(c(
  0, 3, 10,
  1, 17, 12,
  1, 8, 9,
  0, 20, 10,
  0, 34, 9,
  0, 2, 13
), ncol = 3, byrow = TRUE)

With the first column being the female/male trade the second being the work-experience and the third being school education. I now want to make a prediction about the expected wages. This is how I thought it would go:

predictionData <- data.frame(female=students[,1], exper=students[,2], school=students[,3])

predictedIncome <- predict(logAnlaysis, newData = predictionData)

but as it turns out predictedIncome is not an vector of 6 (i.d. 6 predictions, one for each student) but an vektor of [1:3296]. I cannot make sense of that. Maybe I missunderstood the whole function. But I wouldn't know what else it does.

Thank you for your help

Regards

1 个答案:

答案 0 :(得分:0)

只有一个错字。 newData = predictionData而不是newdata = predictionData