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 8873233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:24:48+00:00 2026-06-14T18:24:48+00:00

While running model0 found below I got an error message Error in eval(expr, envir,

  • 0

While running model0 found below I got an error message “ Error in eval(expr, envir, enclos) : could not find function “Lag” . Before posting this message I have scanned this forum and the web, but could not find relevant solution. I believe the error in my model is not probably due to Lag function as other models (1 and 2) shown below could run without encountering any problem.

My main motive was to run a GAM model by looping through a list of explanatory variables and their lags.

library(quantmod)
library(gamair) 
library(mgcv) 
data(chicago) 

names(chicago)

varlist0 <- c("pm10median", "pm25median", "o3median", "so2median")

model0<- lapply(varlist0, function(x) {
  gam(substitute(death ~ s(time,bs="cr",k=200)+ s(tmpd,bs="cr") + Lag(i,0:4) , list(i = as.name(x))),family=quasipoisson,na.action=na.omit, data=chicago)

})

Gam + Lag with no error message:

model1<- gam(death ~ s(time,bs="cr",k=200)+ s(tmpd,bs="cr") + Lag(pm10median, 0:4),family=quasipoisson,na.action=na.omit, data=chicago)

Lm with Lag and no error message:

hsb2 <- read.csv("http://www.ats.ucla.edu/stat/data/hsb2.csv")
varlist <- names(hsb2)[8:11]   
models <- lapply(varlist, function(x) {
    lm(substitute(read ~ Lag(i,0:4) , list(i = as.name(x))), data = hsb2)
})

I am unable to decipher the cause of this error. What have I done wrong in the first model?

  • 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-14T18:24:50+00:00Added an answer on June 14, 2026 at 6:24 pm

    I can’t say the exact cause, but it has something to do with the environment in which mgcv is evaluating the formula. A safer approach than substitute is to do something like the following:

    varlist0 <- c("pm10median", "pm25median", "o3median", "so2median")
    model0 <- lapply(varlist0,function(v) {
        f <- sprintf("death ~ s(time,bs='cr',k=200)+s(tmpd,bs='cr') + Lag(%s,0:4)",v)
        gam(as.formula(f),family=quasipoisson,na.action=na.omit,data=chicago)
    })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

while running: rake snorby:setup getting below error: rake aborted! You have already activated rake
While running the code I've included below I receive the error EntityCommandExecutionException was unhandled
I got the following error while running my perl script with the negative lookaround
I am getting this error While running this LoadError: Expected /home/user/Desktop/Tripurari/myapp/app/models/host.rb to define Host##
While running my android application in emulator,it shows The application is not installed in
I am getting this error when running ./manage.py migrate app_name While loading migration 'whatever.0001_initial':
I am getting a error while running it. The Error is : File binary_Light.py,
While running example of scribe to login with google it is showing following error.
While running my application the user has the possibility to show or hide a
While running my application (which does a good bit of custom drawing) I get

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.