<html>
<head>
</head>
<body class='hmmessage'><div dir='ltr'>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
<div dir="ltr">Thanks Christophe,<br><br>I appreciate your response.<br><br>I tried to fit a cauchy distribution as well - is it again a scaling issue with that distribution as well because these are the results I got...<br><br>> fitdist(<b>A$V1</b>,"cauchy",method="mle")<br>
Error in fitdist(A$V1, "cauchy", method = "mle") : <br>
the function mle failed to estimate the parameters, <br>
with the error code 100<br>
In addition: Warning message:<br>
In dcauchy(x, location, scale, log) : NaNs produce<br><br>>fitdist(<b>A$V1*10^5</b>,"cauchy",method="mle")<br>Fitting of the distribution ' cauchy ' by maximum likelihood <br>Parameters:<br> estimate Std. Error<br>location -29.03782 20.90514<br>scale 119.30992 15.61003<br><br><br><div><div id="SkyDrivePlaceholder"></div>> Subject: Fwd: [R-SIG-Finance] fitdist in R<br>> From: dutangc@gmail.com<br>> Date: Tue, 3 Jan 2012 08:55:35 +0100<br>> CC: RiskAssessment-News@lists.r-forge.r-project.org; ml.delignette@vetagro-sup.fr<br>> To: fin_engr@hotmail.com; josh.m.ulrich@gmail.com<br>> <br>> Please find an answer to your fitdistrplus problem below.<br>> <br>> Kind regards<br>> <br>> Christophe<br>> ________________________________________________________________<br>> <br>> <br>> library(fitdistrplus)<br>> <br>> <br>> A <- structure(list(V1 = c(-0.00707717, -0.000947418, -0.00189753, <br>> -0.000474947, -0.00190205, -0.000476077, 0.00237812, 0.000949668, <br>> 0.000474496, 0.00284226, -0.000473149, -0.000473373, 0, 0, 0.00283688, <br>> -0.0037843, -0.0047506, -0.00238379, -0.00286807, 0.000478583, <br>> 0.000478354, -0.00143575, 0.00143575, 0.00238835, 0.0042847, <br>> 0.00237248, -0.00142281, -0.00142484, 0, 0.00142484, 0.000948767, <br>> 0.00378609, -0.000472478, 0.000472478, -0.0014181, 0, -0.000946522, <br>> -0.00284495, 0, 0.00331832, 0.00283554, 0.00141476, -0.00141476, <br>> -0.00188947, 0.00141743, -0.00236351, 0.00236351, 0.00235794, <br>> 0.00235239, -0.000940292, -0.0014121, -0.00283019, 0.000472255, <br>> 0.000472032, 0.000471809, -0.0014161, 0.0014161, -0.000943842, <br>> 0.000472032, -0.000944287, -0.00094518, -0.00189304, -0.000473821, <br>> -0.000474046, 0.00331361, -0.000472701, -0.000946074, 0.00141878, <br>> -0.000945627, -0.00189394, -0.00189753, -0.0057143, -0.00143369, <br>> -0.00383326, 0.00143919, 0.000479272, -0.00191847, -0.000480192, <br>> 0.000960154, 0.000479731, 0, 0.000479501, 0.000958313, -0.00383878, <br>> -0.00240674, 0.000963391, 0.000962464, -0.00192586, 0.000481812, <br>> -0.00241138, -0.00144963)), .Names = "V1", row.names = c(NA, <br>> -91L), class = "data.frame")<br>> <br>> #your data are very small <br>> summary(A$V1)<br>> <br>> #fit dist does not converge with parameter<br>> fitdist(A$V1,"norm",method="mge",gof="CvM")<br>> <br>> #arguments are correctly specified<br>> ?fitdist<br>> <br>> #equivalent call of mgedist -> same problem<br>> mgedist(A$V1,"norm",gof="CvM")<br>> <br>> #with uniform distribution it works<br>> fitdist(A$V1,"unif",method="mge")<br>> <br>> #as well as with mme and mle<br>> fitdist(A$V1,"norm",method="mme")<br>> fitdist(A$V1,"norm",method="mle")<br>> <br>> #so the problem comes with the mean or the sd parameters of the normal distribution.<br>> #as returns a result, sd is the problem<br>> mgedist(A$V1,"norm",gof="CvM", fix.arg=list(sd=sd(A$V1)), start=list(mean=0))<br>> <br>> #fixing a lower bound for sd returns a result<br>> mgedist(A$V1,"norm",gof="CvM", lower=c(-1, .01))<br>> <br>> #but the appropriate answer to your problem is to rescale your data.<br>> #it works perfectly.<br>> mgedist(1000*A$V1,"norm",gof="CvM", lower=c(-1, 1e-3))<br>> #we don't even need to use lower bounds.<br>> mgedist(1000*A$V1,"norm",gof="CvM")<br>> <br>> <br>> #looking at the source code of mgedist, one can see, that the distance<br>> #of Cramer von Mises is defined as follows.<br>> fnobj <- function(par, fix.arg, obs, pdistnam) {<br>> n <- length(obs)<br>> s <- sort(obs)<br>> theop <- do.call(pdistnam, c(list(q = s), as.list(par), <br>> as.list(fix.arg)))<br>> 1/(12 * n) + sum((theop - (2 * seq(1:n) - 1)/(2 * <br>> n))^2)<br>> }<br>> <br>> #a NaN is produced with negative sd <br>> fnobj(c(1,1), NULL, A$V1, pnorm)<br>> fnobj(c(mean=1,sd=1), NULL, A$V1, pnorm)<br>> fnobj(c(mean=0,sd=0), NULL, A$V1, pnorm)<br>> fnobj(c(mean=0,sd=-1), NULL, A$V1, pnorm)<br>> <br>> <br>> --<br>> Christophe Dutang<br>> Ph.D. student at ISFA, Lyon, France<br>> website: http://dutangc.free.fr<br>> <br>> Début du message réexpédié :<br>> <br>> > De : Joshua Ulrich <josh.m.ulrich@gmail.com><br>> > Date : 3 janvier 2012 04:39:47 HNEC<br>> > À : financial engineer <fin_engr@hotmail.com><br>> > Cc : r-sig-finance@r-project.org<br>> > Objet : Rép : [R-SIG-Finance] fitdist in R<br>> > <br>> > If you're going to cross-post<br>> > (http://stackoverflow.com/q/8707562/271616), please have the courtesy<br>> > to explicitly say so. Otherwise, answers to your question may be<br>> > scattered across multiple sites.<br>> > <br>> > On Mon, Jan 2, 2012 at 9:16 PM, financial engineer <fin_engr@hotmail.com> wrote:<br>> >> <br>> >> apologies if this should be a general R question, but if someone has any suggestions to fix the problem, I'd certainly appreciate it.<br>> >> <br>> > If you feel the need to start your email with an apology, you are<br>> > probably doing something wrong. You're correct, this isn't a finance<br>> > question and is therefore off-topic.<br>> > <br>> >> I am using the fitdist function in the package fitdistrplus in R.<br>> >> <br>> >> I have the following data that I read using<br>> >> A<-read.table("test.dat")`<br>> >> this is the entire dataset<br>> >>> A<br>> >> V1<br>> >> 1 -0.007077170<br>> >> 2 -0.000947418<br>> >> 3 -0.001897530<br>> >> 4 -0.000474947<br>> >> 5 -0.001902050<br>> >> 6 -0.000476077<br>> >> 7 0.002378120<br>> >> 8 0.000949668<br>> >> 9 0.000474496<br>> >> 10 0.002842260<br>> >> 11 -0.000473149<br>> >> 12 -0.000473373<br>> >> 13 0.000000000<br>> >> 14 0.000000000<br>> >> 15 0.002836880<br>> >> 16 -0.003784300<br>> >> 17 -0.004750600<br>> >> 18 -0.002383790<br>> >> 19 -0.002868070<br>> >> 20 0.000478583<br>> >> 21 0.000478354<br>> >> 22 -0.001435750<br>> >> 23 0.001435750<br>> >> 24 0.002388350<br>> >> 25 0.004284700<br>> >> 26 0.002372480<br>> >> 27 -0.001422810<br>> >> 28 -0.001424840<br>> >> 29 0.000000000<br>> >> 30 0.001424840<br>> >> 31 0.000948767<br>> >> 32 0.003786090<br>> >> 33 -0.000472478<br>> >> 34 0.000472478<br>> >> 35 -0.001418100<br>> >> 36 0.000000000<br>> >> 37 -0.000946522<br>> >> 38 -0.002844950<br>> >> 39 0.000000000<br>> >> 40 0.003318320<br>> >> 41 0.002835540<br>> >> 42 0.001414760<br>> >> 43 -0.001414760<br>> >> 44 -0.001889470<br>> >> 45 0.001417430<br>> >> 46 -0.002363510<br>> >> 47 0.002363510<br>> >> 48 0.002357940<br>> >> 49 0.002352390<br>> >> 50 -0.000940292<br>> >> 51 -0.001412100<br>> >> 52 -0.002830190<br>> >> 53 0.000472255<br>> >> 54 0.000472032<br>> >> 55 0.000471809<br>> >> 56 -0.001416100<br>> >> 57 0.001416100<br>> >> 58 -0.000943842<br>> >> 59 0.000472032<br>> >> 60 -0.000944287<br>> >> 61 -0.000945180<br>> >> 62 -0.001893040<br>> >> 63 -0.000473821<br>> >> 64 -0.000474046<br>> >> 65 0.003313610<br>> >> 66 -0.000472701<br>> >> 67 -0.000946074<br>> >> 68 0.001418780<br>> >> 69 -0.000945627<br>> >> 70 -0.001893940<br>> >> 71 -0.001897530<br>> >> 72 -0.005714300<br>> >> 73 -0.001433690<br>> >> 74 -0.003833260<br>> >> 75 0.001439190<br>> >> 76 0.000479272<br>> >> 77 -0.001918470<br>> >> 78 -0.000480192<br>> >> 79 0.000960154<br>> >> 80 0.000479731<br>> >> 81 0.000000000<br>> >> 82 0.000479501<br>> >> 83 0.000958313<br>> >> 84 -0.003838780<br>> >> 85 -0.002406740<br>> >> 86 0.000963391<br>> >> 87 0.000962464<br>> >> 88 -0.001925860<br>> >> 89 0.000481812<br>> >> 90 -0.002411380<br>> >> 91 -0.001449630<br>> >> `<br>> >> I ran the following command:<br>> >> <br>> >>> fitdist(A$V1,"norm",method="mge",gof="CvM")`<br>> >> <br>> >> and it generates the following:<br>> >> Fitting of the distribution ' norm ' by maximum goodness-of-fit<br>> >> Parameters:<br>> >> estimate<br>> >> 1 NA<br>> >> 2 NA<br>> >> Warning message:<br>> >> In pnorm(q, mean, sd, lower.tail, log.p) : NaNs produced<br>> >> <br>> >> given the above error message, I ran the below:<br>> >>> mu=mean(A$V1)<br>> >>> sigma=sd(A$V1)<br>> >>> mu<br>> >> [1] -0.0003091273<br>> >>> sigma<br>> >> [1] 0.002051825<br>> >>> pnorm(A$V1,mu,sigma)<br>> >> [1] 0.0004859313 0.3778682282 0.2194235651 0.4677942525 0.2187728328<br>> >> [6] 0.4675752645 0.9048490462 0.7302272325 0.6487379052 0.9377179215<br>> >> [11] 0.4681427154 0.4680993016 0.5598779146 0.5598779146 0.9373956798<br>> >> [16] 0.0451612910 0.0152074342 0.1559769817 0.1061704134 0.6494763806<br>> >> [21] 0.6494350178 0.2914741494 0.8024493726 0.9056899734 0.9874187360<br>> >> [26] 0.9043830715 0.2936417791 0.2933012328 0.5598779146 0.8009684336<br>> >> [31] 0.7300820807 0.9770270687 0.4682727654 0.6483730677 0.2944326177<br>> >> [36] 0.5598779146 0.3780342225 0.1082503682 0.5598779146 0.9614622560<br>> >> [41] 0.9373152170 0.7995942319 0.2949940199 0.2205866970 0.7999587855<br>> >> [46] 0.1583537921 0.9036385181 0.9031740418 0.9027096003 0.3791890228<br>> >> [51] 0.2954414771 0.1095934742 0.6483327428 0.6482924162 0.6482520879<br>> >> [56] 0.2947687275 0.7997772412 0.3785308577 0.6482924162 0.3784483801<br>> >> [61] 0.3782828856 0.2200710780 0.4680124750 0.4679688685 0.9612699580<br>> >> [66] 0.4682295443 0.3781172281 0.8001429585 0.3782000541 0.2199411992<br>> >> [71] 0.2194235651 0.0042152418 0.2918187280 0.0429384302 0.8029149383<br>> >> [76] 0.6496008197 0.2164182554 0.4667778828 0.7319136560 0.6496837100<br>> >> [81] 0.5598779146 0.6496421754 0.7316179594 0.0426934572 0.1533157552<br>> >> [86] 0.7324331764 0.7322844499 0.2153633562 0.6500594259 0.1527813896<br>> >> [91] 0.2891573876<br>> >> <br>> >> now I am confused why I am getting an error message about NaN's.......anyone have any suggestions what might be the reason....thanks, Bobby<br>> >> <br>> >> [[alternative HTML version deleted]]<br>> >> <br>> >> _______________________________________________<br>> >> R-SIG-Finance@r-project.org mailing list<br>> >> https://stat.ethz.ch/mailman/listinfo/r-sig-finance<br>> >> -- Subscriber-posting only. If you want to post, subscribe first.<br>> >> -- Also note that this is not the r-help list where general R questions should go.<br>> > <br>> > _______________________________________________<br>> > R-SIG-Finance@r-project.org mailing list<br>> > https://stat.ethz.ch/mailman/listinfo/r-sig-finance<br>> > -- Subscriber-posting only. If you want to post, subscribe first.<br>> > -- Also note that this is not the r-help list where general R questions should go.<br>> <br></div></div>
                                           </div></body>
</html>