11839

Error: missing values and NaN's not allowed if 'na.rm' is FALSE

Trying out multiple models chapter of #r4ds and ran into an error message at the end:

Error: missing values and NaN's not allowed if 'na.rm' is FALSE In addition: Warning message: In ns(as.numeric(Month), 4) : NAs introduced by coercion

with

ADA_model<- function(ADA_mutiple_model){ lm(ADA ~ ns(as.numeric(Month), 4), data=ADA_mutiple_model) } ADA_mutiple_model <- ADA_mutiple_model %>% mutate(model=map(data,ADA_model))

as the code I used that creates the error.

See mod3 below to see what the function looks like

<img src=https://www.e-learn.cn/content/wangluowenzhang/"https://i.stack.imgur.com/KhS3h.png" alt="enter image description here">

Answer1:

Your problem has nothing to do with the use of lm, but inside splines::ns when generating B-spline basis for natural cubic splines. <strong>Very likely your Month is a character variable</strong>, and you can not use as.numeric for coercing.

<hr>

I just checked your attached figure. The x-axis in the plots verifies what I guessed. You need to use 1:12 for Month, not "JAN", "FEB", etc.

Recommend

  • What other languages allow programmers to use Interfaces as function parameters?
  • Case statement in SQL Sever to identify possible duplicate
  • Ada - getting string from text file and store in array
  • how to separate a number from a string [closed]
  • assign arraylist value to textview
  • template with lambda as unique default parameter on each instantiation
  • Rename an Ada package
  • Disabling a select from another select in jQuery Mobile
  • Ada: How to check if input is an enumeration type [duplicate]
  • How to achieve Expandablelistview child custom layout?
  • Replace values with numbers
  • rvest package - Is it possible for html_text() to store an NA value if it does not find an attribute
  • Sending commands to stdin and sending end of transmit (Ctrl+D)
  • R: merging copies of the same variable
  • How to predict a new value using simple linear regression log(y)=b0+b1*log(x)
  • get equation of linear SVM regression line
  • Plot a table with R
  • How to get list of users who's birthday is today in MongoDB
  • addressing in assembler
  • How to use arithmetic operators with SAS macro variables [duplicate]
  • Getting errors while using neuralnet function
  • Zend Framework + Doctrine1.2 project structure with more modules
  • Sending Content-Type application/x-www-form-urlencoded WSO2 ESB
  • Neo4j: Filter nodes based on aggregate function
  • What is corresponding c++ data type to SQL numeric(18,0) data type?
  • File extension of zlib zipped html page?
  • CERN ROOT exporting data to plain text
  • Find Previous month name using Calender or any classes that in java
  • Invalid Date on validation Date of js
  • How solve “Qt: Untested Windows version 10.0 detected!”
  • C: Incompatible pointer type initializing
  • Jetty 9 HashLoginService
  • Cancel a live stream “fast motion” catch-up in Flash
  • HTML download movie download link
  • Function pointer “assignment from incompatible pointer type” only when using vararg ellipsis
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • Bitwise OR returns boolean when one of operands is nil
  • sending mail using smtp is too slow
  • costura.fody for a dll that references another dll
  • Binding checkboxes to object values in AngularJs