指数函数在r中不起作用,但pol起作用

时间:2017-07-17 15:55:25

标签: r

我想拟合/绘制指数函数但它不起作用。对于

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)

我收到:

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

但是“~poly(Amplification,2)”有效。怎么了?我已经搜索了错误,但解决方案对我不起作用。 谢谢!

Data

2 个答案:

答案 0 :(得分:1)

此答案基于对OP @Ben

的评论

您使用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'

建议您的至少一个值为NA/NaN/Inf。你的价值范围

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

<强> ----- -----聚

~ poly(Amplification, 2)没有给你一个错误,但poly并没有按照你的预期做到。

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

您可能正在寻找

val <- 1:5
2^val

这解释了为什么poly有效。

<强> ----- -----错误

回到你的错误:

exp(1903.74000)

Inf,它解释了您的错误

答案 1 :(得分:-1)

您的数据集可能包含NULL值function getTransactions($sinceTicks) { global $userEmailAddress; global $userPassword; global $accountGatewayUser; global $accountGatewayPassword; $format = 'JSON'; $wsdl = 'https://apps.blahblahblah.co.uk/recurring-payments/Services/Merchant.asmx?WSDL'; try { $soapclient = new SoapClient($wsdl); $params = array ( 'userEmailAddress' => $userEmailAddress, 'userPassword' => $userPassword, 'accountGatewayUser' => $accountGatewayUser, 'accountGatewayPassword' => $accountGatewayPassword, 'format' => $format, 'sinceTicks' => $sinceTicks ); $response = $soapclient->TransactionsSinceTicks($params); $array = json_decode($response[0]->TransactionsSinceTicksResult, True); return ($array['Transactions']); } catch(SoapFault $error) { return json_encode($error); } } ,因此无法计算这些值的函数NA。 您的数据集是否包含NA值?