1.当使用cor()求相关系数时,出现以下错误:
当求相关系数时,出现如下错误时: > cor(pvnum_avgwinprice$V2, pvnum_avgwinprice$V3) 错误于cor(pvnum_avgwinprice$V2, pvnum_avgwinprice$V3) : 'y'必需是数值
C4KDHL8e1Y 5 19.2 C4KLPJE53d 65 457.5 C4NDP8F12E 6 499.6666666666667 C4RJur4Z3S 1 302.75 C53HK14V3L 3 1102.3333333333333
> typeof(pvnum_avgwinprice$V3) [1] "integer" > is.numeric(pvnum_avgwinprice$V3) [1] FALSE
> cor(pvnum_avgwinprice$V2, as.double(pvnum_avgwinprice$V3))或者
> cor(pvnum_avgwinprice$V2, as.numeric(pvnum_avgwinprice$V3))
时隔多日又碰到这一问题,这回问题更是匪夷所思!
as.numeric(as.character(x))
求曲线回归系数
> dat <- read.table("cvr.dat") > dat V1 V2 1 0.04997310 0.0260000 2 0.04094868 0.0155000 3 0.03326068 0.0105000 4 0.02671426 0.0060000 5 0.02212872 0.0049375 > f=function(x,a,b){a*x+b} > result = nls(dat$V2~f(dat$V1,a,b), data=dat, start=list(a=1.5,b=0.01)) > result Nonlinear regression model model: dat$V2 ~ f(dat$V1, a, b) data: dat a b 0.75548 -0.01356 residual sum-of-squares: 1.148e-05 Number of iterations to convergence: 1 Achieved convergence tolerance: 7.426e-07