Questions tagged [statistics]

Consider whether your question would be better asked at CrossValidated, a Stack Exchange site for probability, statistics, data analysis, data mining, and machine learning. Code Review questions on statistics should be about implementation and working program review, not about theoretical discussions of statistics or research design.

Filter by
Sorted by
Tagged with
5 votes
2 answers
623 views

Kolmogorov-Smirnov function

I'm trying to compare two lists of floating point data and see if they might have come from different underlying distributions. The two samples are a before and after, so by comparing the two I ...
Sp3000's user avatar
  • 373
5 votes
1 answer
305 views

Calculate mode in Rust

I'm new to Rust and still getting used to the ownership model. I'm done with chapter 8 of the book and was trying to solve this exercise: Given a list of integers, use a vector and return the [...] ...
astral_flight_adapter's user avatar
5 votes
2 answers
145 views

A/B testing using chi-square to calculate the significance in an elegant way

The definition of ABtest Goal: For input data, each pair row is a group such as 0 and 1, 2 and 3. I want to test whether each group is significant using chi-square. If result is significant and ...
Jack's user avatar
  • 161
5 votes
2 answers
1k views

Groovy script to get average price per group from different data arrays

I've been trying to learn Groovy lately and I tried to solve a problem which involves designing a routine that will calculate the average Product price per Group. I have the following data: ...
Marcelo Tataje's user avatar
5 votes
2 answers
1k views

Simple function returning 1 if the Mean = Mode, or 0 if not

I'm trying to get better at javascript and have built a simple function that returns 1 if the mode is equal to the mean, and 0 if not. You can enter an array of numbers into the function: ...
user8758206's user avatar
5 votes
2 answers
234 views

Cross-validating Fixed-effect Model

Code Summary The following code is a data science script I've been working on that cross-validates a fixed effect model. I'm moving from R to Python and would appreciate feedback on the code below. ...
Amstell's user avatar
  • 278
5 votes
1 answer
308 views

Probability of event using Central Limit Theorem + plotting results

I've been doing a Udemy course called: "Statistics for Data Science" and I decided to solve one of the homework with Python to kill two birds with one rocket #elon. The task was: The team of ...
Mateusz Konopelski's user avatar
5 votes
2 answers
173 views

Estimating the number of tanks based on a sample of serial numbers

I created code that was supposed to determine how well my system of guessing is. The scenario is that there are n amount of tanks. Each tank is uniquely numbered 1 to n. Seven of these tanks are ...
PGODULTIMATE's user avatar
5 votes
2 answers
226 views

Pearson Correlation in Haskell

As an exercise to help me learn Haskell, I decided to write a small "program" to find the Pearson Correlation Coefficient for 2 lists of numbers. I'm pretty unhappy with how it turned out, because I ...
Jeffrey Brown's user avatar
5 votes
1 answer
897 views

Find the running median with 2 heaps

I wrote code to solve the running median challenge using 2 heaps, and I'd appreciate any and all feedback. Here is the problem: You have a list of numbers and are scanning them one by one. ...
dmr's user avatar
  • 321
5 votes
1 answer
8k views

Comparing data to model and returning a chi squared value

This is quite basic but useful to test various (9) different models using one set of data. I have tried to make it clear and use the PEP8 formatting. I am currently creating a version that can read ...
user52931's user avatar
5 votes
1 answer
90 views

Linear regression on points specified by the user in a GUI

Here's my take on the Linear Regression exercise from John Zelle's Python book. Open a window, let the user click on as many points as they want. Upon pressing the "Done" button the regression line ...
Kevin's user avatar
  • 421
5 votes
1 answer
180 views

Class Design: Calculating statistics from weighted values

I was wondering if this is the best possible design for my situation. Note that this is a simpler version of the problem I am trying to tackle. I have a class ...
Salmonstrikes's user avatar
5 votes
1 answer
83 views

Random distributions in Go with inheritance

I am currently discovering Golang, and I try to implement some random variable generation functions similar to R functions. To avoid code repetition, I'd like to use inheritance, which is quite ...
Eric Burel's user avatar
5 votes
1 answer
4k views

How is my quarterly sales statistics program?

Am I making good use of a 2-D array? Is this code inefficient? I am supposed to receive input from 6 departments for 4 quarterly periods in Java. My assignment asks: Quarterly Sales Statistics ...
eruano57's user avatar
  • 171
5 votes
1 answer
742 views

Monte-carlo simulation code - simple exercise

