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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:44:39+00:00 2026-06-18T08:44:39+00:00

I have subset some data frames based on a three month period and named

  • 0

I have subset some data frames based on a three month period and named like jfm (for January to March) , fma(February to April) , mam(March to May) … until ond(October to December). I wish to run similar analysis on all of these data using several variables as regressors. Below I show how I run the analysis for one the two subset data frames using one of the pollutants as a regressor. I am interested to run the analysis for all pollutants (pm10median, pm25median, o3median and so2median) each entered into the model separately. How can I do this analysis for all data frames?

library(gamair) 
library(mgcv)
data(chicago) 
chicago$date<-seq(from=as.Date("1987-01-01"), to=as.Date("2000-12-31"),length=5114)


chicago$month<-as.numeric(format(chicago$date,"%m")) ## create month
jfm <- subset(chicago, month %in% c(1:3) )      ## subset data for January to March
fma <- subset(chicago, month %in% c(2:4) )  ## February to April
mam <- subset(chicago, month %in% c(3:5) )  ## March to may


jfm$trend<-seq(dim(jfm)[1])   ## cretae a trend for specific df based on dimension of the df
fma$trend<-seq(dim(fma)[1])   ## trend for df fma


## Regress each pollutant separately on death for the first subset

model1<-gam(death ~  pm10median + s(trend,k=21)+ s(tmpd,k=6) ,family=quasipoisson,na.action=na.omit,data=jfm) 

model2<-gam(death ~  pm10median + s(trend,k=21)+ s(tmpd,k=6) ,family=quasipoisson,na.action=na.omit,data=fma) 
  • 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-18T08:44:41+00:00Added an answer on June 18, 2026 at 8:44 am
    # create a function that defines the exact regression
    # you want to run on all three-month data sets
    fun <- 
        function( y , x ){
    
            # store each of the regression outputs into an object
            a <- gam(
                death ~  pm10median + s(trend,k=21)+ s(tmpd,k=6) ,
                family = quasipoisson , 
                na.action = na.omit ,
                data = x[ x$month %in% y , ]
            ) 
            b <- gam(
                death ~  pm25median + s(trend,k=21)+ s(tmpd,k=6) ,
                family = quasipoisson , 
                na.action = na.omit ,
                data = x[ x$month %in% y , ]
            ) 
    
            # return each of the regressions as a list
            list( a , b )
        }
    
    # define which three-month groups you want to run it on
    months <- cbind( 1:10 , 2:11 , 3:12 )
    
    # now just run the function for each row in `months`
    results <- apply( months , 1 , fun , x = chicago )
    
    # look at the whole thing
    results
    
    # extract jfm, for example
    jfm <- results[[1]]
    
    # extract fma (and print it to the screen as well)
    ( fma <- results[[2]] )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the data frame df and I want to subset df based on
I have some observed data by hour. I am trying to subset this data
I have some data that looks like this: List_name Condition1 Condition2 Situation1 Situation2 List1
I have a dataframe called split2_data (actually a drop-leveled subset of a bigger data
I have some data either in a list of lists or a list of
I have the following data frame from which I would like to extract rows
Currently, I have an Excel spreadsheet with some data and a command button that
I have imported data relating to about 70 human subjects from three data tables
I have some data to be processed, with each block being responsible for a
I have been doing some data analysis in R and I am trying to

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.