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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:25:00+00:00 2026-06-17T23:25:00+00:00

I would like to specify a regression in R that would estimate coefficients on

  • 0

I would like to specify a regression in R that would estimate coefficients on x that are conditional on a third variable, z, being greater than 0. For example

y ~ a + x*1(z>0) + x*1(z<=0)

What is the correct way to do this in R using formulas?

  • 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-17T23:25:02+00:00Added an answer on June 17, 2026 at 11:25 pm

    The “:” (colon) operator is used to construct conditional interactions (when used with disjoint predictors constructed with I). Should be used with predict

    > y=rnorm(10)
    > x=rnorm(10)
    > z=rnorm(10)
    > mod <- lm(y ~ x:I(z>0) )
    > mod
    
    Call:
    lm(formula = y ~ x:I(z > 0))
    
    Coefficients:
        (Intercept)  x:I(z > 0)FALSE   x:I(z > 0)TRUE  
          -0.009983        -0.203004        -0.655941  
    
    > predict(mod, newdata=data.frame(x=1:10, z=c(-1, 1)) )
             1          2          3          4          5          6          7 
    -0.2129879 -1.3218653 -0.6189968 -2.6337471 -1.0250057 -3.9456289 -1.4310147 
             8          9         10 
    -5.2575108 -1.8370236 -6.5693926 
    > plot(1:10, predict(mod, newdata=data.frame(x=1:10, z=c(-1)) )  )
    > lines(1:10, predict(mod, newdata=data.frame(x=1:10, z=c(1)) ) )
    

    Might help to look at its model matrix:

    > model.matrix(mod)
       (Intercept) x:I(z > 0)FALSE x:I(z > 0)TRUE
    1            1      -0.2866252     0.00000000
    2            1       0.0000000    -0.03197743
    3            1      -0.7427334     0.00000000
    4            1       2.0852202     0.00000000
    5            1       0.8548904     0.00000000
    6            1       0.0000000     1.00044600
    7            1       0.0000000    -1.18411791
    8            1       0.0000000    -1.54110256
    9            1       0.0000000    -0.21173300
    10           1       0.0000000     0.17035257
    attr(,"assign")
    [1] 0 1 1
    attr(,"contrasts")
    attr(,"contrasts")$`I(z > 0)`
    [1] "contr.treatment"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Similar to this Java question . I would like to specify that a variable
I would like to specify that I want FEATURE_INDETERMINATE_PROGRESS for my Activity . It
I'm using NUnit mocks and would like to specify that I expect a call
I would like to regression test t-sql stored procedures. My idea is to specify
I would like to specify that firefox select a range. I can do this
I would like to specify that a decimal field for a price must be
I would like to specify a default sort order in my model. So that
I would like to specify that: :output_core depends on :build_core :build_extension depends on :build_core
I have two classes that I would like to specify as follows: class Club
I would like to specify the regular expression during run-time, not compile-time. So that

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.