R语言解多元线性方程R语言中输入test之后,数据如下:>testx1 x2 y1 30.0 760.0 114.52

R语言解多元线性方程
R语言中输入test之后,数据如下:
>test
x1 x2 y
1 30.0 760.0 114.5
2 15.0 901.5 77.0
3 15.0 698.0 59.5
4 16.0 595.0 54.0
5 47.8 589.0 135.0
然后输入:
> Im.test=Im(test$y~test$x1+test$x2)
Error in Im(test$y test$x1 + test$x2) :
non-numeric argument to function
这报错了,应该怎么处理啊?
mjgiggs 1年前 已收到1个回答 举报

cc有cc 幼苗

共回答了13个问题采纳率:92.3% 举报

你先试试这样
lm.test=lm(y~x1+x2,test)
根据你的报错:non-numeric argument to function
就是说你的数据里面有非数字型的,可能是NA,可能是字符“n/a” 仔细排查一下吧

1年前 追问

7

mjgiggs 举报

1.这里说,im函数只需要传递一个变量;
> is.na(test) 没有NA的
2.关于非数字型的,我也测试过了
> is.numeric(test$y)
[1] TRUE
> is.numeric(test$x1)
[1] TRUE
> is.numeric(test$x2)
[1] TRUE

举报 cc有cc

我随便用了R的内置数据集iris做了回归,表达运行都没问题啊。
> test<-iris[1:10,1:3]
> colnames(test)<-c("x1","x2","y")
> lm.test=lm(test$y~test$x1+test$x2)
> summary(lm.test)
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 18 q. 0.629 s. - webmaster@yulucn.com