# 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.

363 questions
Filter by
Sorted by
Tagged with
138 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: ...
197 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. ...
281 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 ...
124 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 ...
161 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 ...
7k 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 ...
75 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 ...
160 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 ...
68 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 ...
3k 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 ...
319 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 ...
125 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, ...
80 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 ...
178 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 ...
162 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 ...
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? ...
7k views

### Obtaining prediction bands for regression model

I'm trying to generate prediction bands for an exponential fit to some 2-dimensional data (available here). The data (blue points), best fit found by ...
146 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++: ...
578 views

### Standard deviation from iterators

I want this to be similar to the STL algorithms but I don't find it elegant nor concise at all: ...
146 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 ...
2k views

### Calculate odds of winning (UK) Lottery jackpot

I am interested in calculating odds of winning UK Lottery. The format is that 6 numbers from 1-59 are drawn. I am interested only (at this stage) in the odds of winning the jackpot (matching six balls)...
19k views

### More efficient way of counting the number of values within an interval?

Suppose I have a text file which contains 10,000 random values between 0 and 1, and I want to count the number of values within a specific interval. An example may explain it more clearly. Suppose ...
138 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 ...
459 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 ...
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: ...
253 views

117 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 ...
868 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 ...
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....
112 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 ...
10k 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. ...
147 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 ...
136 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 ...
506 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, ...
4k views

### Fastest computation of N likelihoods on normal distributions

In the context of a Gibbs sampler, I profiled my code and my major bottleneck is the following: I need to compute the likelihood of N points assuming they have been drawn from N normal distributions ...
426 views

### Optimize a zscore algorithm

I wrote a zscore algorithm in Ruby that runs fine, but is incredibly slow when I have 8000+ entries to score. Can anyone help me figure out a way to improve my code, please? ...
368 views

### Calculate mean, median, and mode from list of integers

I am trying to solve a problem put in The Rust Programming Language #2 Given a list of integers, use a vector and return the mean (average), median (when sorted, the value in the middle position), ...