簡體   English   中英

指數擬合在對數標度R上

[英]Exponential fit on logarithmic scale R

這是我的代碼:

a<-c(0.83, 1.67, 2.5, 3.33,6.39)
b<-c(34252553.89, 34430947.5, 36494798.86, 66156794.56, 248698700.1)
plot(a,b)
plot(a,b, log='y')

現在我想為我的情節添加指數擬合(應該與對數刻度呈線性關系)

我怎樣才能做到這一點?

你可以使用lm

dat <- as.data.frame(cbind(a,b))

繪制數據:

plot(log(b)~a, data=dat)

適合線性模型:

fit <- lm(log(b) ~ a, data=dat)
summary(fit)

Call:
lm(formula = log(b) ~ a, data = dat)

Residuals:
       1        2        3        4        5 
 0.27207 -0.04616 -0.30751 -0.03222  0.11383 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) 16.75764    0.20360   82.31 3.95e-06 ***
a            0.38502    0.05798    6.64  0.00696 ** 
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

Residual standard error: 0.2481 on 3 degrees of freedom
Multiple R-squared: 0.9363,     Adjusted R-squared: 0.9151 
F-statistic: 44.09 on 1 and 3 DF,  p-value: 0.006959 

預測值並繪制它們:

lines(predict(fit)~dat$a)

在此輸入圖像描述

這對你有幫助嗎?

使用基本繪圖,您需要在外部調整數據並添加它。 使用ggplot2更容易做到這一點。 例如:

dat <- data.frame(x=a,y=b)
library(ggplot2)
ggplot(dat,aes(x=x,y=y))+
  geom_point(size=5) +
  stat_smooth(method='glm')+
  scale_y_log10()

在此輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM