2017-05-29 78 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