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
1answer
159 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 ...
5
votes
1answer
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 ...
5
votes
1answer
56 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 ...
5
votes
1answer
103 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, ...
5
votes
1answer
77 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 ...
5
votes
1answer
153 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 ...
5
votes
1answer
138 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 ...
5
votes
1answer
6k 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 ...
5
votes
1answer
140 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++: ...
5
votes
2answers
510 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: ...
5
votes
1answer
76 views

Random bits with a specified density (Bernoulli Trials)

I'm sure this is a fully 'solved' problem and expecting cross references but I can't find this on Google. I'm probably missing a keyword. Here is a naive function for populating a ...
5
votes
0answers
58 views

Return probability (Javascript)

I've been working on a personal project. There's this game called TFT which is an autochess game. Each match is played by 8 players and there's a shared pool of champions, each champion have their ...
5
votes
0answers
1k 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? ...
5
votes
0answers
134 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 ...
4
votes
4answers
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)...
4
votes
4answers
17k 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 ...
4
votes
4answers
126 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 ...
4
votes
2answers
451 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 ...
4
votes
2answers
4k 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: ...
4
votes
2answers
244 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}\...
4
votes
2answers
2k 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,...
4
votes
2answers
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() ...
4
votes
2answers
90 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: ...
4
votes
1answer
317 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 ...
4
votes
3answers
319 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 ...
4
votes
2answers
937 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 ...
4
votes
4answers
209 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 ...
4
votes
3answers
207 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. ...
4
votes
2answers
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 ...
4
votes
1answer
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 ...
4
votes
2answers
291 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 ...
4
votes
2answers
351 views

Extracting the five most frequent queries from a log file

I'm trying to print the top 5 most queried strings from a text file. I can't use other third-party libraries to make it easier w.r.t hashmap implementations. I need to improve on these if possible: ...
4
votes
2answers
112 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 ...
4
votes
2answers
713 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 ...
4
votes
1answer
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....
4
votes
3answers
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 ...
4
votes
1answer
9k 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. ...
4
votes
2answers
134 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 ...
4
votes
1answer
530 views

Coin flips and Dice rolls in a stored procedure

I saw a post in chat a few days ago, of what I thought was an interesting (albeit fairly simple) statistical challenge: By @skiwi: If I shoot once with 50% chance of target A and 50% of target B, ...
4
votes
1answer
344 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, ...
4
votes
2answers
146 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 ...
4
votes
1answer
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 ...
4
votes
1answer
394 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? ...
4
votes
1answer
4k views

Compute Gini Coefficient

Recently, I was given a math assignment to calculate Gini Indexes for a table of percent distributions of aggregate income. The table takes the form of: ...
4
votes
1answer
688 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. ...
4
votes
1answer
66 views

Average calculator with filters

I am a beginner in Java and I have a hobby project to create a tool for statistical calculations. Users can upload csv with results of a survey. The responses stored in a ...
4
votes
1answer
62 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 ...
4
votes
2answers
2k views

Find median of two sorted arrays

Problem statement There are two sorted arrays nums1 and nums2 of size m and ...
4
votes
3answers
268 views

Rating normalization algorithm

I have a rating system where users can vote between 1-6. I'd like to normalize the votes a bit to better accommodate for extreme voting, where individuals tend to vote as high or as low as possible. ...
4
votes
1answer
353 views

Bernoulli trials using a condition in a vectorized operation

I was wondering how to vectorize the following code instead of using the for-loop and still be able to check for a condition. ...

1 2
3
4 5
8