Displaying 1 result from an estimated 1 matches for "myalpha".
2011 Nov 10
3
optim seems to be finding a local minimum
...olute residuals after a
regression with a single predictor:
mysum<- function(myIV,myDV){
regr<-lm(myDV[[1]] ~ 0 + myIV[[1]])
mysum<-sum(abs(regr$resid))
return(mysum)
}
### Function to be optimized;
### param is a vector of 2 values (.alpha and .beta)
myfunc <- function(param){
myalpha<-param[1]
mybeta<-param[2]
IVtransf<-transformIV(myalpha, mybeta)
sumofdevs<-mysum(myIV=IVtransf,myDV=DV)
return(sumofdevs)
}
# Optimizing using optim:
myopt <- optim(fn=myfunc, par=c(0.1,max(IV)), method="L-BFGS-B", lower=0)
(myopt)
myfunc(myopt$par)
## Comparing...