I created a quick monte-carlo simulation which seems to do what I want (simple version below). The code basically simulates a Poisson distribution, say this results in a simulation of ...
lmkir99's user avatar
  • 53
5 votes
1 answer
292 views

Linear Regression in Haskell

After quite some time away from Haskell I am trying to brush up. To do so I am writing some basic linear regression functionality. The code produces the output expected. In essence I am trying to ...
Robert Long's user avatar
5 votes
1 answer
2k views

Select array element by its weight/probability

I coded a function that takes an array with numbers and randomly chooses one of these numbers (Returns the index of the chosen one). The value of each number works as an weight which determines the ...
Alan Vinícius's user avatar
5 votes
1 answer
193 views

Gamblers ruin, parallel compute trials

Context The following script is a quick implementation of the gambler's ruin problem. For each given upper bound on the number of rounds in a game max_iter, ...
Quetzalcoatl's user avatar
5 votes
1 answer
88 views

Fetch, plot, and send security incident statistics with Excel

TLDR: I don't develop for a living. If someone could point me in the right direction to make my script more readable/pythonic I would appreciate the assistance. In particular I'm struggling with the ...
ImNotLeet's user avatar
  • 161
5 votes
1 answer
252 views

Simulating coin flips and plotting a histogram

I started playing around recently with F# and I find it quite elegant and succinct language. A common problem I like to solve in every language I start to learn is the coin flip problem, with the ...
gdyrrahitis's user avatar
5 votes
1 answer
206 views

Using NumPy to scale data in 2 out of 3 columns

The below code takes a csv containing age, weight, height and prints the betas determined through linear regression to an output csv. It runs for 10 iterations using a different alpha for each, and ...
user7875185's user avatar
5 votes
1 answer
2k views

Rolling z-score function in R

I have written a rolling z-score function myself. Is my implementation of rolling z-score function correct? ...
Eka's user avatar
  • 349
5 votes
1 answer
199 views

A simple probabilistic AI for generating random sentences in Java

Motivation I have this repository. It contains a program that analyzes an input text file and builds a word graph: in the graph, each node represents a word in the analyzed text. Now, if there are two ...
coderodde's user avatar
  • 28.1k
5 votes
1 answer
159 views

Shoe shine shop model in Rust and C++ - Follow-up

I've just refactored my Rust and C++ code which simulates the shoeshine shop model from this question. What else can be improved? C++: ...
rogday's user avatar
  • 403
5 votes
0 answers
169 views

Kernel density regression in Julia

Here is a naive implementation of a kernel density regression algorithm in Julia. The code works, but there is quite a bit of room for improvement though. First, there is not an optimal bandwidth ...
Vincent's user avatar
  • 561
4 votes
4 answers
147 views

Statistics Library with Sample, SampleBuilder and Tests

Introduction I'm working on a Statistics Library that can record observations and produce a Summary of the statistics when there's enough observations. Right now, it's at its early stages and is ...
Hungry Blue Dev's user avatar
4 votes
2 answers
476 views

Two-way ANOVA table

I changed some methods used previously, and I am wondering if I need to do the multiple for loops over and over again. How do I convert my arrays to lists to use in nested ...
Next Door Engineer's user avatar
4 votes
2 answers
5k views

Pearson Correlation in Python

I have written the following code and I am new to Python. Please let me know if I can make improvements to the following program: ...
xyz's user avatar
  • 185
4 votes
2 answers
323 views

Randomly generate a list with predetermined mean

Aim: randomly generate \$n\$ numbers between \$a\$ and \$b\$ with (roughly) mean \$m\$. Problem: The simple beginner's code I wrote becomes very inefficient as \$m\$ moves away from \$\frac{a + b}{2}\...
user2738815's user avatar
4 votes
2 answers
6k views

Computing the standard deviation of a Number array in Java

(See the next iteration.) I have this funky class method for computing standard deviation from an array of Number objects using the Stream API: StandardDeviation....
coderodde's user avatar
  • 28.1k
4 votes
2 answers
3k views

C++ Int Array/Vector Over 100 Million

Textbook style program that generates the values of two, six-sided dice; which are used to perform simple calculations. Recently, I saw an example using similar criteria that was able to utilize 360,...
Austin's user avatar
  • 125
4 votes
2 answers
15k views

Calculating and displaying number statistics

I'm writing a program which takes individual int inputs from the user and then outputs some details on the numbers (average, min, max and how many). Input.readInt() ...
BradStevenson's user avatar
4 votes
2 answers
134 views

