Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201867

Calculating lm() within a loop

$
0
0

Objective: The overall objective of the problem is to calculate the confidence interval (CI) of various sample sizes (n=2,4..1024) of rnorm, 10,000 times and then count the number of times each one fails (this likely requires a counter and an if/else statement). Finally the results are to be plotted

I am trying to calculate CI of the means for several simulations of a sample sizes, however, I am first trying to break down the code for one specific sample size a = 8.

The problem I have is that I do not know how to generate a linear model for each row. Would anyone know how I can do this? Here is what I have so far:

a <- 8
n.sim.3 <- 10000

for ( i in a) {
  r.mat <- matrix(rnorm(i*n.sim.3), nrow=n.sim.3, ncol = a)
  lm.tmp <- apply(three.mat,1,lm(n.sim.3~1)  # The lm command is where I'm stuck I don't think this is correct)
  confint.tmp <- confint(lm.tmp)

Viewing all articles
Browse latest Browse all 201867

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>