riah w
riah w

Reputation: 1

Repeating Sampling with Replacement and storing Correlation Coefficients

I am very new to coding and I am attempting to preform sampling with replacement. So far I have been able to generate several randomised datasets and their correlation coefficients, however I cannot seem to get the correlations to store within a variable, it keeps showing up with only one correlation and not x amount as the loop output gives. I need to be able to use the array for correlation coefficients to produce a histogram and report the confidence interval (essentially bootstrapping).

Here is what I’ve gotten so far:

correlation = np.array([])
for i in range (num_datasets):
    sample_datasets = dataset[np.random.choice(dataset.shape[0],size[0],size=dataset,shape[0],replace=True)]
  for i in sample_dataset:
    corr = np.corrcoef(sample_dataset[:,0], sample_dataset[:,1])[0,1]
  correlation = np.append(corr)
  print (correlation)

I have tried several variations of this code but it usually keeps only storing just one element to the correlation so I cannot reorder it or do anything.

Upvotes: 0

Views: 23

Answers (0)

Related Questions