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
3
votes
0answers
2k views

A Simple K-Means Cluster Analyzer v0.1

[NOTE] This question can be depreciated in favor of version 0.2. This code works well. This my first attempt at creating a robust, computationally lean K-Means Cluster analyzer. I first saw this ...
3
votes
0answers
1k views

KS-Statistic in C++

Consider the MCG with parameters: a = 23, M = 10^8 + 1, and let the seed be 47594118. (This is the original MCG proposed by Lehmer in 1948.) Apply the Kolmogorov-Smirnov test to the first 1000 random ...
3
votes
0answers
212 views

Naive implementation of Naive Bayes in Haskell

A simple implementation of Naive Bayes, as I'm a Haskell beginner I've tried to put an emphasis on clarity and documentation. I've tried to incorporate the feedback from a similar question. This is ...
3
votes
0answers
138 views

Read in file, Filter out records, output results

I have been working on a project for some time and have let one Python file grow into a huge file that tries to do everything. The structure is pretty flat and I don't like it. I've used other ...
3
votes
0answers
162 views

Nonlinear Nonparametric Regression

I explain the nonlinear correlation coefficients in this paper and provided the code in this post. The nonlinear nonparametric regression is an extension of this work and its description can be found ...
3
votes
0answers
126 views

Correlation and Dependence

It is well known that 0 dependence implies 0 correlation, while 0 correlation does not imply 0 dependence. I have a paper here illustrating nonlinear correlation coefficients from relationship subsets ...
3
votes
0answers
144 views

Computing pairwise distance covariances for a symmetric matrix

I wrote a non-vectorized, non-parallel wrapper function for computing the pairwise distance covariances (Wikipedia) (original paper) in a data frame: ...
2
votes
4answers
116 views

Calculate min, max, mean and median out of array Version 2

This question is a follow up of: Calculate min, max, mean and median out of array I took all the suggestions an reworked the code. Like the description of the excercise suggests i only use one ...
2
votes
3answers
109 views

Statistical methods using PHP (mean, co/variance, standard deviation, skew, correlation)

Functionality This class has a list of statistical functions such as mean, variance, standard deviation, skewness, and it works okay. These functions are applied to arrays of charts data. It is an ...
2
votes
2answers
201 views

Given a list of words, find the most common initial character and other statistics

20 different words are inputted using a string array. A C++ program to display the alphabet which has occurred the maximum number of times as starting letter of a word in the list,and how many times ...
2
votes
2answers
640 views

Extracting price statistics from a CSV file

I got the following task to solve: ...
2
votes
2answers
1k views

Normal distribution array function

I have a function that produce an array with values that are Gaussian (normal) distribution. If you plot the values on a graph, it would look something like this: Is there any way to improve on the ...
2
votes
2answers
639 views

Row-wise mean imputation in R

Someone on SO asked how to fill in the NA's with row means. His example code was: ...
2
votes
1answer
115 views

Rolling mean lag function

I'm working in base R here, but would like to convert these functions to something more efficient in R (e.g. speed up processing with dplyr). This takes a while ...
2
votes
1answer
69 views

Mean of integers, ignoring the largest and smallest values

The code returns the mean of a list of integers, except ignoring the largest and smallest values in the list. If there are multiple copies of the smallest value, ignore just one copy, and likewise for ...
2
votes
1answer
3k views

Finding the percentile corresponding to a threshold

I need to find which percentile of a group of numbers is over a threshold value. Is there a way that this can be speed up? My implementation is much too slow for the intended application. In case this ...
2
votes
2answers
517 views

Binning and calculating a huge range of data

I have a code that I'm fairly certain does what I want. Bear with me as I explain what I'm doing: Imagine that there is 10 houses, where there can be one to an infinite number of persons. Each of ...
2
votes
1answer
45 views

Basic Single Header statistics and ml libray for C++ - Scikit-Learn like implementation

I am developing scikit-learn like implementation for C++ it is in the initial stage while developing I've started doubt myself that is this the correct implementation, since here accuracy is more ...
2
votes
2answers
200 views

Estimating the total production count from a few random serial numbers

This is basically my attempt to the German Tank Problem in which we are given a few serial numbers and expected to return an estimation of the total production count. Such as, if 4 tanks are captured ...
2
votes
2answers
98 views

Top K frequent elements

I am working on an interview question where I need to return the k most frequent elements given a non-empty array of integers. Input: nums = [1,1,1,2,2,3], k = 2 Output: [1,2] Here is my code: <...
2
votes
2answers
50 views

The importance of consistency in percentage returns when investing

It is said that Being consistent in percentage annual returns leads to larger amount over time. That is for any given principal, getting 20% successively for 2 years is better than 30% for first ...
2
votes
3answers
89 views

Speed up weighted average for Leela Chess Zero

Problem: Given a vector of about 40 values m with normal error sd compute the weighted average of the values weighted by the ...
2
votes
2answers
106 views

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

(See the next iteration.) I have this simple "data structure" for storing numbers and querying the statistics on them (average, variance and standard deviation): numberbag.hpp ...
2
votes
1answer
250 views

Multiple files data processing in Clojure

I have made a small script which grabs data into a map from 80 CSV files and calculates some statistics like average, standard deviation etc. It's also adding some additional data to map from filename....
2
votes
1answer
994 views

Calculating exponential moving averages with multiples threads

