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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:50:26+00:00 2026-05-19T23:50:26+00:00

Suppose, there is some data.frame foo_data_frame and one wants to find regression of the

  • 0

Suppose, there is some data.frame foo_data_frame and one wants to find regression of the target column Y by some others columns. For that purpose usualy some formula and model are used. For example:

linear_model <- lm(Y ~ FACTOR_NAME_1 + FACTOR_NAME_2, foo_data_frame)

That does job well if the formula is coded statically. If it is desired to root over several models with the constant number of dependent variables (say, 2) it can be treated like that:

for (i in seq_len(factor_number)) {
  for (j in seq(i + 1, factor_number)) {
    linear_model <- lm(Y ~ F1 + F2, list(Y=foo_data_frame$Y,
                                         F1=foo_data_frame[[i]],
                                         F2=foo_data_frame[[j]]))
    # linear_model further analyzing...
  }
}

My question is how to do the same affect when the number of variables is changing dynamically during program running?

for (number_of_factors in seq_len(5)) {
   # Then root over subsets with #number_of_factors cardinality.
   for (factors_subset in all_subsets_with_fixed_cardinality) {
     # Here I want to fit model with factors from factors_subset.
     linear_model <- lm(Does R provide smth to write here?)
   }
}
  • 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-05-19T23:50:27+00:00Added an answer on May 19, 2026 at 11:50 pm

    See ?as.formula, e.g.:

    factors <- c("factor1", "factor2")
    as.formula(paste("y~", paste(factors, collapse="+")))
    # y ~ factor1 + factor2
    

    where factors is a character vector containing the names of the factors you want to use in the model. This you can paste into an lm model, e.g.:

    set.seed(0)
    y <- rnorm(100)
    factor1 <- rep(1:2, each=50)
    factor2 <- rep(3:4, 50)
    lm(as.formula(paste("y~", paste(factors, collapse="+"))))
    
    # Call:
    # lm(formula = as.formula(paste("y~", paste(factors, collapse = "+"))))
    
    # Coefficients:
    # (Intercept)      factor1      factor2  
    #    0.542471    -0.002525    -0.147433
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose that you have a data frame with many rows and many columns. The
Suppose I have a data frame, df, that looks like: f t1 t2 t3
Suppose we have some data that looks like so R_Id Nm Base Dest Proj
I have a simple application that fetches some data from ONE table on db
Suppose there is a System A which gives some output. This output is used
Propose to consider the following problem. Suppose we have some composite object. Are there
Suppose there is an image_url column in database. I want the user to choose
Suppose there is a table A which has a column AccessRights which is multivalued(
Suppose I'm messing about with some data by binding vectors together, as I'm wont
Suppose I have a text file with some data I want to retrieve lost

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.