Poly is a function in R that generates a basis matrix of polynomial transformations.
Questions tagged [poly]
56 questions
5
votes
2 answers
Why does lm() with the subset argument give a different answer than subsetting in advance?
I am using lm() on a training set of data that includes a polynomial. When I subset in advance with [ ] I get different coefficients compared to using the subset argument in the lm() function call. Why?
library(ISLR2)
set.seed (1)
train <-…

itsMeInMiami
- 2,324
- 1
- 13
- 34
4
votes
1 answer
How to include a spatial lag of an explanatory variable in a panel spatial model?
I am doing a spatial durbin model with spml function (splm package), I have included as regressors a polynom (grade 2) and obviosly I need to include its spatial lag too.
Unfortunately the function slag and lag.listw don't work with a poly…

Silvia
- 41
- 1
3
votes
1 answer
Issues predicting with `nlme::gls`quadratic model fitted with `poly(..., 2)`
I have fitted a quadratic model with a variance structure that allows different variance levels per level of a factor, and I’m having trouble predicting on a new data set with 2 entries only. Here’s a reproducible…

Ceres
- 163
- 7
3
votes
1 answer
Combine like terms in a polynomial equation
Not homework or anything, just personal interests on coding, learning it by myself currently.
Found this question interesting online.
Think if we have a list of number that's
1 2 2 4 3 6 4 2 5 4
that equals to 1x^2+2^4+3^6+4^2+5^4
How can I…

Kim James
- 31
- 5
3
votes
1 answer
How to eliminate variables with p value > 0.7 before computing stepwise polynomial regression?
I am trying to run a stepwise regression using AIC (through step) with 1,400 variables, but my computer just freezes. It works if I include <300 variables (after 13 hrs of running).
Is there a way to eliminate some of the variables (if p-value >.7)…

RegressionMan
- 63
- 5
3
votes
2 answers
dplyr: Using poly function to generate polynomial coefficients
I want to append polynomial coefficient to data.frame as the example given below:
df1 <-
structure(list(
Y = c(4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 16, 16, 16,
16, 16, 32, 32, 32, 32, 32, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 16,
16,…

MYaseen208
- 22,666
- 37
- 165
- 309
2
votes
1 answer
Error using 'poly': 'degree' must be less than number of unique points while using 'effects' package
I am trying to use the effects package to create plots of effects in a linear mixed model. I specify the model
fit1 <- lmer(Values ~ stimuli + timeperiod + scale(poly(distance.code,3,raw=FALSE))*habitat + wind.speed + (1|location.code), data=ex.df,…

parksnrec1
- 69
- 7
2
votes
1 answer
Is there an inverse function for poly?
We can generate orthogonal polynomials in R with
pp <- poly(cars$speed, 2)
Is there a way to get the original values out of the result pp (inverse poly function)?
In other words, what should the function f look like that returns the following…

Andri Signorell
- 1,279
- 12
- 23
2
votes
2 answers
Use poly on dataframe column
I have a dataframe like so
wood <- read_csv("/Users/name/Desktop/AR/Exercise data-20201109/woodstrength.csv")
I select x and y
x <- wood %>% select(Conc)
y <- wood %>% select(Strength)
The relationship can be modeled with a polynomial of degree 2…

Marcel Braasch
- 1,083
- 1
- 10
- 19
2
votes
0 answers
lmer poly() function on interactions
My goal is to run a quadratic function using several IVs across time within subject. I have come across some code and am a little confused. Below is a reproducible example of what I am trying to run. Following the code will be my…

Severe_Dragomere
- 51
- 4
2
votes
1 answer
How to plot lm slope modeled using poly()?
I need to plot the relationship between x and y where polynomials of x predict y. This is done using the poly() function in order to ensure polynomials are orthogonal.
How do I plot this relationship considering linear, quadratic and cubic terms…

Eric M
- 23
- 3
1
vote
1 answer
Separate F tests for different order terms in a polynomial with ANOVA in R?
I have a regression model with a polynomial term and I am using ANOVA to test for the significance of the terms. I have been asked to report the linear and quadratic terms separately for the polynomial term, but can't seem to do this in R using…

corn_bunting
- 349
- 1
- 11
1
vote
2 answers
Why does R keep complaining that I'm giving the wrong type of matrix to my lm model when I'm not using matrices at all?
Specifically, I'm getting the error
Error: variable 'poly(x, degree = i, raw = TRUE)' was fitted with type "nmatrix.2" but type "nmatrix.5" was supplied
I was provided this starting code by my professor:
f = function(x) {
return(x**2)
}
#Set…

Mikayla Eckel Cifrese
- 188
- 7
1
vote
1 answer
modifying lm coefficients - why is predict output shifted like it had modified intercept?
I have a lm model with mortality data depending on daily temperature. To estimate a possible adaptation to climate change, I would like to reduce the slope of the curve by 10%.
Therefore, I modified the slope-coefficients of the lm model by…

Lyzzie777
- 13
- 4
1
vote
1 answer
Why are polynomial multiple regression coefficients missing in poly?
I ran a polynomial multiple regression in R using poly, and in the output the coefficients of some combinations of the two variables (Unc and Window) are seem to be missing, and I cannot get my head around it.
The input data can be downloaded from…

Istvan Gabor Hatvani
- 161
- 2
- 13