PoliFit: An Application to fit data points to a Polynomial Function

DT
01 September 2016

Description

PoliFit application will fit the best polynomial function of degree n:

\( f(x)= a_0 + a_1x + a_2x^2 + ... + a_nx^n \)

The results are presented in five different formats:

  • Data Plot
  • Residuals Plot
  • Coefficient Values (\( a_0, a_1,.., a_n \))
  • Model Summary (a more complete information from the model)

Get the App here

Note: This application was not optimized for mobile devices.

How to use

  • Choose the polynomial degree n value (n=1 is default)
  • Fill the Input Data table with (x,y) values
  • Click on “+” to add or “-” to delete a row
  • Click on “Go” button
  • Change degree n and evaluate the fitting

You can only fit a polynomial function with degree n by using at least (n + 2) data points. For example, you will need to input at least three points to use a linear model, or five points for a cubic model.

Main code

#install.packages("polynom")
library(polynom)
data <- as.data.frame(cbind(c(0,1,3,5,7),c(0,3,5,7,9)))
colnames(data)<-c("xval","yval")
#polynomial degree n=3
x <-poly(data$xval,3, raw = TRUE)
model <- lm(data$yval ~ x)
summary(model)

Call:
lm(formula = data$yval ~ x)

Residuals:
       1        2        3        4        5 
-0.16141  0.35309 -0.35309  0.21185 -0.05044 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)
(Intercept)  0.16141    0.54477   0.296    0.817
x1           2.99412    0.89522   3.345    0.185
x2          -0.55233    0.32172  -1.717    0.336
x3           0.04372    0.02985   1.464    0.381

Residual standard error: 0.5682 on 1 degrees of freedom
Multiple R-squared:  0.9934,    Adjusted R-squared:  0.9735 
F-statistic: 50.06 on 3 and 1 DF,  p-value: 0.1034

Plot Examples

plot of chunk unnamed-chunk-2

plot of chunk unnamed-chunk-3

References


  • For shiny apps look at shiny
  • For the Input data look at shinyTable
  • For the Polynomial functions look at polynom
  • For the fitting method look at Fitting