简体   繁体   English

用R解两个未知数的方程

[英]Solving equations with two unknowns in R

I am fitting distributions to datasets. 我正在将分布拟合到数据集。 I need to adjust the parameters of the distributions according to given functions/ formulas. 我需要根据给定的函数/公式调整分布的参数。 I don't know how to go about solving the issue in R 我不知道如何解决R中的问题

The datasets are precipiations datasets form 14 different durations of rain (5 minutes, 10 minutes, 15 minutes, etc.). 这些数据集是来自14个不同降雨持续时间(5分钟,10分钟,15分钟等)的降水数据集。 To each dataset i fit a distribution. 对于每个数据集,我都适合一个分布。 Afterwards i need to fit a function to the distribution parameters in order to obtain a relationship between rain duration and distribution parameter. 之后,我需要对分布参数拟合函数,以便获得降雨持续时间与分布参数之间的关系。

The functions for each of the distribution parameters are given. 给出了每个分布参数的功能。 For Example the function for the location parameter is: u(d) = a/d^b 例如,location参数的函数为:u(d)= a / d ^ b

where u(d) are the location parameters of all 14 fitted distributions (for each duration d) and d are the durations 5,10,15,30,45,60,90,120,180,240,300,360,720 and 1440 minutes. 其中u(d)是所有14个拟合分布的位置参数(对于每个持续时间d),而d是持续时间5,10,15,30,45,60,90,120,180,240,300,360,720和1440分钟。 I now need to find parameters a and b 我现在需要找到参数a和b

My problem lies in not understanding how to approach the issue in R, due to lacking mathematical knowledge and insufficient knowledge of the terms in english. 我的问题在于,由于缺乏数学知识和对英语术语的了解,因此不了解如何用R解决问题。 I have started reading a bit about deSolve, but i got confused quickly and am not even sure if i am on the right track. 我已经开始阅读一些有关deSolve的文章,但是我很快就感到困惑,甚至不确定自己是否走对了轨道。

An Example 一个例子

u <- seq(0,60, length.out = 14) # these are the resulting location parameters

d <- c(5,10,15,30,45,60,90,120,180,240,300,360,720,1440)

So, if possible, i'd like to get suggestions how to approach the problem and on how to set-up the equation solving code. 因此,如果可能的话,我想获得有关如何解决问题以及如何设置方程式求解代码的建议。

I think i found the solution myself using nls (from package "stats") 我想我自己使用nls找到了解决方案(来自“ stats”包)

d <- c(5,10,15,30,45,60,90,120,180,240,300,360,720,1440)
mu <- seq(5, 30, length.out = 14)

thresholds for a and b were given: 给出了a和b的阈值:

a needs to be higher than 0, and b needs to be higher than -1 a必须大于0,b必须大于-1

start_a <- 0.1 # start-value higher than 0
start_b <- -0.9 # start-value higher than -1

i could then set up the function 然后我可以设置功能

mu_fun <- function(a,d,b) {
a/(d^b) }

and finally run the nls with the function and the given starting estimates 最后使用函数和给定的起始估算值运行nls

mu_fit <- nls(mu ~ mu_fun(a,d,b), start = list(a = start_a, b = start_b))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM