KingDan KingDan - 1 year ago 82
R Question

Finding Mean Squared Error?

I have produced a linear data set and have used

to fit a model to that dataset. I am now trying to find the MSE using

I know the formula for MSE but I'm trying to use this function. What would be the proper way to do so? I have looked at the documentation, but I'm either dumb or it's just worded for people who actually know what they're doing.


x.linear <- seq(0, 200, by=1) # x data
error.linear <- rnorm(n=length(x.linear), mean=0, sd=1) # Error (0, 1)
y.linear <- x.linear + error.linear # y data <- data.frame(x.linear, y.linear)
training.model <- lm(
training.mse <- mse(training.model,


needs two data frames. I'm not sure how to get a data frame out of
. Am I even on the right track to finding a proper MSE for my data?

Answer Source

Try this:

mean(( - predict(training.model))^2)
#[1] 0.4467098
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download