Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use a <a href="http://stat.ethz.ch/R-manual/R-devel/library/utils/html/txtProgressBar.html" rel="nofollow">txtProgressBar</a> to keep track of how far you've progressed through some process.</p> <p>I'm not familiar enough with the function you reference to know exactly where it should go, but just from eyeballing it, it looks like it could spend a healthy portion of its time in the loop beginning with:</p> <pre><code># Iteratively updating the model with addition of one block of variable(s) # Also: extracting the loglikelihood of each estimated model for(j in 1:length(blocks)) </code></pre> <p>If you were to use:</p> <pre><code>pb &lt;- txtProgressBar(style=3) for(j in 1:length(blocks)) setTxtProgressBar(pb, j/length(blocks)) ... } close(pb) </code></pre> <p>That may give you what you're looking for. Note that some displays work better with certain style progress bars than others. You may have more luck trying different styles when creating your progressbar if the output looks funny to you using the code I posted.</p> <p>There is no way for R to know in advance how long a generic function will take to complete, so there's not a generic answer here. Here's the function you posted with progress bars in each loop.</p> <pre><code>forward.lmer &lt;- function( start.model, blocks, max.iter=1, sig.level=FALSE, zt=FALSE, print.log=TRUE) { # forward.lmer: a function for stepwise regression using lmer mixed effects models # Author: Rense Nieuwenhuis # Initialysing internal variables log.step &lt;- 0 log.LL &lt;- log.p &lt;- log.block &lt;- zt.temp &lt;- log.zt &lt;- NA model.basis &lt;- start.model # Maximum number of iterations cannot exceed number of blocks if (max.iter &gt; length(blocks)) max.iter &lt;- length(blocks) pb &lt;- txtProgressBar(style=3) # Setting up the outer loop for(i in 1:max.iter) { #each iteration, update the progress bar. setTxtProgressBar(pb, i/max.iter) models &lt;- list() # Iteratively updating the model with addition of one block of variable(s) # Also: extracting the loglikelihood of each estimated model for(j in 1:length(blocks)) { models[[j]] &lt;- update(model.basis, as.formula(paste(". ~ . + ", blocks[j]))) } LL &lt;- unlist(lapply(models, logLik)) # Ordering the models based on their loglikelihood. # Additional selection criteria apply for (j in order(LL, decreasing=TRUE)) { ############## ############## Selection based on ANOVA-test ############## if(sig.level != FALSE) { if(anova(model.basis, models[[j]])[2,7] &lt; sig.level) { model.basis &lt;- models[[j]] # Writing the logs log.step &lt;- log.step + 1 log.block[log.step] &lt;- blocks[j] log.LL[log.step] &lt;- as.numeric(logLik(model.basis)) log.p[log.step] &lt;- anova(model.basis, models[[j]])[2,7] blocks &lt;- blocks[-j] break } } ############## ############## Selection based significance of added variable-block ############## if(zt != FALSE) { b.model &lt;- summary(models[[j]])@coefs diff.par &lt;- setdiff(rownames(b.model), rownames(summary(model.basis)@coefs)) if (length(diff.par)==0) break sig.par &lt;- FALSE for (k in 1:length(diff.par)) { if(abs(b.model[which(rownames(b.model)==diff.par[k]),3]) &gt; zt) { sig.par &lt;- TRUE zt.temp &lt;- b.model[which(rownames(b.model)==diff.par[k]),3] break } } if(sig.par==TRUE) { model.basis &lt;- models[[j]] # Writing the logs log.step &lt;- log.step + 1 log.block[log.step] &lt;- blocks[j] log.LL[log.step] &lt;- as.numeric(logLik(model.basis)) log.zt[log.step] &lt;- zt.temp blocks &lt;- blocks[-j] break } } } } close(pb) ## Create and print log log.df &lt;- data.frame(log.step=1:log.step, log.block, log.LL, log.p, log.zt) if(print.log == TRUE) print(log.df, digits=4) ## Return the 'best' fitting model return(model.basis) } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload