2017-05-29 75 views

回答

3

您可以使用以下格式:

# Fit model 
model.lm <- lm(Sepal.Length ~ Petal.Length, data = iris[1:75,]) 

# Predict data for some new data 
pred.dat <- predict(model.lm, newdata = iris[76:150,]) 

# Calculate correlation between predicted values for new data and actual values, then square 
cor(iris[1:75,"Sepal.Length"], pred.dat)^2 

,如果你喜欢,你可以打包这一切的功能。如果您需要任何帮助,只需询问。

干杯

费利佩

+0

非常感谢菲利普!我现在会尝试,看起来非常好! – Stephane