0

I just started using nls I tried to fit

y ~  exp(-x^a) :
m<- nls(y ~  exp(-x^a),start=list(a=0))

It seemes to work fine :)

My problem is that I want to get out "a" in order to write the value to a file.

I can see the the value is 3.612 but how to get hold of the value?

m
Nonlinear regression model
  model: y ~ exp(-x^a)
   data: parent.frame()
    a 
3.612 
 residual sum-of-squares: 0.06132

Number of iterations to convergence: 9 
Achieved convergence tolerance: 3.654e-06
Alejandro Alcalde
  • 5,990
  • 6
  • 39
  • 79

1 Answers1

1

You can get the value of a by doing

coef(m)[["a"]]

Example (model from help(nls)):

x <- 1:10
y <- 2*x + 3                            
yeps <- y + rnorm(length(y), sd = 0.01)
(m <- nls(yeps ~ a + b*x, start = list(a = 0.12345, b = 0.54321)))
# Nonlinear regression model
# model: yeps ~ a + b * x
# data: parent.frame()
# a b 
# 3 2 
# residual sum-of-squares: 0.000834
#
# Number of iterations to convergence: 2 
# Achieved convergence tolerance: 5.23e-09
coef(m)[["a"]]
# [1] 3.0052
Rich Scriven
  • 97,041
  • 11
  • 181
  • 245