solve 3 parameter weibull using method of moments - integral with parameters inside a solve
Show older comments
Hi all,
I am trying to use the method of moment to solve the 3 parameters of the weibull distribution. I have input all the equations however the intergal function embedded gives me an output error. I am not sure how to embed the integral into the solve function. I.e. the integral is complaining that is has a variable and not a value. Here is a link to the euqations for the moments.
Error using integral (line 85): A and B must be floating-point scalars.
Error in MOM>@(n)integral(@(s)fun(s,n),0,n)
Error in MOM (line 21) : eqn=[c +
(a*(g(1+1/b)))==u,a*sqrt(g(1+2/b)-(g(1+1/b))^2)==var,(g(1+3/b)-3*g(1+1/b)*g(1+2/b)+2*(g(1+1/b))^3)/((g(1+2/b)-(g(1+1/b))^2)^1.5)==skew;]
note I use 'name' cause i have multiply files which I would need to apply this too.
name=strcat('Location_',num2str(p,'%02d'),'_hs.mat');
load(name);
u=nanmean(values);
var=std(values);
skew=skewness(values);
s=values;
syms a b c
fun=@(s,n) s.^(n-1).*exp(-s); %integal of the gamma function
g=@(n) integral(@(s)fun(s,n),0,n); %gamma funtion
eqn=[c + (a*(g(1+1/b)))==u,a*sqrt(g(1+2/b)-(g(1+1/b))^2)==var,(g(1+3/b)-3*g(1+1/b)*g(1+2/b)+2*(g(1+1/b))^3)/((g(1+2/b)-(g(1+1/b))^2)^1.5)==skew;]
vars=[a b c];
[sola, solb, solc]=solve(eqn, vars)
5 Comments
Jeff Miller
on 20 Feb 2019
- Are you just trying to get numerical estimates or do you need to derive some equations (I'm wondering why you are using symbolics)?
- If you just want estimates, why do you prefer the method of moments over maximum likelihood? Since you have sample data values, you could use ML, which is generally better.
Walter Roberson
on 20 Feb 2019
Your b is symbolic, so when you call g(1+2/b) then you are calling g with a symbolic parameter that cannot be converted to numeric. You defined g as an anonymous function with a single parameter that is to be used as the upper bound for integral(). Because you are passing in an expression that includes an unresolved symbolic variable, you are passing a symbolic upper bound that cannot be converted to numeric to integral(). integral() cannot handle that.
Walter Roberson
on 20 Feb 2019
Why do you assign
s=values;
and then afterwards each place you use s as a variable, it is as an anonyous function parameter ? It is confusing to readers, who could easily confuse the s assigned from values with the "just a parameter" use of s.
Lauren Arendse
on 20 Feb 2019
Lauren Arendse
on 20 Feb 2019
Accepted Answer
More Answers (1)
Lauren Arendse
on 21 Feb 2019
4 Comments
Jan
on 21 Feb 2019
this is the solution that worked for me
@Lauren: Please use flags only to inform the admins about inappropriate content like spam or rudeness. Thanks. Use comments, votes or the accepting of an answer to mark it as working.
Lauren Arendse
on 21 Feb 2019
Jan
on 21 Feb 2019
@Lauren: Please explain this in detail. Are you sure that an admin of MathWorks has asked you to set a flag instead of using teh standard methods of voting or accepting the working answer? You have accepted another answer, which marks it as a working solution. Using a flag to post a comment would be a rather tedious option, because there is a number of users and admin who control the flags frequently, because this is the only method to get attention, if somebody is rude or posts illegal contents.
Lauren Arendse
on 21 Feb 2019
Categories
Find more on Exploration and Visualization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!