Round the coefficients of an mpoly object.
# S3 method for mpoly round(x, digits = 3)
x | an mpoly object |
---|---|
digits | number of digits to round to |
the rounded mpoly object
#> x^4 + 12.56637 x^3 + 59.21763 x^2 + 124.0251 x + 97.40909round(p)#> x^4 + 12.566 x^3 + 59.218 x^2 + 124.025 x + 97.409#> x^4 + 13 x^3 + 59 x^2 + 124 x + 97if (FALSE) { library(plyr) library(ggplot2) library(stringr) n <- 101 s <- seq(-5, 5, length.out = n) # one dimensional case df <- data.frame(x = s) df <- mutate(df, y = -x^2 + 2*x - 3 + rnorm(n, 0, 2)) qplot(x, y, data = df) mod <- lm(y ~ x + I(x^2), data = df) p <- as.mpoly(mod) qplot(x, y, data = df) + stat_function(fun = as.function(p), colour = 'red') p round(p, 1) qplot(x, y, data = df) + stat_function(fun = as.function(p), colour = 'red') + stat_function(fun = as.function(round(p,1)), colour = 'blue') }