lundi 27 mai 2019

How to compute P values for increasing sample size using a loop?

I am having trouble creating a for loop. I want to increase my sample size from 1 to 200 and calculate a p value after each newly added observation. So that first I sample 1 observation - calculate first p value, then sample 2 observations - calculate second p value, then 3... up to 200 observations so that I get 200 p-values.
The observations will all be sampled from one column of a data frame (with replacing).

Lets say the column of the data frame is called data$column1. The sample size increases by one in each "round" from 1:200.

How do I create a for loop so that for each "round", one more observation is being sampled and a new p value is being computed? Finally I want to plot all p values.

n <- 1:200

for i in length(n) {
sample(data$column1,n, replace = TRUE)
pvalue <- t.test(data$column1, alternative = "greater")
}




Aucun commentaire:

Enregistrer un commentaire