0

Could someone help me, please, thank you ! I can only do this, am I doing it wrong?

rm(list=ls())
a = runif(1000,0,1)
b = pnorm(a, mean = 60.5, sd = 0.1)
mean = rep(1,1000)
for(i in 1:1000){
  mean[i] = mean(rexp(b,2))
}
n = seq(1, 1000)
plot(mean ~ n)

1 000 numbers 𝑋 ~ 𝑈(𝑎, 𝑏) distribution Then calculate mean from first, first two, first three..., thousand of these random numbers and means and absolute value.

1 Answer 1

1

Your mistake here was using the probability norm pnorm instead of the quantile norm qnorm. You also use rexp when you can be using the mean function to find the means of the values within your normal distribution b.

rm(list=ls())
a=runif(1000,0,1)
b=qnorm(a,mean=60.5,sd = 0.1)
avg= rep(1,1000)
for(i in 1:1000){
  avg[i] = mean(b[1:i])
}
n=seq(1,1000)
plot(avg~n)

To create a chart of the absolute residual between the calculated average you can simply subtract 60.5 by avg, take its absolute value, and plot that.

residual = abs(60.5 - avg)
plot(residual~n)

I'd also recommend using avg in place of mean, as mean is already the name of a function within R.

2
  • 1
    Upvote but please remove the semi-colons, R is not C. Commented Nov 21, 2021 at 19:38
  • @Luke Trenaman, thank you for the help, I'll apply it to my real data ! Commented Nov 22, 2021 at 23:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.