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

stat.Quantile returns wrong value when dataset is even size #1836

Open
Iriko0606 opened this issue Nov 16, 2022 · 6 comments
Open

stat.Quantile returns wrong value when dataset is even size #1836

Iriko0606 opened this issue Nov 16, 2022 · 6 comments

Comments

@Iriko0606
Copy link

What are you trying to do?

I'm trying to get median value when I request even size of dataset to stat.Quantile

What did you do?

func main() {
	xs := []float64{2, 3, 5, 9}
	median := stat.Quantile(0.5, stat.Empirical, xs, nil)

	fmt.Println(median)
}

https://go.dev/play/p/8b6vDMunna8

What did you expect to happen?

I expect return value 4

What actually happened?

its returns 3

What version of Go and Gonum are you using?

1.19

Does this issue reproduce with the current master?

Yes

@romanwerpachowski
Copy link
Contributor

The current behaviour is consistent with the documentation. I think you will get the behaviour you want if you call Quantile with stat.LinInterp instead of stat.Empirical.

@Iriko0606
Copy link
Author

Thanks for your reply.
I've already tried it but I could not get expect value 4.
Its also returns value 3

https://go.dev/play/p/lM8ZNR0rTsi

func main() {

	xs := []float64{2, 3, 5, 9}
	median := stat.Quantile(0.5, stat.LinInterp, xs, nil)

	fmt.Println(median)
}

@romanwerpachowski
Copy link
Contributor

I see. I agree the documentation may be understood as promising a different behaviour, but I am not sure if the problem is with the code, or the documentation. @sbinet, what is your opinion?

@kortschak
Copy link
Member

kortschak commented Nov 16, 2022

I really need to not do things before my first coffee. Using the correct value in the R, this is not a bug.

> quantile(c(2, 3, 5, 9), probs=0.5, type=4)
50% 
  3 

@Iriko0606 You are looking for the R-7 behaviour. I thought we had implemented that. This should be added.

@Iriko0606
Copy link
Author

Thanks for your investigation and reply.

Is the method should be implemented as Quantile method of another case Empirical or LinInterp,
or be implemented as a Median method as a new method?

@kortschak
Copy link
Member

kortschak commented Nov 19, 2022

Yes, there should be another CumulantKind. The name than numpy uses is Internal, so that's probably a reasonable starting point. I took a look at implementing this the other day, but it's complicated by the impact of weighting.

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

3 participants