我被R难倒了。这可能不是这类问题的最佳论坛,如果我将其发布在其他地方,请道歉。
我通过一些看起来像这样的数据进行线性回归:
但是当我调用线性模型的系数时,它会显示:
> fit$coefficients
(Intercept) data$logA
3.1370219 0.1718147
显然y-intercept更像是2而不是3.这怎么可能?!
这是我的代码:
data <- read.csv("Diamond1976_Table1.csv",header=T,sep=",") # read the csv file
# Make the first species-area curve
Area <- data$A_mi2
Slow <- data$S_low
plot(Area, Slow, xlab = "Area (mi^2)",
ylab = "Species Richness",
pch = 15, cex = 1, col = "skyblue")
# Take the logarithm of the data
data$logS_low = log(data$S_low)
data$logS_mt = log(data$S_mt)
data$logA = log(data$A_mi2)
# Log plot
plot(data$logA, data$logS_low, xlab = "Log area",
ylab = "Log species richness", main = "Log-log plot Diamond (1976)",
pch = 15, cex = 1, col = "skyblue")
fit <- lm(data$logS_low ~ data$logA) # tilda is "explained by"
abline(fit)
summary(fit)
fit$coefficients
有人能找到一个明显的错误吗?我可以发布数据,如果这有用,但我觉得有人可以解释为什么没有数据发生这种情况。