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
7
votes
1answer
111 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
66 views

Generating Latin hypercube samples with numpy

I wrote some code to generate Latin hypercube samples for interpolation over high-dimensional parameter spaces. Latin hypercubes are essentially collections of points on a hypercube that are placed on ...
7
votes
1answer
133 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: ...
7
votes
1answer
575 views

Computing the autocorrelation between 2D time series arrays in python

I have a list of 2D arrays which comes from a time evolution PDE (in \$(x, y, t)\$) that I solved numerically. There are \$k\$ arrays, which all have the same dimensions, and the arrays correspond to ...
7
votes
1answer
459 views

Optimized computation of pairwise correlations in Python

Given a set of discrete locations (e.g. "sites") that are pairwise related in some categorical ways (e.g. general proximity) and contains local level data (e.g. population size), I wish to efficiently ...
6
votes
5answers
3k views

Computing mean and median

I have written a program to compute mean and median. Please review my code and give suggestions. I have a confusion about this temps[temps.size()/2] when temps....
6
votes
3answers
411 views

Find median of two sorted ranges

Given two sorted ranges of elements, compute a median of all the elements in O(log(n+m)) time. This solution contains only one call to std::lower_bound ...
6
votes
3answers
1k views

Numerical Python code to generate artificial data from a time series process

I'm writing code to generate artificial data from a bivariate time series process, i.e. a vector autoregression. This is my first foray into numerical Python, and it seemed like a good place to start. ...
6
votes
2answers
188 views

Finding median from unsorted array with duplicate elements without sorting it

I am implementing a method to find the median of an unsorted array using a counting sort. I would happily go for a median of medians or selection algorithm for better performance but they are ...
6
votes
2answers
537 views

Bash script that counts the characters, frequency, and percentage of letters in Spanish sonnets

This script will be used to analyze a lot of old Spanish sonnets. I have tested it thoroughly and all seems to be working perfectly. However, I want to make sure I am not missing some detail because I ...
6
votes
2answers
2k views

Rolling regressions in R

I want to run rolling regressions over each group and store the coefficient. The following works, but it's slow, since I have too many series and I want to run too many regressions for each group. ...
6
votes
2answers
251 views

Moving average function in C++ for use with R

I am trying to improve the code and speed up in C++ (Rcpp) a (centered) weighted moving average function I coded. An example of what the roll_mean function does. Note that the function works no ...
6
votes
1answer
226 views

Statistical simulation

I've written the following program as a submission to the German Federal Computer Science Competition for highschool students. The program makes the following simulation with a given number of days ...
6
votes
2answers
113 views

Statistics with Python

Write a program to determine the mean, median, and standard deviation of a list of numbers Count the duplicate numbers in the code, listing any that occur more than once with the number of times it ...
6
votes
3answers
114 views

SAT score reader program

This program takes 10 Math SAT scores and 10 Verbal Sat scores from the user, computes the standard deviation and averages, then displays them in a tabular format. After, it displays them to the user ...
6
votes
2answers
7k views

Calculating running average in Java

I have a library which makes HTTP calls to my service. I was trying to calculate running average of how much time my service is taking on an average. Here is the core logic of how I am calculating "...
6
votes
2answers
77 views

Statistical User-Defined Functions (UDF)

Problem The following statistical functions were created to calculate statistics of experiments: Mean Peak to Peak Standard Deviation Variance Mean Absolute Error (MAE) Mean Square Error (MSE) Root ...
6
votes
1answer
70 views

Monte Carlo errors estimation routine

I would value your opinion on the following piece of code. I am rather new to both Python and Monte Carlo analysis, so I was wondering whether the routine makes sense to more experienced and ...
6
votes
2answers
181 views

Program to calculate some stats from Facebook messages

I've written a program that parses JSON downloaded from Facebook to calculate some stats from a conversation between two parties. It attemps to count these things: Messages grouped by day of week ...
6
votes
2answers
23k views

Calculating Standard Deviation using SQL

