将幂律函数拟合到 R 中的数据
Fitting power law function to data in R
我正在尝试使用此处的逐步方法将幂律函数拟合到我的数据
https://www.statology.org/power-regression-in-r/
但我不清楚错误
```Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : NA/NaN/Inf in 'x'```
它说我需要确保它是我所做的 as.numeric,但我仍然得到错误。我怎样才能对此拟合幂律并得到方程?
dput(data)
structure(list(Depth = c(0, 1.12941645231161, 2.25883290462321, 3.38824935693482,
4.51766580924643, 5.64708226155804, 6.77649871386964, 7.90591516618125,
9.03533161849286, 10.1647480708045, 11.2941645231161, 12.4235809754277,
13.5529974277393, 14.6824138800509, 15.8118303323625, 16.9412467846741,
18.0706632369857, 19.2000796892973, 20.3294961416089, 21.4589125939205
), Biomass = c(2.38380058571429, 2.38351444250963, 2.38322874604698,
2.38294349557974, 2.38265869045564, 2.38237435716909, 2.382090559166,
2.38180732244924, 2.38152464168852, 2.38124252252291, 2.38096100921642,
2.38068013931138, 2.38039991126563, 2.38012032354094, 2.3798413897966,
2.37956313811693, 2.37928557316563, 2.37900869200497, 2.37873250170607,
2.37845703591721)), row.names = c(NA, 20L), class = "data.frame")
data$Depth <- as.numeric(data$Depth)
data$Biomass <- as.numeric(data$Biomass)
model <- lm(log(data$Biomass) ~ log(data$Depth))
summary(model)
您的问题出在日志上。
summary(data)
Depth Biomass
Min. : 0.000 Min. :2.378
1st Qu.: 5.365 1st Qu.:2.380
Median :10.729 Median :2.381
Mean :10.729 Mean :2.381
3rd Qu.:16.094 3rd Qu.:2.382
Max. :21.459 Max. :2.384
由于 Depth 的值为零,因此 log(data$Depth)
的值等于 -Inf
我正在尝试使用此处的逐步方法将幂律函数拟合到我的数据
https://www.statology.org/power-regression-in-r/
但我不清楚错误
```Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : NA/NaN/Inf in 'x'```
它说我需要确保它是我所做的 as.numeric,但我仍然得到错误。我怎样才能对此拟合幂律并得到方程?
dput(data)
structure(list(Depth = c(0, 1.12941645231161, 2.25883290462321, 3.38824935693482,
4.51766580924643, 5.64708226155804, 6.77649871386964, 7.90591516618125,
9.03533161849286, 10.1647480708045, 11.2941645231161, 12.4235809754277,
13.5529974277393, 14.6824138800509, 15.8118303323625, 16.9412467846741,
18.0706632369857, 19.2000796892973, 20.3294961416089, 21.4589125939205
), Biomass = c(2.38380058571429, 2.38351444250963, 2.38322874604698,
2.38294349557974, 2.38265869045564, 2.38237435716909, 2.382090559166,
2.38180732244924, 2.38152464168852, 2.38124252252291, 2.38096100921642,
2.38068013931138, 2.38039991126563, 2.38012032354094, 2.3798413897966,
2.37956313811693, 2.37928557316563, 2.37900869200497, 2.37873250170607,
2.37845703591721)), row.names = c(NA, 20L), class = "data.frame")
data$Depth <- as.numeric(data$Depth)
data$Biomass <- as.numeric(data$Biomass)
model <- lm(log(data$Biomass) ~ log(data$Depth))
summary(model)
您的问题出在日志上。
summary(data)
Depth Biomass
Min. : 0.000 Min. :2.378
1st Qu.: 5.365 1st Qu.:2.380
Median :10.729 Median :2.381
Mean :10.729 Mean :2.381
3rd Qu.:16.094 3rd Qu.:2.382
Max. :21.459 Max. :2.384
由于 Depth 的值为零,因此 log(data$Depth)
的值等于 -Inf