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
2
votes
2answers
44 views

Calculating p-value for Welch's t-test

I am attempting to translate some of my Perl code to Ruby, from http://rosettacode.org/wiki/Welch%27s_t-test I am a very very beginner with Ruby, but I have verified that this is producing the ...
5
votes
2answers
58 views

A/B testing using chi-square to calculate the significance in an elegant way

The definition of ABtest Goal: For input data, each pair row is a group such as 0 and 1, 2 and 3. I want to test whether each group is significant using chi-square. If result is significant and ...
9
votes
1answer
282 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 ...
6
votes
1answer
84 views

A straightforward method for computing the Binomial probability mass function

I've been writing up code to test an alternate way of calculating the Binomial probability mass function. The Binomial random variable is the number of heads out of N coin tosses with coins that have ...
43
votes
8answers
7k views

Prettify math formula in code

I have a function to calculate the normal distribution in Python: ...
3
votes
2answers
111 views

BiasedOptionChooser<T>: a class to do “weighted random choices”

I need to select "random" elements from a collection. Random is quoted because I must assign a weight to each element; elements with higher weights have a greater chance of being selected. To achieve ...
1
vote
2answers
74 views

Simple Linear Regression in C++

Python has amazing sci-kit learn library but I am building some projects on C++ with involves some machine learning algorithms. I found machine learning libraries in C++ involves more dependencies so ...
1
vote
1answer
101 views

Rolling mean lag function for multiple variables

Thanks to @josliber's help (Rolling mean lag function), I was able to speed up a rolling mean function for different groups and rollmean lengths. Now I'd like to add to this function the ability to ...
4
votes
1answer
113 views

Calculating difference statistics over a moving window

I'd like to calculate some statistics of given data (frequencies of difference among elements on various distances in percent multiplied by 10) using moving window within that data. Is it possible to ...
14
votes
5answers
3k views

Markov-chain sentence generator in Python

I wrote a Markov-chain based sentence generator as my first non-trivial Python program. I mainly used C before, so I probably have ignored a lot of Python conventions and features, so any advice would ...
6
votes
1answer
931 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: ...
1
vote
0answers
53 views

Find the median of two sorted arrays [closed]

There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall ...
2
votes
0answers
20 views

Kernel based conditional increments of many stochastic processes

I have written this function is part of a research project that involves analyzing time-series data from stochastic processes. We have a small number (from 1 to 3) of independent observations of a ...
1
vote
1answer
39 views

Manual Regression Tree using Python

I wrote a code to create a regression tree for a synthetic train data of size Np. The idea is, first I have the source node (which consists of all set of points) ...
6
votes
2answers
90 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 ...
-2
votes
1answer
59 views
2
votes
2answers
81 views

Generate a large block diagonal covariance matrix with exponential decay

I am implementing Kalman filtering in R. Part of the problem involves generating a really huge error covariance block-diagonal matrix (dim: 18000 rows x 18000 columns = 324,000,000 entries). We denote ...
4
votes
1answer
88 views

Evaluate joint probability density function of a Markov random field

The following code evaluates probability mass function for all possible states of a model. ...
2
votes
1answer
26 views

Statistical function which computes the average work time in different months

It's a task from a Ruby-course, in which I'm currently enrolled: Ruby Course - Page Precisely it's one of the assignments for the first week. Following idea: Your are given a list in which finished ...
2
votes
1answer
52 views

Select optimal piecewise regression fit

I'm making a program which fits a piecewise linear regression with up to 4-5 breakpoints in the data, and then deciding how many breakpoints is best to prevent over and underfitting. However, my code ...
3
votes
2answers
99 views

Calculate mean and standard error of a generator in Python

The goal of the following code is to calculate the mean and the standard error of vectors of randomly-generated numbers. I am looking for feedback both on the correctness of the calculation, and on ...
3
votes
0answers
48 views

Simple Kivy App for Bootstrap Algorithm