I calculate the moving averages of a specific measure. However, multiples threads can access this class in order to compute the average. ...
2
votes
2answers
409 views

Calculating the statistical Mode(s) of a (possibly multi-modal) set of elements

I am trying to come up with the most performant way of calculating the statistical Modes of a std::vector, obeying two conditions: 1) my function should not ...
2
votes
2answers
100 views

Random distribution in Ruby

Below is a Ruby implementation of a random statistical event, based on a hash with the actual observed counts of outcomes. I'd be interested in feedback in particular on what techniques I might use ...
2
votes
1answer
62 views

Compute histrogram bins for a large data.frame fast

I know about apply, but I'm not sure how to write it so that it works for embedded for loops with if statements and so forth. It ...
2
votes
2answers
2k views

War card game simulator

My teacher wants us to create a program that runs n games of war and calculates the average number of battles, wars and double wars that occurred. He has very specific rules (not necessarily the ...
2
votes
1answer
245 views

Check ordinary least squares calculation for correctness

I've written ordinary least squares fitting of market data for learning purposes, so performance is not an issue. I'd like a reviewer to look at correctness and programming flaws, if any, in the code:...
2
votes
2answers
204 views

Calculating the posterior distribution in multivariate Gaussian processes

Matlab profiler throws this horrible bottleneck which is called 700000 times: ...
2
votes
1answer
93 views

Welford's online variance calculation algorithm for vectors

I'm developing a face recognizing application using the face_recognition Python library. The faces are encoded as 128-dimension floating-point vectors. In addition to this, each named known person ...
2
votes
2answers
77 views

Application to monitor device power levels for deviations

I have a high performance, computation intensive application that runs on a Centos 7 machine with Python 2.7.5. I'll try to explain what the application does: The application runs an infinite loop, ...
2
votes
1answer
49 views

Regularised regression code

I wrote some code to do regularised linear regression and it works, but I don't like the fact that I've had to double call the functions when plotting, nor the fact that I've sliced those calls to get ...
2
votes
1answer
47 views

Counts and average code

Using the columns 4 and 2 will create a report like the output file showed below. My code works fine but I believe it can be done shorter. I have a doubt in the part of the split: ...
2
votes
1answer
44 views

Query for stddev of number of stars per chatroom message

I am learning SQL today, so I decided to practice by writing some queries for The Nineteenth Byte Data Explorer. This is a PostgreSQL database about messages from The Nineteenth Byte chatroom, created ...
2
votes
2answers
68 views

A value set data structure for rapid statistics queries in Java

(See the next iteration.) This question is an elaboration of my question. Just like the previous implementation, all operations (except clear) run in exact or ...
2
votes
3answers
201 views

Calculating average stock prices using producer/consumer with async

Task: calculate average price for each stock, using input data, which consists of stock id (int) and its price (float). It's important to detect jumps in prices, therefore need to keep correct ...
2
votes
1answer
634 views

Order statistics without sorting in expected linear time in Java

Given an unsorted array of integers \$A\$, the \$i\$th order statistic of \$A\$ is the \$i\$th smallest element of \$A\$. For example, \$0\$th order statistics of \$A\$ is the minimum of \$A\$; \$(|A| ...
2
votes
2answers
1k views

Read in file, and then compute class mean, median, max, min, class averages & update file

The application is designed to read in class results of individual students from a single text file, and then manipulate the data to give information such as class mean, median, max, min, individual ...
2
votes
1answer
3k views

Compute the mean, variance and standard deviation of all pairs, triplets and sets of four

My code sample for finding the mean for the case of pairs is: ...
2
votes
1answer
44 views

Matrix to calculate effects using delta method

I have written some code to calculate effects using the Delta method. I have a dataframe dpcp with variables x1, ...
2
votes
1answer
4k views

Computing average grades for students in a class

I wrote up a simple averages calculator for student grades, based on this daily programming challenge. First, the script asks for the file name for the text file containing the student names and ...
2
votes
1answer
69 views

Incrementing time in a discrete-event simulation of a supermarket queue

A method has been written that increments time in minutes that simulates how much time it takes to process item in a supermarket queue and if there is an empty queue, skip it and loops around to find ...
2
votes
1answer
59 views

dplyr — tidyverse, pipes, correlation, same variable across time “a” “b”

Have a look at this dataset. The"a" and "b" are used to make possible differentiate when the same variable was measured. In this case X1a and X1b access the same variable, but "a" was (suppose..) in ...
2
votes
1answer
44 views

Grade of Service Probability Function Python

Consider the following typical probability scenario: I defined this function to handle that scenario, I'm curious if Python has a more efficient method to handle this, or if this is the best way: <...
2
votes
1answer
509 views

Simulation study in R with two variables and 10000 iterations

The generic version of what I am trying to do is to conduct a simulation study where I manipulate a few variables to see how that impacts a result. I'm having some speed issues with R. The latest ...
2
votes
1answer
6k views

Create quantile slices from dataframe columns

I have the following, working code: ...
2
votes
1answer
54 views

A C stack with minimum and maximum values

I have this C stack implementation that knows its minimum and maximum values: minmax_stack.h ...
2
votes
1answer
998 views

Method to return statistics from a collection with O(1) time and space

I have a DelayQueue, and the goal is to collect statistical information from the collection in O(1) time and space from ...