Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

44
votes
3answers
5k views

Benchmarking things in C#

I needed a better way to benchmark code, because, well, rewriting the same benchmarking code every time I need it is just...well...unpleasant. So, here's a class which does just that, it runs an <...
43
votes
8answers
6k views

Prettify math formula in code

I have a function to calculate the normal distribution in Python: ...
31
votes
4answers
1k views

Standardly deviated Fibonacci

I'm new to C++ (about 4 weeks with no prior programming experience in other languages) and am writing a program that's supposed to do the following: Define an array of 100 sequential numbers of type <...
30
votes
6answers
4k views

Unbreakable average program

I'm creating a program that averages four numbers - three from a file and one from user input. Simple enough. But the catch is, the professor is going to be deliberately trying to break the program. ...
26
votes
3answers
18k views

Calculate a median

I got this as an implementation of "get me the median of those values". But it sort of doesn't feel right (too long, too many branch points) so I thought I'll post it here to see what you think. <...
22
votes
4answers
5k views

C++ Coin flip simulator and data collector

Asks the user for the chance of a coin landing on heads, the number of trials per experiment, and the number of experiments. For example, given 5 trials per experiment and 20 experiments, the program ...
19
votes
1answer
373 views

Alea implementation

The following is an implementation of the Alea random number generation approach by Johannes Baagøe, reworked from the rot.js implementation by dropping all the pesky underscore prefixes in the ...
16
votes
3answers
2k views

Newton-Pepys, common birthdays and other probability simulations in Python 3

I have been learning Probability from Statistics 110 and trying to simulate problems that have an unintuitive answer ...
15
votes
2answers
532 views

Counting density of Python code

I created a tool to examine Python 3 source code. It measures the density of program. More info in docstring (to not reinvent the wheel). What could be done to increase its usability? Any edge cases ...
13
votes
5answers
26k views

Chi Square Independence Test for Two Pandas DF columns

I want to calculate the scipy.stats.chi2_contingency() for two columns of a pandas DataFrame. The data is categorical, like this: ...
12
votes
3answers
9k views

Calculating Standard Deviations

We were discussing Standard Deviations in chat, so I decided to write a standard deviation calculator: ...
12
votes
1answer
4k views

Calculate mean, median, and mode in Rust

