在分类变量上提取非线性方程的系数

发布于 2025-01-18 08:28:54 字数 1206 浏览 3 评论 0原文

这个问题似乎偏离主题,因为它侧重于编程、调试或执行常规操作,或者询问有关获取数据集的问题。您可以尝试使用我们维护的支持链接或开放数据网站。

如果您询问如何调试某些代码或使用编程语言执行任务,这不是一个主题问题。如果您询问如何获取数据,那么这不是一个主题问题。如果您认为您的问题确实与帮助中心中所述的统计数据有关,请[编辑]进行澄清。

25 分钟前关闭。

(给你的私人反馈)

我试图从方程中提取系数 k1,2 和 3:

Mt=M1exp(−k1⋅CDI⋅t)+M2exp(−k2⋅CDI⋅t)+M3exp(−k3⋅CDI⋅t)

其中 Mt 是时间 t 时的质量,m1 是初始不稳定碳含量(以%为单位),m2 是全纤维素含量,m3 是木质素内容,最后,CDI

是气候分解指数(见下图)。

我已经设法使用以下代码从单个视线中提取系数:

eqtn <- function(m1, k1, cdi, t, m2, k2, m3, k3){(m1 * exp(-k1 * cdi * t)+
                                             m2 * exp(-k2 * cdi * t)+
                                             m3 * exp(-k3 * cdi * t))}

nls(mass_remaining_percent ~ eqtn(scf_mean_initial, k1, cdi_mean, days_between, 
                                  holocellulose_mean_initial, k2, lignin_mean_initial, k3),
    start = list(k1 = 0.0007, k2 = 0.0005, k3 = 0.0001), data = a.3_pooled_data)

有谁知道如何将其应用于视线类别(字段代码)并提取系数/ R2?我知道它需要分成许多小数据集,然后应用模型,提取数据并重新组合,但我不知道如何做到这一点

提前感谢 Example of data

我刚刚设法编写了上述代码,将模型拟合到单行代码,我知道我可以手动执行此操作,拟合许多较小的数据集,但这需要年龄和我想要了解如何使用 apply 系列或 broom 包来完成此操作。

This question appears to be off-topic because it focuses on programming, debugging, or performing routine operations, or it asks about obtaining datasets. You could try the support links we maintain or the Open Data site instead.

If you are asking about how to debug some code or carry out a task in a programming language, this is not an on-topic question. If you're asking about how to obtain data, that is not an on-topic question. If you feel your question is truly about statistics as described in the help center, please [edit] to clarify.

Closed 25 mins ago.

(Private feedback for you)

I am trying to extract the coefficients k1,2 and 3 from the equation:

Mt=M1exp(−k1⋅CDI⋅t)+M2exp(−k2⋅CDI⋅t)+M3exp(−k3⋅CDI⋅t)

where Mt is mass at time t, m1 is the initial labile carbon content (in %), m2 is holocellulose content, m3 is lignin content, and finally, CDI

is climate decomposition index (see below image).

I have managed to extract the coefficients from a single sight using the following code:

eqtn <- function(m1, k1, cdi, t, m2, k2, m3, k3){(m1 * exp(-k1 * cdi * t)+
                                             m2 * exp(-k2 * cdi * t)+
                                             m3 * exp(-k3 * cdi * t))}

nls(mass_remaining_percent ~ eqtn(scf_mean_initial, k1, cdi_mean, days_between, 
                                  holocellulose_mean_initial, k2, lignin_mean_initial, k3),
    start = list(k1 = 0.0007, k2 = 0.0005, k3 = 0.0001), data = a.3_pooled_data)

Does anyone know how I can apply this over categories of sight (field code) and extract the coefficients/ R2? I know that it needs splitting into many small datasets, then applying the model, extracting data and recombining but I can't figure out how to do it

Thanks in advanceExample of data

I have just managed to write the above code, fitting the model to a singular line of code, I know that I can do this manually, fitting to many smaller datasets but it will take an age and I would like to learn how to do it using the apply family or the broom package.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陌上青苔 2025-01-25 08:28:54

对于系数,请使用 coef返回向量或 summary.nls(...)$coefficients 返回一个矩阵,其中还包括 t 统计数据和 p 值nls() 的结果。要按分组运行模型,请考虑 bytapply 的面向对象包装器):

eqtn <- function(m1, k1, cdi, t, m2, k2, m3, k3) {
    (m1 * exp(-k1 * cdi * t) +
     m2 * exp(-k2 * cdi * t) +
     m3 * exp(-k3 * cdi * t))
}

model <- mass_remaining_percent ~ eqtn(
    scf_mean_initial, k1, cdi_mean, days_between, 
    holocellulose_mean_initial, k2, lignin_mean_initial, k3
)

run_model_by_group <- function(sub) {
    results <- nls(
        model,
        start = list(k1 = 0.0007, k2 = 0.0005, k3 = 0.0001), 
        data = sub
    )

    return(summary(results)$coefficients)
}

# LIST OF COEFFICIENT MATRICES BY FIELD CODE
field_code_coefficient_matrices <- by(
    a.3_pooled_data,
    a.3_pooled_data$Field.Code,
    FUN = run_model_by_group
)

For coefficients, use either coef to return a vector or summary.nls(...)$coefficients to return a matrix which also includes t-stats and p-values on results of nls(). To run model by groupings, consider by (the object-oriented wrapper of tapply):

eqtn <- function(m1, k1, cdi, t, m2, k2, m3, k3) {
    (m1 * exp(-k1 * cdi * t) +
     m2 * exp(-k2 * cdi * t) +
     m3 * exp(-k3 * cdi * t))
}

model <- mass_remaining_percent ~ eqtn(
    scf_mean_initial, k1, cdi_mean, days_between, 
    holocellulose_mean_initial, k2, lignin_mean_initial, k3
)

run_model_by_group <- function(sub) {
    results <- nls(
        model,
        start = list(k1 = 0.0007, k2 = 0.0005, k3 = 0.0001), 
        data = sub
    )

    return(summary(results)$coefficients)
}

# LIST OF COEFFICIENT MATRICES BY FIELD CODE
field_code_coefficient_matrices <- by(
    a.3_pooled_data,
    a.3_pooled_data$Field.Code,
    FUN = run_model_by_group
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文