I have been reading a bit about statistics to improve the way I understand data. This is my attempt at calculating Standard Variance using data tables. I solved this simple question: This is the code ...
6
votes
1answer
72 views

Statistics mode function

I will get straight to the point - I am a freshman at uni and I am currently working on my first bigger personal project - Statula is a terminal tool for data analysis which takes in dataset (as a ...
6
votes
1answer
2k views

Bean Machine Simulation

I could not find a solution from my book's website (student-level access) but I feel that I am missing something that I'm supposed to learn from this exercise. Instructions: Balls are dropped from ...
6
votes
3answers
18k views

Counting words, letters, average word length, and letter frequency

I'm pretty sure my code is mostly correct. I think I'm having formatting errors more than anything. I keep receiving warnings about "double to float and int to float,possible loss of data. Here is ...
6
votes
1answer
432 views

Univariate analysis with SQL stored procedure

I wrote a SQL univariate analysis stored procedure taking as input a schemaname and a tablename on PostgreSQL. It is exactly like a PROC SAS UNIVARIATE. As output, you get less than 20 usable ...
6
votes
1answer
169 views

Summarizing downtime statistics

I am not satisfied with the performance and especially the time my piece of code takes to complete. The surrounding environment for better understanding is the following: A statistic for Downtime ...
6
votes
1answer
893 views

Django Rest Framework Totaling API values in different ways

I am working on a stats website for my softball teams that I manage/play for. Here is my current Stat model: ...
6
votes
0answers
82 views

Pivot-friendly binning of arbitrary vector

I frequently get a situation in which I want a pretty binned column from a vector of values, so that I divide the vector in approximately even ranges and choose 'sensible' values so that it looks ...
5
votes
4answers
8k views

Find the most frequent integer in an array

I have been a Python developer for a few years and I'm going through some simple exercises to learn C++. Please consider the following Python snippet ...
5
votes
2answers
384 views

Counting consecutive selections of a given number when sampling integers in a range

This script counts consecutive number strikes of a number that you determine in a number-sequence that you also determine. I would be very pleased if this script can be reviewed in terms of ...
5
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: ...
5
votes
2answers
195 views

Continuous median in Ruby

I have written a program in Ruby which calculates the median of a streaming set of numbers dynamically. For each number that arrives, the median is calculated for all the numbers that have arrived so ...
5
votes
3answers
503 views

Count sub-sequences of an array having median lying in that subsequence itself

We need to calculate the number of sub-sequences of an array having its median lying in the sub-sequence itself. My code is - ...
5
votes
2answers
2k views

Multiple similar methods to compute the average student grade

I have bunch of similar methods in different classes to average student grades. In the Student class: ...
5
votes
2answers
154 views

Django model to do accounting for a Litecoin miner pool

I'm coming from Java so I am used to performing calculations I require in separate functions. I would like to know if the below code makes sense in my Django model especially the loop and calling ...
5
votes
1answer
756 views

Fun with probability theory

I want to play around with the Powerball lotto drawing history. What other probability theories could I try or what other probability class libraries exist. The code parses the file very quickly but ...
5
votes
1answer
103 views

Analyzing the U.S. Births dataset in Python

I'm a Data Science newbie and currently looking to improve my code. I was trying to calculate the total number of the following: The total number of births on each month The total number of births on ...
5
votes
2answers
529 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 ...
5
votes
1answer
2k views

Improve performance of Gaussian kernel function evaluation

I need to improve the performance of a function that calculates the integral of a two-dimensional kernel density estimate (obtained using the function stats.gaussian_kde) where the domain of ...
5
votes
2answers
60 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: ...
5
votes
2answers
176 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. ...
5
votes
1answer
178 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 ...
5
votes
2answers
117 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 ...
5
votes
1answer
6k 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 ...
5
votes
3answers
6k views

Sampling from a distribution with given probabilities

I have found myself needing to sample numbers from a given distribution and was wondering what the most efficient method of doing so is. I have a set of N elements ...
5
votes
1answer
62 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 ...
5
votes
1answer
156 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
138 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
126 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 ...