0

I would like to fit/draw an exponential function but it does not work. For

before_database.frame<- read.table("APD_data.txt", 
                                  header = TRUE,
                                  sep = "",
                                  dec="."
                                 )

Single_APD.frame<- before_database.frame[before_database.frame$Serial_number==912009913, ]

# fit<- lm(Voltage ~ poly(Amplification,2), data=Single_APD.frame)
fit<- lm(Voltage ~ exp(Amplification), data=Single_APD.frame)

I receive:

Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 
  NA/NaN/Inf in 'x'

But " ~ poly(Amplification, 2)" works. What is wrong? I already searched for the error but the solutions do not work for me. Thank you!

Data

Ben
  • 1,432
  • 4
  • 20
  • 43
  • 1
    Could you show the output of `range(Single_APD.frame$Amplification)`? – CPak Jul 17 '17 at 15:58
  • 1
    `exp` can easily blow up – platypus Jul 17 '17 at 15:59
  • @ChiPak Sure, it's" [1] 1.00252 1903.74000 " – Ben Jul 17 '17 at 16:01
  • 1
    See `https://stackoverflow.com/questions/19484053/what-does-the-r-function-poly-really-do`. My guess is that `poly` doesn't do what you think...You want to compare to `val <- 1:5`, `2^val` I think... – CPak Jul 17 '17 at 16:04
  • `exp(max(Single_APD.frame$Amplification))` is `Inf`, which explains your error – CPak Jul 17 '17 at 16:06
  • I didn't understand it but as mentioned there "Voltage ~ Amplification^2" looks more sensefull. How do I close the question/accept your comment? – Ben Jul 17 '17 at 16:14
  • @Ben, I wouldn't worry about closing the question or accepting an answer. Finding an answer in the comments happens all the time with posts... – CPak Jul 17 '17 at 16:35
  • @ChiPak But isn't it better when people know the question is not open anymore? – Ben Jul 18 '17 at 08:31
  • @Ben Yes...I'll collect my comments into an answer. – CPak Jul 18 '17 at 11:09

2 Answers2

1

This answer is based on comments with the OP @Ben

The error you were getting with lm(Voltage ~ exp(Amplification), data=Single_APD.frame):

Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 
NA/NaN/Inf in 'x'

suggested that at least one of your values was NA/NaN/Inf. The range of your values

What is output of range(Single_APD.frame$Amplification)?
@ChiPak Sure, it's" [1] 1.00252 1903.74000 

-----poly-----

~ poly(Amplification, 2) was not giving you an error, but poly doesn't do you what you expected.

See https://stackoverflow.com/questions/19484053/what-does-the-r‌​-function-poly-reall‌​y-do. 

You probably were looking for

val <- 1:5
2^val

This explains why poly works.

-----Error-----

Going back to your error:

exp(1903.74000)

is Inf, which explains your error

CPak
  • 13,260
  • 3
  • 30
  • 48
-1

Your dataset probably contains NULL values NA, and for this reason the function exp for those values, can not be calculated. Your dataset contains NA values, or not?

Lorenzo Benassi
  • 621
  • 1
  • 8
  • 31