Dear R-users, I have the following problem: I am running the function 'pvcm' from the 'plm' Panel Data package. Inside this function 'solve' is called and gives for a certain individual data series an exception because of singularity. I would like to know which individual data series causes this error. I tried to debug it, but this is truly painful, as solve is called inside of 'lapply' and there are over 5,000 individual data series in the panel. Now, what I would like to do is to count the calls to 'solve' inside the function, so I can see, where the function throws the exception. I tried to use 'trace' with a count variable, but I have no clue how to define a global variable to be used by trace and updated at every call.....is there another approach? Best Simon
This is where <<- is helpful: > N <- 0 ; trace(solve, quote(N <<- N + 1), print=FALSE) Tracing function "solve" in package "base" [1] "solve" > lapply(3:0, function(i)solve(diag(i,3), 1:3)) Error in solve.default(diag(i, 3), 1:3) : Lapack routine dgesv: system is exactly singular: U[1,1] = 0 > N [1] 4 You can also set options(error=recover) to look at the state of things when the error occurs. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf > Of Simon Zehnder > Sent: Tuesday, February 26, 2013 2:53 AM > To: r-help at r-project.org help > Subject: [R] Count function calls > > Dear R-users, > > I have the following problem: I am running the function 'pvcm' from the 'plm' Panel Data > package. Inside this function 'solve' is called and gives for a certain individual data series > an exception because of singularity. I would like to know which individual data series > causes this error. I tried to debug it, but this is truly painful, as solve is called inside of > 'lapply' and there are over 5,000 individual data series in the panel. > > Now, what I would like to do is to count the calls to 'solve' inside the function, so I can > see, where the function throws the exception. I tried to use 'trace' with a count variable, > but I have no clue how to define a global variable to be used by trace and updated at > every call.....is there another approach? > > > Best > > Simon > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
Hello. Another thing you may want to do depends on whether you are using model="within" (the default) or model="random". In the first case, pvcm() estimates separate regressions, so you just need to loop lm() on individual indices to spot where it fails. In the second case, what you may want to do is try a similar estimator: pmg(..., model="mg"), which is an unweighted version of Swamy's estimator in pvcm() and a simpler function to read and modify, possibly using the global assignment operator '<<-' as already suggested by William to output diagnostics. Best, Giovanni> -----Original Message----- > From: r-help-bounces at r-project.org[mailto:r-help-bounces at r-project.org] On Behalf> Of Simon Zehnder > Sent: Tuesday, February 26, 2013 2:53 AM > To: r-help at r-project.org help > Subject: [R] Count function calls > > Dear R-users, > > I have the following problem: I am running the function 'pvcm' fromthe 'plm' Panel Data> package. Inside this function 'solve' is called and gives for acertain individual data series> an exception because of singularity. I would like to know whichindividual data series> causes this error. I tried to debug it, but this is truly painful, assolve is called inside of> 'lapply' and there are over 5,000 individual data series in the panel. > > Now, what I would like to do is to count the calls to 'solve' insidethe function, so I can> see, where the function throws the exception. I tried to use 'trace'with a count variable,> but I have no clue how to define a global variable to be used by traceand updated at> every call.....is there another approach? > > > Best > > Simon > > ______________________________________________? Ai sensi del D.Lgs. 196/2003 si precisa che le informazi...{{dropped:12}}