Mic Check my simulation

trinker

ggplot2orBust
#1
I'm not a statistician but like to pretend. I help a friend write simulations in R but don't really do the math end. Here's a small baby attempt at a simulation to answer Noetsi's question of how using a single Likert item vs an interval scale affects the estimates and slopes.

Please give me feed back:

Code:
y <- rnorm(100)
w <- rnorm(100)

z1 <- function() summary(lm(y ~ sample(1:7, 100, T) + w))[[4]]
z2 <- function() summary(lm(y ~ sample(1:100, 100, T) + w))[[4]]

x <- 1000000
likert <- matrix(rowMeans(do.call(cbind, lapply(lapply(1:x, function(i) z1()), c))), ncol=4)
interval <- matrix(rowMeans(do.call(cbind, lapply(lapply(1:x, function(i) z2()), c))), ncol=4)
colnames(likert) <- colnames(interval) <- colnames(z1())
likert; interval
 

trinker

ggplot2orBust
#4
Thought I'd share the results for scaling up and supplying 3, 7, 20, 50, 100 in how the IV was allowed to vary. It appears to affect only the x1 not x2's SE which of course affects the t value.

Code:
y <- rnorm(100)
w <- rnorm(100)

z1 <- function(k) summary(lm(y ~ sample(1:k, 100, T) + w))[[4]]
FUN <- function(j, n.reps) {
    OUT <- matrix(rowMeans(do.call(cbind, lapply(lapply(1:n.reps, function(i) z1(j)), c))), ncol=4)
    colnames(OUT) <- c("Estimate",   "Std. Error", "t value",    "Pr(>|t|)")
    return(OUT)
}

opts <- c(3, 7, 20, 50, 100)
n.reps <- 10000

library(parallel)
cl <- makeCluster(mc <- getOption("cl.cores", detectCores()))
clusterExport(cl=cl, varlist=c("z1", "opts", "FUN", "n.reps", "y", "w"), 
    envir=environment())
x <- parLapply(cl, opts, function(i) {
    FUN(i, n.reps=n.reps)
    }
)
stopCluster(cl) 
names(x) <- opts
x
Code:
$`3`
           Estimate Std. Error      t value  Pr(>|t|)
[1,] -0.01758687205  0.3216154 -0.055228175 0.5210664
[2,]  0.00008394705  0.1490660  0.001038983 0.4974930
[3,]  0.14467986831  0.1118591  1.293554050 0.2011786

$`7`
          Estimate Std. Error      t value  Pr(>|t|)
[1,] -0.0196652587 0.27195712 -0.073006141 0.5386201
[2,]  0.0005583406 0.06093346  0.009855581 0.5050038
[3,]  0.1447863795 0.11189453  1.294080334 0.2009572

$`20`
           Estimate Std. Error      t value  Pr(>|t|)
[1,] -0.01663105383 0.25267724 -0.066822564 0.5423810
[2,] -0.00005852673 0.02113486 -0.002527214 0.5016699
[3,]  0.14447583917 0.11188896  1.291349406 0.2019108

$`50`
           Estimate  Std. Error      t value  Pr(>|t|)
[1,] -0.01704233432 0.246821086 -0.069412224 0.5436323
[2,] -0.00001718442 0.008441321 -0.001664539 0.5017278
[3,]  0.14473747712 0.111886989  1.293744266 0.2009154

$`100`
            Estimate  Std. Error      t value  Pr(>|t|)
[1,] -0.016848260900 0.244899338 -0.069532880 0.5393250
[2,] -0.000007199792 0.004220732 -0.001870799 0.4963603
[3,]  0.144700118199 0.111861739  1.293690967 0.2010787