2
votes

I have a problem using the descdist() function of the fitdistrplus package on my data frame. I think the problem comes from the data type: double. I would like to avoid the conversion to double when importing my csv, but keeping the data as a numeric (I apparently cannot convert them back using as.numeric, it remains as double after that).

Here is my code to import the dataset:

setwd("[directory]")
data=read.csv('data_BehCoor.csv', header=T, sep=";", dec=".", fill=T)

require("fitdistrplus")
descdist(data$stateTSp)

returns the following error

Error in plot.window(...) : 'xlim' needs finite values

An idea of the data:

dput(head(data))
structure(list(day = c(2L, 2L, 2L, 2L, 2L, 2L), 
trial = c(1L, 1L, 1L, 1L, 1L, 1L), ID = structure(c(2L, 2L, 3L, 3L, 4L, 4L), 
.Label = c("", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"),
 class = "factor"), 
condition = structure(c(3L, 3L, 3L, 3L, 2L, 2L), .Label = c("", 
"C", "T"), class = "factor"), gender = structure(c(3L, 2L, 
3L, 2L, 3L, 2L), .Label = c("", "F", "M"), class = "factor"), 
TSp = c(5, 3, 1, 5, 0, 6), AGR = c(3, 0, 0, 0, 0, 0), beAGR = c(0, 
3, 0, 0, 0, 0), FOR = c(27.729, 24.51, 51.459, 37.645, 34.489, 
34.281), FOR_noTSp = c(22.729, 21.51, 50.459, 32.645, 34.489, 
28.281), NI = c(39.857, 82.421, 76.922, 9.277, 265.484, 249.692
), stateTSp = c(55.858, 21.607, 0, 79.961, 0, 2.001), TSpFOR = c(20.345, 
8.408, 0, 0, 0, 0), tot_duration = c(136.967, 136.967, 128.395, 
128.395, 300, 300), OL_FOR = c(3.746, 3.746, 5.002, 5.002, 
10.081, 10.081), OL_FOR_stateTSp = c(4.563, 10.907, 41.703, 
0, 0, 0), OL_FOR_TSpFOR = c(3.372, 1.113, 0, 0, 0, 0), OL_FOR_NI = c(11.041, 
8.496, 2.748, 27.639, 19.655, 18.191), OL_stateTSp_FOR = c(10.907, 
4.563, 0, 41.703, 0, 0), OL_stateTSp = c(3.249, 3.249, 0, 
0, 0, 0), OL_stateTSp_TSpFOR = c(4.034, 0, 0, 0, 0, 0),
OL_stateTSp_NI = c(36.66, 
11.79, 0, 37.249, 0, 2.001), OL_TSpFOR_FOR = c(1.113, 3.372, 
0, 0, 0, 0), OL_TSpFOR_stateTSp = c(0, 4.034, 0, 0, 0, 0), 
OL_TSpFOR = c(0, 0, 0, 0, 0, 0), OL_TSpFOR_NI = c(18.23, 
2.499, 0, 0, 0, 0), overlap_NI_FOR = c(8.496, 11.041, 27.639, 
2.748, 18.191, 19.655), OL_NI_stateTSp = c(11.79, 36.66, 
37.249, 0, 2.001, 0), OL_NI_TSpFOR = c(2.499, 18.23, 0, 0, 
0, 0), OL_NI = c(16.065, 16.065, 6.528, 6.528, 230.021, 230.021
), AGR_in_FOR = c(0, 0, 0, 0, 0, 0), AGR_in_stateTSp = c(0, 
0, 0, 0, 0, 0), AGR_in_TSpFOR = c(0, 0, 0, 0, 0, 0), AGR_in_NI = c(3, 
0, 0, 0, 0, 0), beAGR_in_FOR = c(0, 0, 0, 0, 0, 0), beAGR_in_stateTSp = c(0, 
0, 0, 0, 0, 0), beAGR_in_TSpFOR = c(0, 0, 0, 0, 0, 0), beAGR_in_NI = c(0, 
3, 0, 0, 0, 0), comment = structure(c(1L, 1L, 1L, 1L, 1L, 
1L), 
.Label = c("", "moved the plate too fast"), class = "factor")),
 row.names = c(NA, 6L), class = "data.frame")

Thanks in advance

1
I'm afraid that the information you have provided will make it difficult for the community to help you. Can you provide more information about your data, how you are using the function and the error that is thrown out? I would suggest you to follow this post. - DJJ
yes I tried to add part of my dataset as an example but cannot find how to join it.. ^^' - SmartFish
Have a look at the link in the first comment. Sometimes copying the results of dput(head(data)) in the question might be enough. - DJJ
from your example plot(df$stateTSp) work fine. I'm pretty sure that the problem is not the double type. You probably have some NA, of Inf values in df$stateTsp. - DJJ
it imported a last line full of NAs.. now it is good, thanks ! - SmartFish

1 Answers

1
votes

fitdistrplus::descdist works fine with type double, see below:

foo <- runif(50, min = 1, max = 100)
typeof(foo)
fitdistrplus::descdist(foo)