@betasy
2016-09-20T08:32:33.000000Z
字数 1008
阅读 1483
R 学习笔记
order函数
a=data.frame(a1=c(2,1,3,4,2,5,4),a2=c(7,4,5,6,5,6,4),a3=c(1,2,3,4,5,6,7))a<-a[order(a$a1,-a$a2),]
这里按照a1升序,a2降序排列
barplot(q$COEF,q$ZONE_CODE)
library(car)pop.mod1 <- nls(population ~ theta1/(1+exp(-(theta2+theta3*year))),start=list(theta1=400,theta2=-49,theta3=0.025),data=USPop, trace=T)
改写
nls.al <- nls(COEF~exp(c0+c1/delta_t+c2*log(delta_t)),start=list(c0=0,c1=-1,c2=0.5),data=t,trace=T)
判断拟合效果
library(ggplot2)p<-ggplot(t,aes(YEAR,COEF))p+geom_point(size=3)+geom_line(aes(delta_t,fitted(nls.al)),col='red')
library(plotly)# variance-covariance matrix for a multivariate normal distributions <- matrix(c(1, .5, .5,.5, 1, .5,.5, .5, 1), ncol = 3)# use the mvtnorm package to sample 200 observationsobs <- mvtnorm::rmvnorm(200, sigma = s)# collect everything in a data-framedf <- setNames(data.frame(obs), c("x", "y", "z"))library(plotly)plot_ly(df, x = x, y = y, z = z, type = "scatter3d", mode = "markers")
2.使用scatterplot3d包
s3d<-scatterplot3d(x,y,z)lm.xyz<-lm(z~x+y)s3d$plane3d(lm.xyz) #添加拟合平面
