Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fBoxplot: error if length(outliers_id) == 1 (line 85) #7

Closed
byandell opened this issue Sep 29, 2022 · 13 comments
Closed

fBoxplot: error if length(outliers_id) == 1 (line 85) #7

byandell opened this issue Sep 29, 2022 · 13 comments

Comments

@byandell
Copy link

https://github.com/myllym/GET/blob/master/R/fboxplot.r

I had error tracked down to line 85 of fBoxplot
outliers <- funcs[,outliers_id]

Error in colnames<-(*tmp*, value = 15L) :
attempt to set 'colnames' on an object with less than two dimensions

if length(outliers_id) == 1, then outliers becomes a vector in recent R versions. Line 87 tries to set colnames:
colnames(outliers) <- outliers_id

solution would be
outliers <- funcs[,outliers_id, drop = FALSE]

See for instance
https://stackoverflow.com/questions/47754509/how-to-use-drop-f-correctly-in-r-to-preserve-matrix-structure-when-subsetting

There may be other issues like this? Brian

@myllym
Copy link
Owner

myllym commented Sep 29, 2022

Thank you very much for reporting this, and for your hint. The error in fBoxplot is now fixed in the development version available here. I will check if I can find any other issues like this, thank you. -Mari

@byandell
Copy link
Author

byandell commented Sep 29, 2022 via email

@byandell
Copy link
Author

byandell commented Sep 30, 2022 via email

@myllym
Copy link
Owner

myllym commented Sep 30, 2022

Dear Brian,

Thank you again. I tried to reproduce your example, as follows, but I was not able to replicate your problem.

r <- seq(0,756,by=3)
funcs <- cbind(seq(0,126,by=0.5), seq(0,126,by=0.5))
curve_set <- create_curve_set(list(r=r, obs=funcs))
forder(curve_set, measure = "area")

Here the equal curves get equal values of the measure (0.5, 0.5 in the above example), too. Is something missing from this example? Could you try to send your example curve_set again for my further testing? I could not find it attached here. Thanks.

Best,
Mari

@byandell
Copy link
Author

byandell commented Oct 1, 2022 via email

@myllym
Copy link
Owner

myllym commented Oct 2, 2022

Thanks! Right, I was missing a condition on the required number of functions in forder. For a moment I thought that also the case of two functions is handled, even though ordering just two functions with these methods do not really make much sense. Namely,

  • If there are only two functions, both of these functions are always the most extreme one for each value of r as measured by a normal rank, in the case of two-sided alternative (the case of measure 'rank' or 'erl'). In this case, it is possible to calculate the measures, but the measures should always be the same for the two functions, i.e. no decision on the order of two functions can be given.
  • The measures 'cont' & 'area' are based on continuous pointwise ranks and then the minimum number of functions needed to make any calculation is 3.

I will add a condition on the number of functions. Thanks for noting that this is missing.
Do you truly have some case where you would like to obtain the ordering measures just for two functions, or it was just experimenting?

-Mari

@myllym
Copy link
Owner

myllym commented Oct 2, 2022

I added the check to forder and it appears in the development version here. Thank you for reporting this and any other problems that you might find. -Mari

@byandell
Copy link
Author

byandell commented Oct 3, 2022 via email

@byandell
Copy link
Author

byandell commented Oct 4, 2022 via email

@myllym
Copy link
Owner

myllym commented Oct 5, 2022

Dear Brian,
The package uses ggplot for the plotting. There is a default title, but it can be modified. Namely, the plotting function returns a ggplot object, which can be modified. So, e.g.,

library(fda)
years <- paste(1:18)
curves <- fda::growth[['hgtf']][years,]
cset1 <- create_curve_set(list(r = as.numeric(years),
obs = curves))
bp <- fBoxplot(cset1, coverage=0.50, type="area", factor=1)
plot(bp)
plot(bp) + ggtitle("My title")

The same holds, for example, for the x and y labels. Example of that given in ?fBoxplot.
The other thing I must think further.

-Mari

@byandell
Copy link
Author

byandell commented Oct 5, 2022 via email

@myllym
Copy link
Owner

myllym commented Oct 9, 2022

Dear Brian,

Some updates

  1. Now the continuous ranks work are defined also for just 1 or 2 functions. Although ordering these functions do not make much sense here, it can be nice that the function returns anyway a result. Thanks to @mikkoku!

  2. The checks "if(length(class(curve_sets)) == 1 && inherits(curve_sets, "list"))" were/are for checking whether the user has provided a curve_set (or object that can be converted to a curve_set) or a list of curve_sets. In the latter case, the curves of the different curve_sets are ordered jointly. I agree this check looked somewhat cryptic, and I have now recoded the above as "!is_a_single_curve_set(curve_sets)", where is_a_single_curve_set is now a helper function that checks if the object given inherits either curve_set or something else that can currently be converted to a curve_set.

  3. It seems that there is no problem to add "curve_set" and "fclust" objects to have also the class "list", and I did this. I just had not realised that it might be needed.

All these are just in this development version at the moment and up to further changes.

Kind regards,
Mari

@byandell
Copy link
Author

byandell commented Oct 10, 2022 via email

@myllym myllym closed this as completed Nov 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants