R²计算的差异

时间:2016-02-23 11:18:25

标签: r statistics

我不确定我是否正确使用<configuration> <connectionStrings> <add name="MyDBConnectionString" connectionString="Data Source=localhost; Initial Catalog=University;Integrated Security=True" providerName="System.Data.SqlClient"/> </connectionStrings> </configuration> C# code try { String constring = ConfigurationManager.ConnectionStrings["MyDBConnectionString"].ConnectionString; using (SqlConnection con = new SqlConnection(constring)) { } } catch (Exception ex) 函数来计算Pearson的R²,因此我手动完成了一次并略有差异。

我在这里使用了cor.test数据集来使这个问题重现:

meuse

哪个收益

library(sp)
library(gstat)
data(meuse)
coordinates(meuse) = ~x+y
data(meuse.grid)
gridded(meuse.grid) = ~x+y
m <- vgm(.59, "Sph", 874, .04)
# ordinary kriging:
x <- krige(log(zinc)~1, meuse, meuse.grid, model = m)


#1-out Cross Validation
cross<-krige.cv(zinc~1,meuse,m)
cross

# R² Method 1:
RSQR1 <- as.numeric(cor.test(meuse$zinc,cross$var1.pred)$estimate)^2  #Pearson's R Squared

# R² Method 2:
numerator <- c()
for (l in 1:length(meuse$zinc))
{
  numerator[l] <- (meuse$zinc[l] - cross$var1.pred[l])^2
}

denominator  <- c()
for (k in 1:length(meuse$zinc))
{
  denominator[k] <- (meuse$zinc[k] - mean(meuse$zinc))^2
}

RSQR2 <- 1-((sum(numerator))/(sum(denominator)))

# Compare results:
RSQR1
RSQR2

哪个错了,我忘记了什么?

0 个答案:

没有答案