Displaying 20 results from an estimated 10000 matches similar to: "Interpretation of poly(x, y, degree=2) coefficients"
2011 Feb 03
3
interpret significance from the contr.poly() function
Hello R-help
I don’t know how to interpret significance from the contr.poly() function . From
the example below
: how can I tell if data has a significant Linear/quadratic/cubic trend?
> contr.poly(4, c(1,2,4,8))
.L .Q .C
[1,] -0.51287764 0.5296271 -0.45436947
[2,] -0.32637668 -0.1059254 0.79514657
[3,] 0.04662524 -0.7679594 -0.39757328
[4,] 0.79262909
2008 Apr 23
0
poly() can exceed degree k - 1 for k distinct points (PR#11251)
The poly() function can create more variables than can be fitted when
there are replicated values. In the example below, 'x' has only 5
distinct values, but I can apparently fit a 12th-degree polynomial with
no error messages or even nonzero coefficients:
R> x = rep(1:5,3)
R> y = rnorm(15)
R> lm(y ~ poly(x, 12))
Call:
lm(formula = y ~ poly(x, 12))
Coefficients:
2010 Aug 03
0
Issue with prediction from lm object with poly
DDear developeRs,
about a year ago, Alex Stolpovsky posted an issue with predict.lm on a
fit generated using poly with the raw=TRUE option and too few new data
(slightly modified reproducible example below). Alex did not get any
reply. I have just stumbled on the same problem, and I think that this
is a bug of function poly, which arises from the check whether the
polynomial degree is
2005 Jun 29
1
poly() in lm() leads to wrong coefficients (but correct residuals)
Dear all,
I am using poly() in lm() in the following form.
1> DelsDPWOS.lm3 <- lm(DelsPDWOS[,1] ~ poly(DelsPDWOS[,4],3))
2> DelsDPWOS.I.lm3 <- lm(DelsPDWOS[,1] ~ poly(I(DelsPDWOS[,4]),3))
3> DelsDPWOS.2.lm3 <-
lm(DelsPDWOS[,1]~DelsPDWOS[,4]+I(DelsPDWOS[,4]^2)+I(DelsPDWOS[,4]^3))
1 and 2 lead to identical but wrong results. 3 is correct. Surprisingly
(to me) the residuals
2013 Apr 01
2
example to demonstrate benefits of poly in regression?
Here's my little discussion example for a quadratic regression:
http://pj.freefaculty.org/R/WorkingExamples/regression-quadratic-1.R
Students press me to know the benefits of poly() over the more obvious
regression formulas.
I think I understand the theory on why poly() should be more numerically
stable, but I'm having trouble writing down an example that proves the
benefit of this.
I
2009 Nov 08
2
linear trend line and a quadratic trend line.
Dear list users
How is it possible to visualise both a linear trend line and a quadratic trend line on a plot
of two variables?
Here my almost working exsample.
data(Duncan)
attach(Duncan)
plot(prestige ~ income)
abline(lm(prestige ~ income), col=2, lwd=2)
Now I would like to add yet another trend line, but this time a quadratic one. So I have two
trend lines. One linear trend line
2008 Apr 22
1
Bug in poly() (PR#11243)
Full_Name: Russell Lenth
Version: 2.6.2
OS: Windows XP Pro
Submission from: (NULL) (128.255.132.36)
The poly() function allows a higher-degree polynomial than it should, when
raw=FALSE.
For example, consider 5 distinct 'x' values, each repeated twice. we can fit a
polynomial of degree 8:
=====
R> x = rep(1:5, 2)
R> y = rnorm(10)
R> lm(y ~ poly(x, 8))
Call:
lm(formula = y ~
2012 Mar 14
0
using predict() with poly(x, raw=TRUE)
Dear r-devel list members,
I've recently encountered the following problem using predict() with a model
that has raw-polynomial terms. (Actually, I encountered the problem using
model.frame(), but the source of the error is the same.) The problem is
technical and concerns the design of poly(), which is why I'm sending this
message to r-devel rather than r-help.
To illustrate:
2002 Jul 03
0
poly.transform in R
Dear all,
I am trying to transform polynomial coefficients from orthogonal form to
the standard power basis. There's poly.transform in S-plus. Does anybody
know how to do that in R ? I've found question about that in the
archives of R-help but no real answer.
Example : I'm doing polynomial regression of percentage of one insect in
a community on altitude, precipitations,
2005 Feb 14
0
using poly in a linear regression in the presence of NA fails (despite subsetting them out)
I ran into a to me surprising result on running lm with an orthogonal
polynomial among the predictors.
The lm command resulted in
Error in qr(X) : NA/NaN/Inf in foreign function call (arg 1)
Error during wrapup:
despite my using a "subset" in the call to get rid of NA's.
poly is apparently evaluated before any NA's are subsetted out
of the data.
Example code (attached to
2007 Jan 25
1
poly(x) workaround when x has missing values
Often in practical situations a predictor has missing values, so that poly
crashes. For instance:
> x<-1:10
> y<- x - 3 * x^2 + rnorm(10)/3
> x[3]<-NA
> lm( y ~ poly(x,2) )
Error in poly(x, 2) : missing values are not allowed in 'poly'
>
> lm( y ~ poly(x,2) , subset=!is.na(x)) # This does not help?!?
Error in poly(x, 2) : missing values are not allowed in
2017 Jul 16
0
How to formulate quadratic function with interaction terms for the PLS fitting model?
??
If I haven't misunderstood, they are completely different!
1) NIR must be a matrix, or poly(NIR,...) will fail.
2) Due to the previously identified bug in poly, degree must be
explicitly given as poly(NIR, degree =2,raw = TRUE).
Now consider the following example:
> df <-matrix(runif(60),ncol=3)
> y <- runif(20)
> mdl1 <-lm(y~df*I(df^2))
> mdl2
2009 Nov 28
1
R function that duplicates Octave's poly function?
By any chance is anyone aware of an R function that duplicates Octave's poly function?
Here is a description of Octave's poly function:
Function File: poly (A)
If A is a square N-by-N matrix, `poly (A)' is the row vector of
the coefficients of `det (z * eye (N) - a)', the characteristic
polynomial of A. As an example we can use this to find the
eigenvalues
2008 Feb 13
1
use of poly()
Hi,
I am curious about how to interpret the results of a polynomial regression--
using poly(raw=TRUE) vs. poly(raw=FALSE).
set.seed(123456)
x <- rnorm(100)
y <- jitter(1*x + 2*x^2 + 3*x^3 , 250)
plot(y ~ x)
l.poly <- lm(y ~ poly(x, 3))
l.poly.raw <- lm(y ~ poly(x, 3, raw=TRUE))
s <- seq(-3, 3, by=0.1)
lines(s, predict(l.poly, data.frame(x=s)), col=1)
lines(s,
2009 Jul 13
0
problem predict/poly
Dear R experts,
I am observing undesired behavior of predict(fit, newdata), in case when fit object is produced by lm() involving a poly(). Here is how to reproduce:
x <- c(1:10)
y <- sin(c(1:10))
fit <- lm(formula=y~poly(x, 5, raw=TRUE))
predict(fit, newdata=data.frame(x=c(1:10))) ## this works
predict(fit, newdata=data.frame(x=c(1:1))) ## this is broken, error below
Error in poly(x,
2009 Dec 17
1
poly() with unnormalized values
How can I get the result of, e.g., poly(1:3. degree=2) to give me the
unnormalized integer coefficients
usually used to explain orthogonal polynomial contrasts, e.g,
-1 1
0 -2
1 1
As I understand things, the columns of x^{1:degree} are first centered
and then
are normalized by 1/sqrt(col sum of squares), but I can't
see how to relate this to what is returned by poly().
>
2006 Jun 13
1
poly(*,*) in lm() (PR#8972)
Full_Name: Jens Keienburg
Version: 2.3.0
OS: Windows XP
Submission from: (NULL) (193.174.53.122)
I used the function lm() to calculate the coefficients of a polynome. If I used
the function poly(t,2) to denote a polynome of form 1 + x + x^2, the
coefficients are wrong. I appended an excerpt below:
> t=1:100
> p=-20 - 10 * t + 2 * t^2
> p
[1] -28 -32 -32 -28 -20 -8 8
2009 Jun 04
0
Dropping terms from regression w/ poly()
Hello r-help,
I'm fitting a model with lm() and using the orthogonal polynomials
from poly() as my basis:
dat <- read.csv("ConsolidatedData.csv", header=TRUE)
attach(dat)
nrows <- 1925
Rad <- poly(Radius, 2)
ntheta <- 14
Theta <- poly(T.Angle..deg., ntheta)
nbeta <- 4
Beta <- poly(B.Beta..deg., nbeta)
model.1 <- lm( Measurement ~ Block + Rad + Theta + Beta
2009 Jun 10
1
gpc.poly datatype
I have a list of polygons generated by the contourLines() command (each
object of the list is a list in itself with two objects: a vector of x
values, and a vector of y values for each vertex). I wish to convert that
list into a gpc.poly object of multiple contours. How do I do this? gpclib
apparently has no method of coercing lists into the gpc.poly object type.
As well, when I have a
1997 Sep 09
2
R-beta: "Comparison of Mathematical Programs for Analysis"
Hi,
I have just seen Stefan Steinhaus' web page :
http://www.uni-franfurt.de/~stst/ncrunch.html
I think it would be nice to include "R" as well.
I have taken Forrest Young's email on stat-lisp list and changed the
stuff for "R" :) Here it is: (someone please check this so we can
also send it to Stefan Steinhaus.