Reputation: 11
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
The datasets are precipiations datasets form 14 different durations of rain (5 minutes, 10 minutes, 15 minutes, etc.). 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
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. I now need to find parameters a and 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. 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.
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.
Upvotes: 0
Views: 673
Reputation: 11
I think i found the solution myself using nls (from package "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 needs to be higher than 0, and b needs to be higher than -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
mu_fit <- nls(mu ~ mu_fun(a,d,b), start = list(a = start_a, b = start_b))
Upvotes: 1