[R] Seeking help with code

David Winsemius dwinsemius at comcast.net
Fri Dec 8 00:24:25 CET 2017


> On Dec 7, 2017, at 2:51 PM, Stephanie Tsalwa <stsalwa at hotmail.com> wrote:
> 
> Assuming the days of raining during half a year of all states(provinces) of a country is normally distributed (mean=�, standard deviation=�) with sigma (�) equals to 2. We now have 10 data points here: 26.64, 30.65, 31.27, 33.04, 32.56, 29.10, 28.96, 26.44, 27.76, 32.27. Try to get the 95% level of CI for �, using parametric Bootstrap method with bootstrap size B=8000.

This has the definite appearance of a homework assignment. It also has several other features which likewise suggest a failure to read the Posting Guide, a link to which is at the bottom of every posting sent out from the Rhelp mail-server.

You are advised to post credential/affiliation information and more context of the wider goals if my assumption of HW-status is incorrect.

-- 
David.

(And yes I do realize that I am also not posting any affiliation information, either, but I'm retired and am not asking for free advice, am I? Don't follow my bad example.)
> 
> my code - what am i doing wrong
> 
> #set sample size n, bootstrap size B
> n = 10
> b = 8000
> 
> 
> set a vector of days of rain into "drain"
> drain = c(26.64, 30.65, 31.27, 33.04, 32.56, 29.10, 28.96, 26.44, 27.76, 32.27)
> 
> #calculate mean of the sample for days of rain
> mdr=mean(drain)
> mdr
> 
> #calculate the parameter of the exponential distribution
> lambdahat = 1.0/mdr
> lambdahat
> 
> #draw the bootstrap sample from Exponential
> x = rexp(n*b, lambdahat)
> x
> 
> bootstrapsample = matrix(x, nrow=n, ncol=b)
> bootstrapsample
> 
> # Compute the bootstrap lambdastar
> lambdastar = 1.0/colMeans(bootstrapsample)
> lambdastar
> 
> # Compute the differences
> deltastar = lambdastar - lambdahat
> deltastar
> 
> # Find the 0.05 and 0.95 quantile for deltastar
> d = quantile(deltastar, c(0.05,0.95))
> d
> 
> # Calculate the 95% confidence interval for lambda.
> ci = lambdahat - c(d[2], d[1])
> ci
> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA

'Any technology distinguishable from magic is insufficiently advanced.'   -Gehm's Corollary to Clarke's Third Law



More information about the R-help mailing list