Skip to main content
added 546 characters in body
Source Link

This is an old question, but it may help you.

You can use ConsReg package.

See the example below:

Imagine you want the following constraints in your parameters:

  • All coefficients will be less than 1 and greater than -1
  • $x_4 < 0.2$
  • The coefficient of $x_3$ and $x_3^2$ must satisfied: $(x_3 + x_3^2 > 0.01$)

Your can put this constraints to the the function in a easy way:

constraints = '(x3 + `I(x3^2)`) > .01, x4 < .2'

LOWER = -1, UPPER = 1

And finally, set initial parameters that have to fulfill the constraints above:

ini.pars.coef = c(-.4, .12, -.004, 0.1, 0.1, .15)

Complete example:

require(ConsReg)
data("fake_data")
fit2 = ConsReg(formula = y~x1+x2+x3+ I(x3^2) + x4, data = fake_data,
            family = 'gaussian',
            constraints = '(x3 + `I(x3^2)`) > .01, x4 < .2',
            optimizer = 'mcmc',
            LOWER = -1, UPPER = 1,
            ini.pars.coef = c(-.4, .12, -.004, 0.1, 0.1, .15))

This is an old question, but it may help you.

You can use ConsReg package.

See the example below:

require(ConsReg)
data("fake_data")
fit2 = ConsReg(formula = y~x1+x2+x3+ I(x3^2) + x4, data = fake_data,
            family = 'gaussian',
            constraints = '(x3 + `I(x3^2)`) > .01, x4 < .2',
            optimizer = 'mcmc',
            LOWER = -1, UPPER = 1,
            ini.pars.coef = c(-.4, .12, -.004, 0.1, 0.1, .15))

This is an old question, but it may help you.

You can use ConsReg package.

See the example below:

Imagine you want the following constraints in your parameters:

  • All coefficients will be less than 1 and greater than -1
  • $x_4 < 0.2$
  • The coefficient of $x_3$ and $x_3^2$ must satisfied: $(x_3 + x_3^2 > 0.01$)

Your can put this constraints to the the function in a easy way:

constraints = '(x3 + `I(x3^2)`) > .01, x4 < .2'

LOWER = -1, UPPER = 1

And finally, set initial parameters that have to fulfill the constraints above:

ini.pars.coef = c(-.4, .12, -.004, 0.1, 0.1, .15)

Complete example:

require(ConsReg)
data("fake_data")
fit2 = ConsReg(formula = y~x1+x2+x3+ I(x3^2) + x4, data = fake_data,
            family = 'gaussian',
            constraints = '(x3 + `I(x3^2)`) > .01, x4 < .2',
            optimizer = 'mcmc',
            LOWER = -1, UPPER = 1,
            ini.pars.coef = c(-.4, .12, -.004, 0.1, 0.1, .15))

added 25 characters in body
Source Link
lennon310
  • 2.7k
  • 2
  • 24
  • 31

This is an old question, but it may help you.

You can use ConsReg package: cran.r-project.org/web/packages/ConsReg/indexConsReg package.html

See the example below:

require(ConsReg)
data("fake_data")
fit2 = ConsReg(formula = y~x1+x2+x3+ I(x3^2) + x4, data = fake_data,
            family = 'gaussian',
            constraints = '(x3 + `I(x3^2)`) > .01, x4 < .2',
            optimizer = 'mcmc',
            LOWER = -1, UPPER = 1,
            ini.pars.coef = c(-.4, .12, -.004, 0.1, 0.1, .15))
 
```

This is an old question, but it may help you.

You can use ConsReg package: cran.r-project.org/web/packages/ConsReg/index.html

See the example below:

require(ConsReg)
data("fake_data")
fit2 = ConsReg(formula = y~x1+x2+x3+ I(x3^2) + x4, data = fake_data,
            family = 'gaussian',
            constraints = '(x3 + `I(x3^2)`) > .01, x4 < .2',
            optimizer = 'mcmc',
            LOWER = -1, UPPER = 1,
            ini.pars.coef = c(-.4, .12, -.004, 0.1, 0.1, .15))
 
```

This is an old question, but it may help you.

You can use ConsReg package.

See the example below:

require(ConsReg)
data("fake_data")
fit2 = ConsReg(formula = y~x1+x2+x3+ I(x3^2) + x4, data = fake_data,
            family = 'gaussian',
            constraints = '(x3 + `I(x3^2)`) > .01, x4 < .2',
            optimizer = 'mcmc',
            LOWER = -1, UPPER = 1,
            ini.pars.coef = c(-.4, .12, -.004, 0.1, 0.1, .15))

Source Link

This is an old question, but it may help you.

You can use ConsReg package: cran.r-project.org/web/packages/ConsReg/index.html

See the example below:

require(ConsReg)
data("fake_data")
fit2 = ConsReg(formula = y~x1+x2+x3+ I(x3^2) + x4, data = fake_data,
            family = 'gaussian',
            constraints = '(x3 + `I(x3^2)`) > .01, x4 < .2',
            optimizer = 'mcmc',
            LOWER = -1, UPPER = 1,
            ini.pars.coef = c(-.4, .12, -.004, 0.1, 0.1, .15))

```