所以我使用以下脚本:
area <- c(1854,2001,2182,2520,4072,1627,1308,1092,854,1223,2231,1288,898,2328,1660,6018,5420,943,1625,1095,1484,929,1178,4072,2413)
weight1 <- c(24281,28474,33725,40707,76124,16263,12190,10153,8631,13690,34408,15375,8806,36245,20506,109489,104014,11308,23262,11778,20650,8771,12356,76124,28346)
weight <- weight1/1000
df <- data.frame(weight = log10(weight), area = log10(area))
fit_line <- predict(lm(area ~ weight, data=df))
fit_power <- predict(nls(area ~ i*weight^z, start=list(i=2,z=0.7), data=df))
plot(df$weight,df$area)
lines(df$weight,fit_line,col="red")
lines(sort(df$weight),sort(fit_power), col="blue")
做一个对数 - 对数图。我可以绘制一条直线,lm()
但是当我nls()
用来进行功率拟合时,它绘制的是曲线而不是直线,见下文:
如何以直线的形式绘制功率拟合,或者如何从lm()
. 所以我有以下形式的答案:y = a*x^b