I'm getting an error in my R program that says:
Error in as.double(x) : cannot coerce type 'closure' to vector of type 'double'
Here's my code, I can't figure out where it's coming from:
norm.pop = rnorm(100000,10,sd = 1)
exp.pop = rexp(100000, rate = 1/10)
true.mean = 10
norm.func = function(n, N, type)
{
if(type == "N")
pop = norm.pop
else if(type =="E")
pop = exp.pop
all.the.probs = sapply(1:N, function(i)
{
the.sample = sample(pop, size = n, replace = TRUE)
x.bar = mean(the.sample)
sd.norm = sd(sample)/sqrt(n)
z.score = 1.96
upper.fence = x.bar + z.score*sd.norm
lower.fence = x.bar - z.score*sd.norm
if((true.mean >= lower.fence) & (true.mean <= upper.fence))
{
return(1)
}
else
{
return (0)
}
})
result = mean(all.the.probs)
return (result)
}
norm.func(10, 10000, "N")
Change:
sd.norm = sd(sample)/sqrt(n)
to:
sd.norm = sd(the.sample)/sqrt(n)
You are trying to use the function sample
(a closure) as a number (double)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With