我正在try 将一些非线性模型拟合到SHILINY中,以确定最佳参数值,然后将它们用作初始值.举个例子,我使用的是一个非线性逻辑模型.

以下是计算 routine :

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形数据之上.我try 了许多参数,我的模型是正确的(所考虑的模型基于本文:10.34188/bjAerv4n1-035),请参阅:

enter image description here

推荐答案

通过将Beta 2滑块调整为0.1个步长,您可以得到曲线.

output

R相关问答推荐

是否有任何解决方案可以优化VSCode中RScript的图形绘制?

卸载安装了BRM的模型发出的警告

R Lubridate:舍入/快照日期时间到一天中最近的任意时间?

对lme 4对象运行summary()时出错(diag中的错误(from,names = RST):对象unpackedMatrix_diag_get找不到)

如何对数据集进行逆向工程?

在rpart. plot或fancyRpartPlot中使用带有下标的希腊字母作为标签?

如何同时从多个列表中获取名字?

解析R函数中的变量时出现的问题

在GG图中绘制射线的自动程序

具有重复元素的维恩图

为什么在BASE R中绘制线条时会看到线上的点?

从R中发出的咕噜声中的BUG?

R中时间间隔的大向量与参考时间间隔的相交

如何预测原始数据集并将值添加到原始数据集中

填充图例什么时候会有点?

在不重复主题的情况下重新排列组

R dplyr::带有名称注入(LHS of:=)的函数,稍后在:=的RHS上引用

图中显示错误 colored颜色 的图例geom_sf

将日期列从字符转换为日期得到的结果是NAS

带查找数据的FCT_REORDER.帧