Query to plot a histogram of song ratings

I wrote code to plot a rating distribution, which looks like this: The most important function is the stats function: ...
K. P.'s user avatar
  • 243
4 votes
1 answer
717 views

Concise Proof of the Monty Hall Problem in R

This is an attempt at a concise proof of the Monty Hall problem in probability and statistics in R. For those unfamiliar, the scenario is this: There exists a contestant on a game show. This ...
Miller's user avatar
  • 533
4 votes
3 answers
412 views

Estimating the number of tanks based on a sample of serial numbers 2.0

There was some confusion with the code I had posted in my previous version of this question and there was some good advice from @Oscar Smith. The explanation is the same; please give improvements for ...
PGODULTIMATE's user avatar
4 votes
2 answers
1k views

Calculate Geometric and Arithmetic Mean

I am trying to make general class to calculate Geometric mean using exponential of the arithmetic mean of logarithms , and Arithmetic Mean. I am looking for some general feedback on how I can improve ...
Eslam Ali's user avatar
  • 433
4 votes
4 answers
215 views

Find the locally biggest or equal values including corners in an array

I am looking for a function, that will find in array of n integers highest or equal locally values including corners. My code is probably wrong, and I somehow think solution is in some library like ...
Michał Piotr Stankiewicz's user avatar
4 votes
3 answers
211 views

Classifying rows of data by the number of days to close

DataTable looks like below I would like to simplify this code in a better manner. ...
SivaRajini's user avatar
4 votes
2 answers
5k views

Optimization for histogram computation algorithm in C

Next is an algorithm to calculate the histogram for a given YUV420sp image. The YUV data is given by the hardware camera as an unsigned char*. The algorithms ...
Perraco's user avatar
  • 615
4 votes
1 answer
1k views

Statistical samples and distributions

It is usually inefficient to find bugs in a longer code. Unfortunately, after spending too much time in debugging my code, I realize that a good programming habit is important. Please give me some ...
fishiwhj's user avatar
  • 341
4 votes
2 answers
398 views

Simple and efficient data structure for standard deviation queries in Java

I have this data structure to which the user can add number or remove them, both in constant time. Also, there is a \$O(1)\$ operation for querying the standard deviation of the current contents of ...
coderodde's user avatar
  • 28.1k
4 votes
2 answers
1k views

Rolling 100-sided "dice" until they are the same number

I've just begun my journey into python (1 week now) and I've written couple of lines incorporating everything I've learned so far. It would be greatly appreciated if anyone could guide me in writing a ...
John Lee's user avatar
4 votes
1 answer
1k views

Finding the similarity between the two movies using Pearson correlation coefficient

I am trying to find the similarity between the two movies using Pearson correlation coefficient. The programs is working well for small inputs but for large inputs (like 100000 lines) it takes forever....
Praveen Allam's user avatar
4 votes
3 answers
118 views

Extracting sleep quality scores from periodic readings

How can I optimize the next function to work faster? The function must prepare a list to put in a CSV file. The list must contain values of average percentage of sleep per minute counted from ...
Pavel  Shlepnev's user avatar
4 votes
1 answer
11k views

Building a histogram array in PHP

I'm visualizing my stored data in an histogram similar to this one: However, I'm sure that my code smells a lot! So I'd like to have your opinion on how to make it better. ...
ILikeTacos's user avatar
4 votes
1 answer
212 views

Modelling of partcle flow under electric field

This is my first modeling exercise on the particle flow. Recently, I read a paper https://acp.copernicus.org/articles/20/3181/2020/. After reading the paper, thought of modeling it in Python. It seems ...
Vishal's user avatar
  • 43
4 votes
2 answers
128 views

Block Bootstrap Estimation using Java

The data are in a file called test.txt, which is available at https://drive.google.com/file/d/1g0ffvH5oP5C4Cp6ciEp_L1Rst6WeTuYG/view?usp=sharing. There are some odd ...
Clarinetist's user avatar
4 votes
2 answers
151 views

On-line evaluation of mean and variance in C#

In various projects, I have to evaluate the mean and/or the variance of relatively large samples. I wrote the following, to help me evaluate these quantities with a constant footprint. Basically, it ...
RUser4512's user avatar
  • 1,033
4 votes
1 answer
628 views

Non-overflowing avg calculation with integer arithmetic

I have multiple long values and I want to calculate their average value using integer arithmetic, without precision loss and using java rounding rules for division, ...
basin's user avatar
  • 141

1 2
3
4 5
8