[R] Problem with fitdistr function

Peter Dalgaard p.dalgaard at biostat.ku.dk
Sat Feb 9 11:06:02 CET 2008


Aswad Gurjar wrote:
> Hello,
>
> I am using fitdistr function for parameter estimation.
>  When I use
> fd<-fitdistr(V2,"gamma")
> I get following error:
> Error in optim(x = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,  :
>         initial value in 'vmmin' is not finite
>
>   fd<-fitdistr(V2,"weibull")
> Error in optim(x = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,  :
>         non-finite value supplied by optim
>
> But if I use following I dont get any errors.
> fd<-fitdistr(V2,"exponential")
>
> I have included necessary libraries.
> How can i remove this error?Are there any restrictions in using fitdistr
> function?If yes is there any alternative approach for solving such problem?
> My aim is to get estimated value of parameters.
>
>   
The density of a gamma distribution can be infinite at zero, so fitting 
to data with exact zeros is asking for trouble. Probably the sanest way 
to handle this sort of data is to treat the zeroes as left-censored 
observations, i.e. for x=0 use pgamma(0.5,....) instead of 
dgamma(0,....). I think fitdistr() will do this if you set up the 
"density" appropriately.

> Data is as follows:
> N
>        V1  V2
> 1   32400   0
> 2   32460   0
> 3   32520   0
> 4   32580   0
> 5   32640   0
> 6   32700   0
> 7   32760   0
> 8   32820   0
> 9   32880   0
> 10  32940   0
> 11  33000   0
> 12  33060   0
> 13  33120   0
> 14  33180   0
> 15  33240   0
> 16  33300   0
> 17  33360   0
> 18  33420   0
> 19  33480   0
> 20  33540   0
> 21  33600   0
> 22  33660   0
> 23  33720   0
> 24  33780   0
> 25  33840   0
> 26  33900   0
> 27  33960   0
> 28  34020   0
> 29  34080   0
> 30  34140   0
> 31  34200   0
> 32  34260   0
> 33  34320   0
> 34  34380   0
> 35  34440   0
> 36  34500   0
> 37  34560   0
> 38  34620   0
> 39  34680   0
> 40  34740   0
> 41  34800   0
> 42  34860   0
> 43  34920   0
> 44  34980   0
> 45  35040   0
> 46  35100   0
> 47  35160   0
> 48  35220  32
> 49  35280   0
> 50  35340   0
> 51  35400   0
> 52  35460   0
> 53  35520   0
> 54  35580   0
> 55  35640   0
> 56  35700   0
> 57  35760   0
> 58  35820   0
> 59  35880   0
> 60  35940   0
> 61  36000   0
> 62  36060   0
> 63  36120  31
> 64  36180  32
> 65  36240   0
> 66  36300   0
> 67  36360   0
> 68  36420   0
> 69  36480   0
> 70  36540   0
> 71  36600   0
> 72  36660   0
> 73  36720   0
> 74  36780   0
> 75  36840   0
> 76  36900   0
> 77  36960   0
> 78  37020   0
> 79  37080   0
> 80  37140   0
> 81  37200   0
> 82  37260   0
> 83  37320   0
> 84  37380   0
> 85  37440   0
> 86  37500   0
> 87  37560   0
> 88  37620   0
> 89  37680   0
> 90  37740   0
> 91  37800   0
> 92  37860   0
> 93  37920  32
> 94  37980   0
> 95  38040   0
> 96  38100   0
> 97  38160   0
> 98  38220   0
> 99  38280   0
> 100 38340   0
> 101 38400   0
> 102 38460   0
> 103 38520   0
> 104 38580   0
> 105 38640   0
> 106 38700   0
> 107 38760   0
> 108 38820  32
> 109 38880  32
> 110 38940  32
> 111 39000   0
> 112 39060   0
> 113 39120   0
> 114 39180   0
> 115 39240   0
> 116 39300   0
> 117 39360   0
> 118 39420   0
> 119 39480   0
> 120 39540   0
> 121 39600   0
> 122 39660   0
> 123 39720  32
> 124 39780  32
> 125 39840  77
> 126 39900   0
> 127 39960   0
> 128 40020   0
> 129 40080   0
> 130 40140   0
> 131 40200   0
> 132 40260   0
> 133 40320   0
> 134 40380   0
> 135 40440   0
> 136 40500   0
> 137 40560   0
> 138 40620  32
> 139 40680  32
> 140 40740 109
> 141 40800  67
> 142 40860  92
> 143 40920   0
> 144 40980   0
> 145 41040   0
> 146 41100   0
> 147 41160   0
> 148 41220   0
> 149 41280   0
> 150 41340   0
> 151 41400   0
> 152 41460   0
> 153 41520 112
> 154 41580   0
> 155 41640   0
> 156 41700   0
> 157 41760   0
> 158 41820   0
> 159 41880   0
> 160 41940   0
> 161 42000   0
> 162 42060   0
> 163 42120   0
> 164 42180   0
> 165 42240   0
> 166 42300   0
> 167 42360   0
> 168 42420   0
> 169 42480   0
> 170 42540  66
> 171 42600   0
> 172 42660  93
> 173 42720   0
> 174 42780   0
> 175 42840   0
> 176 42900   0
> 177 42960   0
> 178 43020   0
> 179 43080   0
> 180 43140   0
> 181 43200   0
> 182 43260   0
> 183 43320   0
> 184 43380   0
> 185 43440   0
> 186 43500   0
> 187 43560   0
> 188 43620   0
> 189 43680 138
> 190 43740   0
> 191 43800   0
> 192 43860   0
> 193 43920   0
> 194 43980   0
> 195 44040   0
> 196 44100   0
> 197 44160   0
> 198 44220   0
> 199 44280   0
> 200 44340   0
> 201 44400   0
> 202 44460   0
> 203 44520   0
> 204 44580   0
> 205 44640   0
> 206 44700   0
> 207 44760   0
> 208 44820   0
> 209 44880   0
> 210 44940   0
> 211 45000   0
> 212 45060   0
> 213 45120  69
> 214 45180  90
> 215 45240   0
> 216 45300   0
> 217 45360 112
> 218 45420   0
> 219 45480   0
> 220 45540   0
> 221 45600  87
> 222 45660   0
> 223 45720  97
> 224 45780   0
> 225 45840   0
> 226 45900   0
> 227 45960   0
> 228 46020   0
> 229 46080   0
> 230 46140   0
> 231 46200   0
> 232 46260   0
> 233 46320  92
> 234 46380   0
> 235 46440   0
> 236 46500   0
> 237 46560   0
> 238 46620   0
> 239 46680   0
> 240 46740   0
> 241 46800   0
> 242 46860   0
> 243 46920   0
> 244 46980   0
> 245 47040   0
> 246 47100   0
> 247 47160   0
> 248 47220   0
> 249 47280   0
> 250 47340   0
> 251 47400   0
> 252 47460   0
> 253 47520   0
> 254 47580   0
> 255 47640   0
> 256 47700   0
> 257 47760   0
> 258 47820   0
> 259 47880   0
> 260 47940   0
> 261 48000   0
> 262 48060   0
> 263 48120   0
> 264 48180   0
> 265 48240   0
> 266 48300   0
> 267 48360   0
> 268 48420   0
> 269 48480   0
> 270 48540   0
> 271 48600   0
> 272 48660   0
> 273 48720   0
> 274 48780   0
> 275 48840   0
> 276 48900   0
> 277 48960   0
> 278 49020   0
> 279 49080   0
> 280 49140   0
> 281 49200   0
> 282 49260   0
> 283 49320   0
> 284 49380   0
> 285 49440   0
> 286 49500   0
> 287 49560   0
> 288 49620  32
> 289 49680  32
> 290 49740   0
> 291 49800   0
> 292 49860   0
> 293 49920   0
> 294 49980  33
> 295 50040   0
> 296 50100   0
> 297 50160   0
> 298 50220   0
> 299 50280   0
> 300 50340   0
> 301 50400   0
> 302 50460   0
> 303 50520 102
> 304 50580   0
> 305 50640   0
> 306 50700   0
> 307 50760 100
> 308 50820   0
> 309 50880   0
> 310 50940   0
> 311 51000   0
> 312 51060   0
> 313 51120   0
> 314 51180   0
> 315 51240   0
> 316 51300   0
> 317 51360   0
> 318 51420  32
> 319 51480  32
> 320 51540   0
> 321 51600   0
> 322 51660   0
> 323 51720   0
> 324 51780   0
> 325 51840   0
> 326 51900   0
> 327 51960   0
> 328 52020   0
> 329 52080   0
> 330 52140   0
> 331 52200   0
> 332 52260   0
> 333 52320   0
> 334 52380   0
> 335 52440   0
> 336 52500   0
> 337 52560   0
> 338 52620   0
> 339 52680   0
> 340 52740   0
> 341 52800   0
> 342 52860   0
> 343 52920   0
> 344 52980   0
> 345 53040   0
> 346 53100   0
> 347 53160   0
> 348 53220   0
> 349 53280   0
> 350 53340   0
> 351 53400   0
> 352 53460   0
> 353 53520   0
> 354 53580   0
> 355 53640   0
> 356 53700   0
> 357 53760   0
> 358 53820   0
> 359 53880   0
> 360 53940   0
> 361 54000   0
> 362 54060   0
> 363 54120   0
> 364 54180   0
> 365 54240   0
> 366 54300   0
> 367 54360   0
> 368 54420   0
> 369 54480   0
> 370 54540   0
> 371 54600   0
> 372 54660   0
> 373 54720   0
> 374 54780   0
> 375 54840   0
> 376 54900   0
> 377 54960   0
> 378 55020   0
> 379 55080   0
> 380 55140   0
> 381 55200   0
> 382 55260   0
> 383 55320   0
> 384 55380   0
> 385 55440   0
> 386 55500   0
> 387 55560   0
> 388 55620   0
> 389 55680   0
> 390 55740   0
> 391 55800   0
> 392 55860   0
> 393 55920   0
> 394 55980   0
> 395 56040   0
> 396 56100   0
> 397 56160   0
> 398 56220   0
> 399 56280   0
> 400 56340   0
> 401 56400   0
> 402 56460   0
> 403 56520   0
> 404 56580   0
> 405 56640   0
> 406 56700   0
> 407 56760   0
> 408 56820   0
> 409 56880   0
> 410 56940   0
> 411 57000   0
> 412 57060   0
> 413 57120   0
> 414 57180   0
> 415 57240   0
> 416 57300   0
> 417 57360   0
> 418 57420   0
> 419 57480   0
> 420 57540   0
> 421 57600   0
>
>
> Thank You.
>
>
> Aswad
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>   


-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907



More information about the R-help mailing list