I am looking for a way to score model fits of x,y data on a scale from 0 to 1, depending on which model the data best fit. If data fit a linear model best, the score would come out close to 1. Log would be close to 0, and quadratic would be intermediate (0.5, for example).
My problem is that the function below does not differentiate between linear and quadratic models - any ideas on how to fix this? I might be overlooking something simple or going about this the wrong way. I am using R. Sample code and function below;
`# Functions sat <- function(x, alpha) (1-alpha)*x + alpha*log(x) lik.sat <- function(alpha, x, y) as.numeric(logLik(lm(y ~ sat(x,alpha)))) est.sat <- function(x, y){ fit <- optim(par=.5, fn=lik.sat, method="Brent", control=list(fnscale=-1), lower=0, upper=1, x=x, y=y) if(fit$convergence==0) return(fit$par) return(NA) } # Simulate data #Linear model x<- abs(rnorm(100)) lin.y <- x + rnorm(100, sd=.25) #quad model quad.y <- x + x^2 + rnorm(100, sd=.25) #log model log.y <- log(x) + rnorm(100, sd=.25) # Fit data lik.sat(0, x, lin.y) lik.sat(1, x, lin.y) lik.sat(0, x, quad.y) lik.sat(1, x, quad.y) lik.sat(0, x, log.y) lik.sat(1, x, log.y) # Estimate transformation est.sat(x, lin.y) ## close to 1 est.sat(x, quad.y) #### DOESN'T WORK! est.sat(x, log.y) ## close to 0`