fit_2D: Iteratively fits 2D regression models to a dataset using the...

Description Usage Arguments Examples

View source: R/fit_2D.R

Description

The function, fit_2D, takes four arguments, func, dat, it, op_v and fits the 2D model described by the argument func into the data described by the argument dat. The parameter it describes the number of iterations that the code generates before it decides to declare that the starting/intial values of the vector to be iterated, op_v, is a bad starting point to search for a local minima within the given number of iterations, it. In such cases the message solution did not converge will be displayed. op_v is a vector comprising the initial values/guess point from where the vector will iterate itself to look for a local minima. It must however be remembered that the function, fit_2D, does not have pre-defined default values attached to its arguments and also that the function does not under present circumstances support optimization algorithms with constraints defined on them. This however is a work in progress and will be taken care of in future contexts.

Usage

1
fit_2D(func, dat, it, op_v)

Arguments

func

The argument func is a R function. It defines the model that the user wants to fit to his data defined in the argument dat. The argument has certain rules and restrictions. 1. The argument func has to be a user-defined function itself 2. The function that the user passes to the argument func must itself be a function that accepts only one argument. This argument must be the vector that needs to be iterated, op_v. 3. The vector op_v must be defined after the definition of the function that is to be passed in func, failing which, the argument passed in func ceases to be a function and this would throw an error. See example below 4. The function has to return a value, y. See example below

dat

The argument dat has to be a matrix of size 2Xn, where, n<-length(x). The first row of dat(dat[1,]) should be the y values whereas the second row dat[2,] should be the x values. See example below

it
op_v

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
library(DataAnalyze1.0)
x<-seq(-10,10, by=0.02)
g<-function(v){
  y<-v[1]*exp(-1*(((x-v[2])/(v[3]))^2))+2*v[1]*exp(-1*(((x-v[4])/(v[5]))^2))
  return(y)
}
y<-3*exp(-1*(((x-4)/(5))^2))+6*exp(-1*(((x-4.5)/(4))^2))
y_d<-y+runif(length(x))
plot(x,y_d)
m<-matrix(c(y_d,x), byrow = T, nrow = 2)
v<-c(2.2,3.5,4.7,4.8,5)
fit_2D(func=g, dat=m, op_v = v, it=20000)

Chitran1987/DataAnalyze1.0 documentation built on July 23, 2019, 12:50 a.m.