Poly is a function in R that generates a basis matrix of polynomial transformations.
Questions tagged [poly]
56 questions
0
votes
2 answers
R caret's train with poly of a given degree
I'm rolling a loop over the degree of the approximating polynomial for training with caret
ds = 1:20
for(i in 1:length(ds)){
print(i)
d=ds[i]
fit = train(y~poly(x,degree=d),data=training,method="lm",trControl=fitCtrl)
# other…

Fabio
- 211
- 1
- 8
0
votes
1 answer
Sml program -> confusion on "AS syntax error"
so I have to write a small program in SML ->>
a file named ‘p0.sml’ that contains a function named epoly, which accepts as parameters a list of real values a0 through an, and a single real value x. The list contains the coefficients of a polynomial…

Matalic17
- 3
- 1
0
votes
0 answers
lm produces different coefficients in r
attach(mtcars)
poly_model <- lm(mpg ~ poly(hp,degree=1), data = mtcars)
summary(poly_model)
lin_model <- lm(mpg ~ hp, data = mtcars)
summary(lin_model)
x <- with(mtcars, seq(min(hp), max(hp), length.out=2000))
y1 <- predict(poly_model, newdata =…
0
votes
1 answer
How is the fitted.values from lm function calculated?
I'm adjusting a response surface using the lm function on R. On output, using fit[["fitted.values"]], the reported values are consistent with the actual values. However, when I use the coefficients generated for each effect (Intercept, x1, x1*x2)…

Sthln
- 71
- 6
0
votes
1 answer
How to find a turning point of quadratic term for different categories?
I have built a logistic regression with polynomial relationship with variable age, which I include in the model as an interaction with variable sex. I also have other independent and control variables.
The main question is: How do I find a turning…

Saina V
- 9
- 4
0
votes
1 answer
Fitting an R linear model with poly() gives incorrect coefficients
I have the following data:
Which looks quadratic. If I fit a quadratic curve using I() I get coefficients that make sense:
> modelI = lm(
formula = Y ~ I(X^2) + I(X),
data = df
)
> modelI
Call:
lm(formula = Y ~ I(X^2) + I(X), data =…

GMSL
- 355
- 2
- 11
0
votes
1 answer
Poly() with raw=TRUE provides different result then I()
After running some polynomial fitting on wavelength data, I encountered quite different results for poly() with raw=TRUE enabled and using `I()'.
Some side-information: ln and T_T0 are colomns of the fbg_data_simp dataframe
reg_fbg<-lm(ln ~…

pnivelle
- 1
- 1
0
votes
1 answer
Interpretation of coefficients 2nd degree polynomial in R
I made a trend surface using the lm and poly functions in R.
The summary of my results looks as follows:
> summary(tls.lm)
Call:
lm(formula = DEM_small_domain_TLS_5cm ~ poly(x, y, degree = 2),
data = tlsDF)
Residuals:
Min 1Q …

PMouton
- 1
- 4
0
votes
1 answer
How to make the dredge (MuMin) output from a model with "poly(x, 2)*factor" show both polynomial terms?
Model structure:
fixed = Y ~ poly(x, 2) * factor
The dredge output shows only:
[...] factor, poly(x,2) , factor:poly(x,2)
instead of:
[...] factor, poly(x,1) , poly(x,2) , factor:poly(x,1) , factor:poly(x,2)
It is unclear for me how to interpret…
0
votes
1 answer
R: How to plot custom range of polynomial produced by lm poly fit
I'm confused by the coefficients produced by the output of lm
Here's a copy of the data I'm working…

FreelanceConsultant
- 13,167
- 27
- 115
- 225
0
votes
1 answer
Find both solutions for X in second-degree polynomial equation given Y in R
I'm just starting to use R so it is possible that I'm not understanding the functions correctly.
I have length and age data from the literature and I have measured some specimens. I need to find the age of these specimens I measured based on the…

Agnese Lanzetti
- 1
- 1
0
votes
1 answer
Predicting multivariant linear model in R
I have a question regarding a prediction for linear model with two variants (multivariant). I am trying to use a model I trained to predict new data. I have this code that trains z in terms of x and y. The data is around 60,000 rows:
fit <- lm(z ~…

Lush_coding
- 33
- 4
0
votes
1 answer
How can I use lm() with poly() and ggeffect() to plot model effects when variable in quadratic term is not being plotted
I am trying to plot model effects using the ggeffects package. Usually this is no problem. However, I have a model in which there is an interaction between a quadratic term and a first order term (Ex: var_a^2:var_b). In my actual model there are…

jmar
- 73
- 6
0
votes
1 answer
R: Problems of wrapping polynomial regression in a function
When I was doing polynomial regression, I tried to put fits with different degree of polynomial into a list, so I wrapped the glm into a function:
library(MASS)
myglm <- function(dop) {
# dop: degree of polynomial
glm(nox ~ poly(dis, degree…

Frank
- 136
- 1
- 10
0
votes
1 answer
R How to construct polynom with form c0 + c1 * x + .. + cn * x^n from orthogonal lm (with poly(raw=F))
How can I extract the coefficients of an orthogonal polynomial regression in R?
It works like a charm with a raw regression:
#create datas
set.seed(120)
x= 1:20
y=x^2 + rnorm(length(x),0,10)
datas = data.frame(x,y)
#compute raw model with function…

jakzr
- 129
- 1
- 1
- 11