Hi. It is doing three times because of the vector sample_size, as you said, but each time is doing the exact same operation.
I would not consider it valid. I mean, writting a loop without using it is not good. Here the time is not that important due to the small magnitude of the example, but it may be in other tasks (real example: I had some very old code with some routines that took ~30 min per individual, with ~200 individuals. When I went back to that code I found a messy loop doing nothing but repeating the same operation several thousands of times. Of course, the loop was propagated along the script, making it worst. Once removed, each individual process took 1-2 seconds)
Anyway, I don't think your apprach is valid, if you want to do the operation you wrote for each of the three values os sample_sizes,, you have to explicit it in a loop or using an *pply function for it.
What your code is doing is dividing the first (p(1-p)) by the first sample_size value, the second (p(1-p)) by the second sample_size value, the third (p(1-p)) value by the third and the fourth (p(1-p)) again by the first sample_size value and so on. R is recycling the vector sample_size as it is smaller than the vector p. So this is not what I think you are aiming.
Running the loop I coded above, and plotting it,, makes it looking more to what I think you are aiming:
Cols <- c('black','dodgerblue','firebrick')
plot(p,se[[1]], type = 'l', col = Cols[1],lwd = 2, xlab = 'p', ylab = 'se')
points(p,se[[2]], type = 'l', col = Cols[2], lwd = 2)
points(p,se[[3]], type = 'l', col = Cols[3], lwd = 2)
## legend
leg = paste('N = ', sample_sizes, sep = '')
legend('topleft', col = Cols, legend = leg, lwd = 2)
![example](https://forum.posit.co/uploads/default/original/2X/3/3df410e2510dd8264855a3afa598ffd8158d6e12.jpg)
the SE got reduced as sample size increases
cheers
Fer