I have a dataset of people, it includes their assigned id from one through eight, and their gender. Using python, how might I use Disproportional Stratified Sampling to make some teams? I’ve used this code to get the distribution: from openpyxl import load_workbook wb = load_workbook("dataset.xlsx") sh = wb["Page"] dist =  for i in… Read More Disproportional Stratified Sampling – Python
In R it is quite trivial to "collapse" an n-dimensional array into a one-dimensional column vector and sample from that using e.g. sample() function in base R. However, I would like to sample dimnames-groups (i.e. rowname-colname pairs in case of a two-dimensional array) based on the frequencies. Let’s have an example, and assume we have… Read More How to sample rowname-colname pairs from a crosstab (or dimname groups from an n-dimensional array) in R?
I have a data frame with 20 rows, I randomly select n rows and modify them. How can I put the modified value back to the original data frame with only the modified value being different? df<- data.frame(rnorm(n = 20, mean = 0, sd = 1)) n = 8 a<- data.frame(df[ c(1, sample(2:(nrow(df)-1), n), nrow(df)… Read More Replace the subsetted and modified data back into the main dataframe
I am using VBA for Excel and I have a workbook with a few tabs. I would like to randomize and pull a sample from each tab. An example of the code is below sql = "SELECT TOP " & myNum & " * " & _ "FROM [Annual$] ORDER BY RND()" Debug.Print sql Individually,… Read More Randomize and Sample using SQL in Excel VBA
When I run the following I get an error: sample(c(1,4),5,replace=FALSE) This is the error: Error in sample.int(length(x), size, replace, prob) : cannot take a sample larger than the population when ‘replace = FALSE’ Is there a way to sample without replacement where it just automatically stops sampling once there is nothing left to sample? The… Read More In R how do you take a sample of size n without replacement where length of vector sampling from is <= n
I am having difficulties solving the error "there should be the same number of samples in x and y". I notice that others have posted on this site regarding this error, but their solutions have not worked for me. I am attaching an abbreviated version of my dataset here. x_train is here: x_train <- structure(list(laterality… Read More Caret rfe() error "there should be the same number of samples in x and y"
Is there a way to sample X number of random rows and X non-random rows in a single sample? For example, I want to get 1,000 samples of 4 rows of iris. I want to randomly sample 3 rows of iris and the fourth row will be the same one in each sample (this is… Read More Sampling randomly and non-randomly in one sample
I have an equation with three parameters namely a, b, and c. I am minimizing the parameters of this equation by comparing it to a measured behaviour. For this purpose, I am trying to generate a Latin Hypercube Sampling of three-dimensional parameter space (namely for a, b, and c) and want to use different samples… Read More How to get the distribution of a parameter using Latin Hypercube Sampling that has bounds in different scales using Python?
Suppose I have a vector<Point> p of some objects. I can pick a uniformly random by simply p[rand() % p.size()]. Now suppose I have another same-sized vector of doubles vector <double> chances. I want to randomly sample from p with each element having a probability analogous to its value in chances (which may not be… Read More How to randomly pick element from an array with different probabilities in C++