Question

I'm learning R using a book called "Discovering Statistics using R". It's great but seems to skip over some areas.

So, I have a function in R that calculates the parameters a, b of the following pdf beta function:

func

My function returns the following parameters found from a sample of 500:

  [1] 1.028316 2.095143 #a b

I'm trying to calculate the standard error of the parameters.

I'm wondering how this can be implemented in R?

As far as I can find online, standard errors are calculated from the sample, not the parameters. So, all i've implemented is, here:

    stderr <- function(x) sqrt(var(x)/length(x))

Thanks in advance.

Was it helpful?

Solution

I'm not sure which function you're using to fit a beta distribution to your data, but the fitdistr function from the MASS package provides standard error values for the shape1 and shape2 parameters of the beta distribution:

# Obtain data to fit
set.seed(144)
data <- rbeta(500, 1, 2)

# Fit and output result
library(MASS)
fit <- fitdistr(data, "beta", start=list(shape1=0.5, shape2=0.5))
fit
#     shape1      shape2  
#   1.0596902   2.0406073 
#  (0.0602071) (0.1284133)

Here, the standard errors are 0.060 for shape1 and 0.128 for shape2. You can get at the values with fit$sd.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top