This is probably a silly question but here goes: I want to fit parameter "a" from x^a using mle in R. When x>=0, I want the function to read:
x^a
When x<0, I want however the function to change into
-(-x)^a
. A simple "if-else" specification in the code does not work. For example:
Q<-function(r){
if(r>=0){r^a}
else{-(-r)^a}
}
The program returns the following warning:
the condition has length > 1 and only the first element will be used
Has anyone else encountered a similar challenge? At face value this seems like a problem similar to a piecewise regression...But how would one implement this in a mle function? Thanks!