You are on page 1of 2

> ?

rexp
>
>
> SS<-function(x,th){ (mean(x)-1/th)^2+(sum((x-mean(x))^2)/length(x)-1/th^2)2}
Error: unexpected numeric constant in "SS<-function(x,th){ (mean(x)-1/th)^2+
(sum((x-mean(x))^2)/length(x)-1/th^2)2"
> SS<-function(x,th){ (mean(x)-1/th)^2+(sum((x-mean(x))^2)/length(x)-1/th^2)^2}
> data<-rexp(100,3)
> SS(data,3)
[1] 0.001910573
> SS(data,3.1)
[1] 0.001092931
> Ss(data,2.9)
Error in Ss(data, 2.9) : could not find function "Ss"
> SS(data,2.9)
[1] 0.00317404
>
>
>
> SSfunc<-function(th){ (mean(dat)-1/th)^2+(sum((dat-mean(dat))^2)/length(dat)-
1/th^2)^2}
>
> dat<-rexp(100,3)
> SSfunc(1)
[1] 1.162373
> that<-optimize(SSfunc, tol=0.0001)
Error in optimize(SSfunc, tol = 1e-04) :
argument "interval" is missing, with no default
> ?optimize
> that<-optimize(SSfunc, tol=0.0001 , lower= 0 , upper=50*1/mean(dat))
> that
$minimum
[1] 2.759693

$objective
[1] 3.05843e-06

> 1/mean(dat)
[1] 2.7519
>
>
> MMestexp<-function (dat) { SSfunc<-function(th){ (mean(dat)-1/th)^2+(sum((dat-
mean(dat))^2)/length(dat)-1/th^2)^2}}
>
> MMestexp<-function (dat) { SSfunc<-function(th){ (mean(dat)-1/th)^2+(sum((dat-
mean(dat))^2)/length(dat)-1/th^2)^2}

+ hat<-optimize(SSfunc, tol=0.0001 , lower= 0 , upper=50*1/mean(dat))


+ return(hat$minimum) }
>
>
>
> mydata<-rexp(100,5)
> MMextexp(mydata)
Error in MMextexp(mydata) : could not find function "MMextexp"
> MMestexp(mydata)
[1] 4.853563
>
>
>
> samplingdist<-vector()
> for ( i in 1:5000){simul<-rexp(50, 3)
+ estimado<-MMestexp(simul)
+ samplingdist[i]<-estimado }
> hist(samplingdist)
> mean(samplingdist)
[1] 3.084404
> mean(samplingdist)-3
[1] 0.08440414
> shapiro.test(samplingdist)

Shapiro-Wilk normality test

data: samplingdist
W = 0.98829, p-value < 2.2e-16