[R] nls - Error in qr.qty(QR, resid) : NA/NaN/Inf in foreign function call (arg 1)
Arpit Jain
arpitrb at gmail.com
Mon Jul 7 15:50:13 CEST 2014
Dear All,
I have made a script in R (r_nonlinear_leastsquare.R) to fit an exponential
decay curve to my data using nls module:
-----------------------------------------------------------------------------------------------------------------
args <- commandArgs(trailingOnly = TRUE)
#"/project/dmp-work/alex/workspace/test/test_data"
path = args[1]
y <- scan(path)
x = seq(0.1, length(y)*0.1, 0.1)
y=1-y
myfunc = function(t, params){
(1*params[1]*exp(params[2]*t))/(1+params[1]*(exp(params[2]*t)-1)) }
fitModel = nls(y~(1*N*exp(r*x))/(1+N*(exp(r*x)-1)), start=list(N=0.01,
r=0.6), control = list(maxiter = 500), alg="plinear", trace = TRUE)
par = coef(fitModel)
y2 = myfunc(x, par)
jpeg(paste(path, ".jpg", sep=""))
plot(x, 1-y2, type="l", ylab="fraction of detection", xlab="distance")
points(x, 1-y)
dev.off()
write(par[1], file=paste(path, "_parameter", sep=""), append = FALSE)
write(par[2], file=paste(path, "_parameter", sep=""), append = TRUE)
residual_sumofsquares = sum(resid(fitModel)^2);
write(residual_sumofsquares, file=paste(path, "_residualsumofsquares",
sep=""), append = FALSE)
q()
--------------------------------------------------------------------------------------------------------------------
The script is called using the following command:
R --vanilla --file=r_nonlinear_leastsquare.R --args copy_decay_YEAST04876
The 'copy_decay_YEAST04876' has been enclosed in this email.
*On execution, this throws an error:*
Error in qr.solve(QR.B, cc) : singular matrix 'a' in solve
Calls: nls -> <Anonymous> -> qr.solve
Kindly help me in solving this issue.
Regards,
--
*Arpit Jain*
PhD student at Goethe Universität, Frankfurt, Germany
CALIPSO, Marie-Curie ITN,
Ph :- +49 157 50913290
More information about the R-help
mailing list