I'm learning Rust using The Rust Programming Language. I'm trying the assignment at the end of chapter 8 — Hash Maps. The task is: Given a list of integers, use a vector and return the mean (...
11
votes
3answers
2k views

Calculate min, max, mean and median out of array

Another C exercise: Write a function that takes an array of 'ints' as its input and finds the smallest and largest elements. It should also compute the median and mean. Use a ...
11
votes
1answer
786 views

Calculating and displaying score statistics using C# 6.0 features

I'm studying C# and trying to work on efficiency and making the best use of C# 6.0 features. I have created the following program based on an exercise challenge in a book, and have used Resharper to ...
11
votes
3answers
554 views

Meta-programming template for collection statistics

I find that I often want to calculate summary statistics from collections of data and decided to create a template to do that. I'm interested in a general review, but I also have some specific ...
11
votes
3answers
142 views

Compute mean and variance, incrementally

I have previously reviewed code that computes standard deviation using the mathematical formula E(x²) - E(x)², and warned against the use of this formula because floating-point precision is severely ...
11
votes
1answer
1k views

Lotto simulator

With the recent craziness of the Powerball in the US, I got interested in building a little lotto simulator to see how frequently I could win with purchasing large amounts of tickets. For those not ...
11
votes
1answer
135 views

C++ thread-safe averaging

Although having very little C++ experience, I was tasked to implement several statistics objects that are safe to be asynchronous accessed by different threads, that collect data in relatively small ...
10
votes
6answers
2k views

Median Calculator

This is just a simple median calculator that calculates the median for a given array/list. ...
10
votes
2answers
26k views

Calculating population standard deviation

This is a script I have written to calculate the population standard deviation. I feel that this can be simplified and also be made more pythonic. ...
10
votes
2answers
609 views

Powerball Lottery Simulator in C

I made a Powerball lottery simulator in C. I chose C because it is fast. Here's how it plays: The user plays one ticket every day. The user can choose to play the same ticket every day or a ...
10
votes
1answer
655 views

Computing average without overflows and with half-decent precision

At some point I needed to compute the average of a big collection of integers. I knew the size of the collection prior computation, but a naive average computation was prone to integer overflow while ...
9
votes
4answers
2k views

Program to accept numbers, then calculate the mean, median, and range

I created a basic program that allows a user to continuously input values until he or she is satisfied; furthering, the program outputs the mean, median, and range. Then, the code gives you the option ...
9
votes
4answers
183 views

A bag of numbers in C++ for constant time statistics queries - follow-up

(See the previous iteration.) (See the next iteration.) I have a simple "data structure" for storing numbers and querying the statistics on them (average, variance and standard deviation). Now I ...
8
votes
4answers
3k views

Calculate sum, mean, sum of squares, and standard deviation of array elements

Also, I've commented out a function I was trying to do to count the elements of an array; I realized that is not possible due to the fact that I won't be be able to return a NULL on an array. ...
8
votes
3answers
170 views

Python program to calculate statistics for laboratory data

I am new in Python, but I have laboratory work with some routine computing, so I have decided do these calculations in Python. Program input is physical characteristic, measured several times (i.e ...
8
votes
4answers
16k views

Finding the mode of an array

I am a beginner in JavaScript and just wanted to get my code reviewed. Here I have created a function that takes in an array and returns the mode. If there is no more then I just want the function to ...
8
votes
2answers
1k views

Algorithms to find statistical information of an array

I was working on a program that creates an array, then gives statistical information about that array such as std dev, median, mode average etc. I have written a method for each statistical value, ...
8
votes
3answers
905 views

Deviating from the norm

Back on track with my C++ saga: The standard deviation of a list of numbers is a measure of how much the numbers deviate from the average. If the standard deviation is small, the numbers are ...
8
votes
2answers
448 views

Sparse 3D binning/histogram function

This is a function written in Python I wrote to process galaxy catalogs for cosmology research, however it is more generally applicable than just my pipeline. The goal is to take a Python list of ...
8
votes
3answers
561 views

Statistical calculations with sets of genes

The following piece of code executes 20 million times each time the program is called, so I need a way to make this code as optimized as possible. ...
8
votes
1answer
105k views

Create a struct to store student data and perform statistical analysis on data

I had to create a program that had a struct that held data inside of it. I had to read an input file and take the contents and read it into an array of structs. Then, I had to solve for some ...
8
votes
1answer
6k views

Moving average calculation

I am hoping to make this method run a little faster. I typically need to run this on a list with more than 100000 entries. Note that at the start and end of the list, I wish to weight the average so ...
8
votes
2answers
2k views

Average movie rankings

Given a list of tuples of the form, (a, b, c), is there a more direct or optimized for calculating the average of all the c's ...
8
votes
1answer
47 views

Python implementation of approximating the chance a particle is at a location after n steps in the cardinal directions

Recently, I became very interested in a probability practice problem in my textbook for my class. I decided to implement it in code and I think I got most of it implemented. Right now, I'm hoping to ...
8
votes
1answer
26k views

Calculate min, max, average, and variance on a large dataset

I got a piece of Java code using Hadoop to calculate min, max, average and variance on a large dataset made of (index value) couples separated by a newline: ...
8
votes
1answer
269 views

R function for Dynamic Ordinary Least Squares regression

SHORT VERSION: Made a workflow function, want a better output with methods. General Background I have been working on a package for some time to eliminate the tedium of preliminary time series ...
7
votes
2answers
1k views

Simple average grade calculator

I'd like this code to be minimized, while displaying the exact same stuff. Specifically, on how to remove some of the repetitions made within the code (such as "if, else if") etc. using other ...
7
votes
4answers
173 views

Summarizing calories for a food diary

I'm new to C and I've been working on some code for a project for school. This was the finished result and now that I'm done it, I came back and tried making it better. So I was wondering, how would I ...
7
votes
4answers
757 views

Median Calculation of List of Integers without using heap

References Using those references: rolling median implementations benchmark FAST RUNNING MEDIAN USING AN INDEXABLE SKIPLIST Calculate the median of a billion numbers Find running median from a ...
7
votes
3answers
161 views

Find the fastest run of each year from a list of running results

Problem Explained: Imagine there is a list of running results of 1000m, like following: ...
7
votes
4answers
1k views

Fast evaluation of Euclidean distance with sparse data

I am working on a KNN implementation for sparse datasets (that I apply to text analysis). My points are represented by a Dictionary<string, double>, each key ...
7
votes
2answers
1k views

Several math calculation functions

The code I have created calculates an arrangement of math calculation functions, and I would like to see if there is any way I could improve it, especially the calculator function. The guide function ...
7
votes
2answers
5k views

Mean, Median and Mode of a QVector

I would like some help condensing this code down to size. I am trying to utilize Qt's container classes as efficiently as possible. I do not believe this code reflects my objective. ...
7
votes
2answers
325 views

Monte Carlo estimation of the Hypergeometric Function

I am trying to implement the algorithm described in the paper Statistical Test for the Comparison of Samples from Mutational Spectra (Adams & Skopek, 1986) DOI: 10.1016/0022-2836(87)90669-3: $$p =...
7
votes
2answers
1k views

Java class for simple statistics calculations

I've written a class for a project of mine whose responsibility is to perform basic statistic calculations like mean, median and mode. The aim is for it to be a helper class, so it should not be ...
7
votes
1answer
108 views

Calculate where the patient results reside within the normal distribution

My background is medical, but I required a program that calculated whether my patients are "normal" or 1-2 SD values away from the mean. The program works just fine, but I'm interested how I can do ...
7
votes
2answers
2k views

Count how many times a value is greater than or equal to the median of previous D elements

I am self-studying algorithms and data structures. So, bear with me if the code I've written isn't stellar or interpretation is accurate. Essentially, the problem (which I took from HackerRank) ...
7
votes
1answer
288 views

Average across direction-specific average speeds and probabilities

I have a wind rose with 72 evenly-spaced directions, spanning 360°, each describing a direction-specific average wind speed and associated probability. We must condense this information to 36 evenly-...
7
votes
1answer
116 views

Frequency Analysis & Chi-Squared Test

Following up on my implementation of Cryptopals Challenge 1, this is my solution to Challenge 3. Single-byte XOR cipher The hex encoded string: ...