【问题标题】:Hi, I have just started learning R and would like to add curve to the function嗨,我刚开始学习 R,想在函数中添加曲线
【发布时间】:2020-11-04 16:01:55
【问题描述】:

我刚开始学习 R,想在函数中添加曲线。 但是收到“逻辑错误(x,c(0.05,3)):找不到对象't_0'”

logistic<-function(t,theta=c(b,t_0)) {
return((exp(b*(t-t_0))/(1+exp(b*(t-t_0))))) #function
}  
x<-c(-30:30)
curve(logistic(x,c(0.05,3)),from=-30, to=30, add=TRUE)

【问题讨论】:

    标签: r function curve


    【解决方案1】:

    您不能将向量传递给像 R 中那样的函数。您可以传递向量但使用 [] 索引来访问它们的元素:

    logistic<-function(t,theta=c(b,t_0)) {
      return((exp(theta[1]*(t-theta[2]))/(1+exp(theta[1]*(t-theta[2]))))) #function
    }
    

    或者您可以将每个元素作为不同的参数传递:

    logistic<-function(t, b, t_0) {
      return((exp(b*(t-t_0))/(1+exp(b*(t-t_0))))) #function
    }  
    

    【讨论】:

    • 非常感谢。花了我 5 个小时:)
    • 如果有帮助,请接受将帖子标记为已解决的答案:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-20
    • 2016-11-29
    • 1970-01-01
    • 2019-05-04
    • 1970-01-01
    • 2011-01-21
    相关资源
    最近更新 更多