-2

How can I plot graph for sample variance versus sample size while putting random numbers from 1 to 20 in R language?

user2079657
  • 7
  • 1
  • 2
  • 1
    I guess you want integers 1 to 20? And what type of plot? What range of sample sizes do you want? – N8TRO Feb 17 '13 at 02:39
  • 1
    do have example or reproducible example ? – rdorlearn Feb 17 '13 at 02:42
  • 4
    You're on a fast track to having this post closed. It's your first post so check out this link: http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Tyler Rinker Feb 17 '13 at 02:46

1 Answers1

5

Trinker will probably hate that I answered this, but here is a crude example with many assumptions:

sample.max <- 20000
sample.sizes <- seq(1, sample.max, by=10)

myfun <- function (x){
var(sample(1:20, x, replace=TRUE))
}

variances <- sapply(sample.sizes, myfun)

plot(sample.sizes, variances, t='l')

enter image description here

N8TRO
  • 3,348
  • 3
  • 22
  • 40
  • +1 for mind reading, and/but: in the second line do you mean `1:sample.max` (`c()` is redundant, and you never defined `x.range` in this code). I would actually suggest `seq(1,sample.max,by=10)`, as 20000 separate samples is probably overkill. – Ben Bolker Feb 17 '13 at 04:49
  • 1
    @BenBolker .. you're right, of course. I had x and y before then edited with more meaningful labels and shamefully missed that 1. – N8TRO Feb 17 '13 at 04:52