I have a very simlpe app built using Kivy, for performing bootstrap algorithm (statistics). We must input some samples in the form x1,x2,...,xn (these will be ...
7
votes
1answer
97 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 ...
1
vote
0answers
34 views

Sortings stocks into quantiles based on their signal

This function sorts stocks into quantiles. To do so I used this function that accepts sig_df (dataframe with the timeseries of stocks signal) and number of ...
4
votes
1answer
90 views

Pick the best combination of n choose k models

Algorithm Let \$M_0\$ denote the null model which contains no predictors. This model simply predicts the sample mean of each observation. For \$k=1,2,\ldots,n\$: Fit all \$n \choose k\...
4
votes
1answer
40 views

Entropy calculation function in Haskell

I've written a function in Haskell for calculating the entropy of a collection. I'd like feedback on how the function could be rewritten to be more flexible/reusable, and also how to profile the ...
3
votes
1answer
1k views

HackerRank: Climbing the Leaderboard

Below is my solution to Climbing the Leaderboard on HackerRank: Alice is playing an arcade game and wants to climb to the top of the leaderboard. Can you help her track her ranking as she beats ...
2
votes
0answers
69 views

Bias-corrected percentile Bootstrapping Optimization

I have never posted to this forum, but was referred here. I need some help printing key iterations as well as optimizing my code for run time. If someone had some time to help/explain how to correct ...
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 ...
2
votes
3answers
128 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 ...
3
votes
1answer
138 views

Groovy script to get average price per group from different data arrays

I've been trying to learn Groovy lately and I tried to solve a problem which involves designing a routine that will calculate the average Product price per Group. I have the following data: ...
1
vote
0answers
30 views

Flagging out-of-stock items

I wrote a function that iterates over 3 parameters to spot out-of-stock items. To illustrate this I'll draw an example: suppose that the product 10 in store 2 for an offer named "super5" is following ...
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 ...
3
votes
0answers
26 views

TensorFlow regressor to predict probability of winning, given a current score

This is a TensorFlow regressor that tells me that if you get x score, you will have x% to win a game in x game(game is not important). Doing this as a project to learn tensorflow. ...
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
219 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 ...
3
votes
3answers
129 views

Computing average duration per user from a large CSV file that doesn't fit in memory

We have a large log file which stores user interactions with an application. The entries in the log file follow the following schema: {userId, timestamp, actionType} where actionType is one of two ...
1
vote
0answers
50 views

Lazy Statistics: XYSamples java

After previous review I chose to alter this project to use lazy evaluation. Looking for any and all improvement feedback. This project is meant to represent a two dimensional data set, i.e., single-...
3
votes
1answer
113 views

Program which accepts grades and prints grade distribution

I'm doing the MOOC Java course (CTRL+F "distribution"): The input of the program is a set of exam scores of a course. Each score is an integer. When -1 is entered, the program stops asking for ...
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 ...
2
votes
1answer
133 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 ...
3
votes
1answer
65 views

Generating random number from a binomial distribution

In my application of Monte Carlo simulation, the crucial part is to generate a random number from a binomial distribution with parameters n = size and p = 0.5. Here is my current implementation ...
3
votes
1answer
40 views

Sample size, P-values (its relationship), and data visualization with plots. ggplot and T test

We know that P-values (within t-test context as an example..) is highly sensitive to sample size. A larger sample will yield a smaller p-value remaining everything else constant. On the other hand, ...
2
votes
1answer
75 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 ...
8
votes
1answer
48 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 ...
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. ...
3
votes
2answers
78 views

Constructing a cumulative distribution function from a histogram

During some running process, a histogram of values shall be build up. When done, the CDF shall be derived from it and used to get the quantiles for some values. My current implementation looks as ...
3
votes
1answer
69 views

Evaluating association strengths of items

I have a list of animals with their counts: ...
2
votes
0answers
23 views

Simple data analysis for forecasting

This Python script extracts data from txt files containing raw numerical data, notably the increase average, the relative evolution and the standard deviation of ...
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 ...