【发布时间】:2018-01-02 21:38:04
【问题描述】:
背景:物种丰富度与体重的负值 -0.75 成正比。但是,当我拟合我的数据时,我得到的值为 0.57。一位朋友告诉我,summary(lm) 结果打印出数据的“最佳拟合”斜率。不过,我想知道是否可以创建一个回归图,其中我将斜率强制为 -0.75,就像文献中一样。
我的代码是:
y 值
log.nspecies.dec = c(3.05, 2.95, 2.97, 2.98, 2.84, 2.85, 2.83, 2.71, 2.64, 2.62, 2.58, 2.37, 2.26, 2.17, 2.00, 1.88, 1.75, 1.62, 1.36, 1.30, 1.08, 1.20, 0.90, 0.30, 0.70, 0.30, 0.48, 0.00, 0.30, 0.00)
x 值
logbio.dec = c(2.1, 2.3, 2.5, 2.7, 2.9, 3.1, 3.3, 3.7, 3.9, 4.1, 4.3, 4.5, 4.7, 4.9, 5.1, 5.3、5.5、5.7、5.9、6.1、6.3、6.5、6.7、6.9、7.1、7.3、7.5、7.7、7.9)
绘制条形图并叠加回归线
用 x 命名 y 变量
名称(log.nspecies.dec)= logbio.dec
对 y 变量进行排序
log.nspecies.dec = log.nspecies.dec[order (as.numeric(names(log.nspecies.dec)))]
做条形图
xpos = barplot(log.nspecies.dec, las = 2, space = 0)
lm.fit = lm(log.nspecies.dec ~ as.numeric(names(log.nspecies.dec))) 摘要(lm.fit)
y.init = lm.fit$coefficients[2] * as.numeric(names(log.nspecies.dec))1 + lm.fit$coefficients1
y.end = lm.fit$coefficients[2] * as.numeric(names(log.nspecies.dec))[length(log.nspecies.dec)] + lm.fit$coefficients1
segments(xpos1, y.init, xpos [length(xpos)], y.end, lwd = 2, col = 'red')
title(main = 'ln 种数~lm 重量')
系数(lm.fit)
【问题讨论】:
标签: r regression