闪亮的非线性模型的曲线拟合

问题描述 投票:0回答:1

我正在尝试将一些非线性模型拟合为闪亮的,以识别最佳参数值,然后将它们用作初始值。作为示例,我正在使用非线性逻辑模型。

以下是计算例程:

library(shiny)
library(ggplot2)

ui <- fluidPage(
  sliderInput("beta_0", "Beta 0:", min = -100, max = 100, value = 1),
  sliderInput("beta_1", "Beta 1:", min = -1000, max = 100, value = 1),
  sliderInput("beta_2", "Beta 2:", min = -100, max = 100, value = 1),
  
  plotOutput("grafico")
)

server <- function(input, output) {
  
  logistic_model <- function(x, beta_0, beta_1, beta_2) {
    return (beta_0 / (1 + beta_1 * exp(-beta_2 * x)))
  }
  
  data_modelling <- structure(list(x = c("10.66", "16.87", "12.57", "15.92", "9.71", 
                                         "15.92", "17.35", "6.37", "11.94", "11.14", "8.91", "13.05", 
                                         "17.67", "10.66", "17.19", "7", "10.82", "11.62", "16.71", "18.3", 
                                         "11.78", "12.25", "8.91", "10.98", "17.03", "15.92", "12.73", 
                                         "12.41", "11.78", "18.62"), y = c("15.2", "18.3", "15.7", "17.5", 
                                                                           "14.8", "16.7", "19.8", "10.3", "18.6", "14.4", "14.3", "17.8", 
                                                                           "21", "18.8", "18.9", "13.7", "17.6", "17.5", "19.6", "18.8", 
                                                                           "15.3", "16.8", "15.1", "14.7", "18.5", "17.9", "17.8", "16.9", 
                                                                           "17.5", "18.7")), row.names = 31:60, class = "data.frame")
  data_modelling$x = as.numeric(data_modelling$x)
  data_modelling$y = as.numeric(data_modelling$y)
  
  output$grafico <- renderPlot({
    ggplot(data_modelling, aes(x = x, y = y)) +
      geom_point() +
      stat_function(fun = logistic_model, args = list(
        beta_0 = input$beta_0,
        beta_1 = input$beta_1,
        beta_2 = input$beta_2
      )) +
      labs(x = "X", y = "Y")
  })
}

shinyApp(ui, server)

我遇到的问题是曲线没有出现在实际的 S 型数据之上。我尝试了很多参数,我的模型是正确的(考虑的模型是基于这篇文章:10.34188/bjaerv4n1-035),请参阅:

r plot shiny regression non-linear-regression
1个回答
0
投票

将 beta 2 滑块调整为 0.1 步长,即可得到曲线。

© www.soinside.com 2019 - 2024. All rights reserved.