the code seems fine but when i run it its giving me NaNs producedNaNs

by ali krisht   Last Updated May 22, 2020 21:24 PM - source

SXX = var(X)*(length(X)-1) SE = sqrt(1/n + xbar_2 / SXX) n = 5 n.sim <- 100 xbar_2 = (sum(X)/n)^2

b0 <- vector()

b1 <- vector()

sig2hat <- vector()

sigy <- vector()

LCL = vector()

UCL = vector()

for(i in 1:n.sim){ Y <- beta0 + beta1*X + rnorm(n = nsample, mean = 0, sd = sqrt(sig2)) model <- lm(Y ~ X) b0[i] <- coef(model)[1] b1[i] <- coef(model)[2] sigy[i] <- summary(model)$sigma^2 } summary(model)

b0;b1;sigy

for z CI b0

LCL = b0[i] - qnorm(97.5) * sigy[i] * (sqrt(1/n + xbar_2 / SXX)) UCL = b0[i] + qnorm(97.5) * sigy[i] * (sqrt(1/n + xbar_2 / SXX)) cbind(LCL,UCL)



Related Questions



Add a way to highlight/emphasize changes in code

Updated August 11, 2017 18:24 PM