# 用基本R拟合平方根函数

``````plot(gbl\$g_aH_upper~gbl\$windspeed,
main="Boundary Layer Conductance",
xlab="wind speed [m/s]",
xaxt='n',
cex.axis=0.8,
pch=19,
las=1,
col="black",type="p",cex=0.7)
axis(side=1,las=1, at=c(seq(from=0,to=2.0,by=0.1), tick=F))
legend('bottomright', legend=c("Upper leaves","Lower leaves")[-50],
lty=1, col=c('black', 'red'), bty='n', cex=1.0, y.intersp = 0.6, x.intersp = 0.4, seg.len = 0.6,lwd=1.5, text.width = 0.8)
par(new = TRUE)
plot(gbl\$g_aH_lower~gbl\$windspeed, axes = FALSE, xlab = ' ', ylab = ' ', col="red" ,type="p",cex=0.7,las=1, pch=16)
``````

``````#create limited data
x<-c(0,  1.1, 1.4, 1.7)
y<-c(0.06, 0.115, 0.115, 0.125)

plot(y~x)
model<-lm(y~x)
#plot a linear fit
abline(model, col="blue")
print(summary(model))

#model with the square of x
modelsr<-lm(y~I(sqrt(x)))
print(summary(modelsr))

#generate the data to the model
xbar<-seq(0, 1.7, 0.03)
ybar<-modelsr\$coefficients[1]+sqrt(xbar)*modelsr\$coefficients[2]
#plot model
lines(y=ybar, x=xbar, pch=19, col="green")
``````

0 条评论