簡體   English   中英

在R,實際數據和估計參數中繪制NLS

[英]Plot NLS in R, real data and estimated parameters

我的數據集ICM_Color0具有以下結構,其中列為:

Lum Ruido Dist RT.ms條件

有2599行。

有三種亮度= [13,19,25];兩種類型的噪聲= [1、2]-> 3x2 = 6個條件。

條件:

Lum   Ruido   Condicion
13     1        1
13     2        2
19     1        3
19     2        4
25     1        5
25     2        6

我的模型是:

Color0.nls <- nls(RT.ms ~ 312 + K[Condicion]/(Dist^1),     
              data = ICM_Color0, start = list(K = rep(1,6)))



> summary(Color0.nls)

Formula: RT.ms ~ RT0.0 + K[Condicion]/(Dist^n)

Parameters:
   Estimate Std. Error t value Pr(>|t|)    
K1  1.84108    0.03687   49.94   <2e-16 ***
K2  2.04468    0.03708   55.14   <2e-16 ***
K3  1.70841    0.03749   45.58   <2e-16 ***
K4  2.09915    0.03628   57.86   <2e-16 ***
K5  1.62961    0.03626   44.94   <2e-16 ***
K6  2.18235    0.03622   60.26   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 120.5 on 2593 degrees of freedom

Number of iterations to convergence: 1 
Achieved convergence tolerance: 1.711e-08

我需要繪制實際數據和參數估計。

我已經對文獻進行了全面回顧,但是沒有發現像我的模型那樣的示例依賴於條件變量的示例。 誰能指導我?

非常感謝

從回歸(非線性或非線性)繪制擬合線是非常簡單的。 我通常通過使用“ predict來從原始數據計算預測值,然后將其繪制為數據散點圖上方的線來執行此操作。

您沒有提供可復制的示例,因此我根據此答案制作了一些非線性數據。

# Create data to fit with non-linear regression
set.seed(16)
x = seq(100)
y = rnorm(200, 50 + 30 * x^(-0.2), 1)
site = rep(c("a", "b"), each = 100)
dat = data.frame(expl = c(x, x), resp = y, site)

然后,我擬合了非線性回歸,允許每個參數隨分組變量site不同而變化。

fit1 = nls(resp ~ a[site] + b[site] * expl^(-c[site]), data = dat, 
      start = list(a = c(80, 80), b = c(20, 20),  c = c(.2, .2)))

現在,我只是使用predict.nls將擬合值添加到數據集中

dat$pred = predict(fit1)

我使用ggplot2軟件包對此進行了繪制。

ggplot(data = dat, aes(x = expl, y = resp, color = site)) +
    geom_point() +
    geom_line(aes(y = pred))

在這種情況下,我允許所有參數隨站點而變化,看起來您可以通過geom_smoothggplot完成所有這些geom_smooth 我在這里找到了一個很好的例子。

這是玩具數據集的外觀。

ggplot(data = dat, aes(x = expl, y = resp, color = site)) +
    geom_point() +
    geom_smooth(aes(group = site), method = "nls", formula = "y ~ a + b*x^(-c)", 
              start = list(a = 80, b = 20,  c = .2), se = FALSE)

暫無
暫無

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

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