I have written a little function that samples from a normal distribution with linearly changing variance
rnormltv <- function(n,mu,rsd) {
vc <- vector(mode="numeric", length=n)
i <- 1
for (x in seq(from=rsd[1], to=rsd[2], length=n)) {
vc[i]=rnorm(1,mu,x)
i <- i+1
}
return(vc)
}
Suppose we obtain 1000 samples, with a decreasing variance from 9 to 1.
set.seed(1)
x <- rnormltv(1000,0,c(9,1))
plot(x)
The goal is to estimate the parameters 9 and 1 given this data, the mean of zero, assuming a normal distribution and a linear trend in variance. Conceptually I can see how this can be done with maximum likelihood, but how can it by done in practice, preferably in R ?
Note: This is not homework.