nlsregression: nlsregression

View source: R/nlsregression.R

nlsregressionR Documentation

nlsregression

Description

Creates regression parameter estimates and plots with any function you want that has no more than two independent variables

Usage

nlsregression(
  func,
  y,
  x,
  z = NULL,
  startvalues = NULL,
  weight = NULL,
  weighting = TRUE,
  xlab = NULL,
  ylab = "y",
  header = NULL,
  z_plot_lines = NULL,
  weightcolorpoints = TRUE,
  x_log10 = FALSE,
  toPlot = "all",
  plot_x_function = "ignore",
  regressioncolor = "blue",
  weight_threshold = NULL,
  crossvalid = NULL,
  ...
)

Arguments

func

function that shall be fitted. Function should contain the dependent variable y and and the independent variable x, eventually a second independent variable z. All other unknowns are treated as parameters that are estimated.

y

dependent variable,vector

x

independent variable,vector

z

optional independent variable,vector

startvalues

the optimization algorithm may require starting values for the fitting procedure. provide them in a list with the parameter names: e.g. list(a=3,b=2)

weight

optional weight,vector

weighting

if weighting is TRUE, the fit will minimize the weighted residuals

xlab

name of x axis in plot

ylab

name of y axis in plot

header

plot function main argument

z_plot_lines

vector>1 of values for z you want to be plotted into the graph

weightcolorpoints

if TRUE, the points are clustered into three quantiles according to their weight and coloured lighter for low weights.

x_log10

allows log10 scale for X axis if set to TRUE. Only changes the picture, not the regression!

toPlot

"all", "frame" (axis etc), "observations" (points), "regressionline" (line), "infos" (parameters, R2)

plot_x_function

depreciated, please do not enter into function call.

regressioncolor

color of regression line and paramter text

weight_threshold

if numeric, all countries below this threshold will be excluded (e.g. to exclude minor islands)

crossvalid

vector with boolean values, indicating which data should be excluded from sampling and rather be used for validation

...

will be passed on to function nls

Value

A nice picture and regression parameters or eventually some errors.

Author(s)

Benjamin Leon Bodirsky, Susanne Rolinski, Xiaoxi Wang

Examples

## Not run: 
x=1:10
y=(1:10)^2+1
z=c(10:1)

# one independent variable
nlsregression(func=y~a*x+b,y=y,x=x,startvalues=list(a=1,b=1))
# two independent variables
nlsregression(func=y~a*x^1.1+b*z+c*x,y=y,x=x,z=z,startvalues=list(a=1,b=1,c=0))
# no fit because residuals are zero (excluded from the nls makers due
 to statistical reasons)
nlsregression(func=y~x^a+b,y=y,x=x,z=z,startvalues=list(a=1,b=1,c=0))

DNase1 <- subset(DNase, Run == 1)
DNase1$sets<- c(rep(1,8),rep(2,8))
nlsregression(func=y~a*x+b,y=DNase1$density,x=DNase1$conc,startvalues=list(a=1,b=1))
nlsregression(func=y~a*x+b*z,y=DNase1$density,x=DNase1$conc,z=DNase1$sets,
startvalues=list(a=0.1344,b=0.2597))
nlsregression(func=y~a*x+b*z,y=DNase1$density,x=DNase1$conc,z=DNase1$sets,
startvalues=list(a=0.1344,b=0.2597),plot_x_function=log)

## End(Not run)

pik-piam/regressionworlddata documentation built on June 6, 2024, 11:08 p.m.