Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7788125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:53:43+00:00 2026-06-01T20:53:43+00:00

I’m running some some functions in R that sometimes take quite a long time

  • 0

I’m running some some functions in R that sometimes take quite a long time to complete (anywhere from 10 minutes to 4 hours). Specifically, I am using a function (forward.lmer()) written by Rense Nieuwenhuis that can be found here. I’d like to know if there is any way for R to tell the % complete the operation is. Especially, when the operation has been running for over an hour, I’d like to know how close it is to completion.

Is there a generic function that will allow me to know the progress of any given function?
What I would ideally like to know is if there is a function like so:

percentComplete()
forward.lmer(inputs)

That will then tell me about how close to complete the function is?

The first thing I tried was using library(time) and doing the following:

time<-getTime()
function(inputs)
timeReport(time)

But this just tells me how long it took to complete the function upon completion. Is there a way to know how the function is progressing (percentage completed) as it is running?

I’d love to increase the efficiency of this function, in addition, but that is another question. Thanks all!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:53:46+00:00Added an answer on June 1, 2026 at 8:53 pm

    You can use a txtProgressBar to keep track of how far you’ve progressed through some process.

    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:

    # 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))
    

    If you were to use:

    pb <- txtProgressBar(style=3)
    for(j in 1:length(blocks))
      setTxtProgressBar(pb, j/length(blocks))
      ...
    }
    close(pb)
    

    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.

    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.

    forward.lmer <- 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 <- 0
        log.LL <- log.p <- log.block <- zt.temp <- log.zt <- NA
        model.basis <- start.model
    
        # Maximum number of iterations cannot exceed number of blocks
        if (max.iter > length(blocks)) max.iter <- length(blocks)
          pb <- 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 <- 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]] <- update(model.basis, as.formula(paste(". ~ . + ", blocks[j])))
            }
    
            LL <- 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] < sig.level)
                {
    
                  model.basis <- models[[j]]
    
                  # Writing the logs
                  log.step <- log.step + 1
                  log.block[log.step] <- blocks[j]
                  log.LL[log.step] <- as.numeric(logLik(model.basis))
                  log.p[log.step] <- anova(model.basis, models[[j]])[2,7]
    
                  blocks <- blocks[-j]
    
                  break
                }
              }
    
              ##############
              ############## Selection based significance of added variable-block
              ##############
    
              if(zt != FALSE)
              {
                b.model <- summary(models[[j]])@coefs
                diff.par <- setdiff(rownames(b.model), rownames(summary(model.basis)@coefs))
                if (length(diff.par)==0) break
                sig.par <- FALSE
    
                for (k in 1:length(diff.par))
                {
                  if(abs(b.model[which(rownames(b.model)==diff.par[k]),3]) > zt)
                  {
                    sig.par <- TRUE
                    zt.temp <- b.model[which(rownames(b.model)==diff.par[k]),3]
                    break
                  }
                }
    
                if(sig.par==TRUE)
                {
                  model.basis <- models[[j]]
    
                  # Writing the logs
                  log.step <- log.step + 1
                  log.block[log.step] <- blocks[j]
                  log.LL[log.step] <- as.numeric(logLik(model.basis))
                  log.zt[log.step] <- zt.temp
                  blocks <- blocks[-j]
    
                  break
                }
              }
            }
      }
      close(pb)
    
      ## Create and print log
      log.df <- 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)
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am currently running into a problem where an element is coming back from
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.