# conclk.r September 2007 # # concentrated likelihood problem, Example 9.6 # x <- c(1,2,3,4,5,7) y <- c(8.3, 10.3, 19.0, 16.0, 15.6, 19.8) # construct error sum of squares function sse <- function(t2) { z <- 1 - exp(-t2*x) t1 <- crossprod(y,z)/crossprod(z,z) # regression through origin e <- y - t1*z # residuals s <- crossprod(e,e) # error sum of squares print("t1,t2,sse") print(c(t1,t2,s)) sse <- as.real(s) } # make it a scalar # starting values? sse(.1) sse(1) sse(5) sse(10) # minimize error sum of squares that2 <- optimize(f=sse,lower=.1,upper=5) # print it out print("min sse") print(that2) # done rm(list=ls()) q()