[关闭]
@betasy 2016-09-20T08:32:33.000000Z 字数 1008 阅读 1483

R语言使用笔记

R 学习笔记


  1. 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))
  2. a<-a[order(a$a1,-a$a2),]

这里按照a1升序,a2降序排列

  1. barplot(q$COEF,q$ZONE_CODE)
  1. library(car)
  2. pop.mod1 <- nls(population ~ theta1/(1+exp(-(theta2+theta3*year))),start=list(theta1=400,theta2=-49,theta3=0.025),data=USPop, trace=T)

改写

  1. 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)

判断拟合效果

  1. library(ggplot2)
  2. p<-ggplot(t,aes(YEAR,COEF))
  3. p+geom_point(size=3)+geom_line(aes(delta_t,fitted(nls.al)),col='red')
  1. library(plotly)
  2. # variance-covariance matrix for a multivariate normal distribution
  3. s <- matrix(c(1, .5, .5,
  4. .5, 1, .5,
  5. .5, .5, 1), ncol = 3)
  6. # use the mvtnorm package to sample 200 observations
  7. obs <- mvtnorm::rmvnorm(200, sigma = s)
  8. # collect everything in a data-frame
  9. df <- setNames(data.frame(obs), c("x", "y", "z"))
  10. library(plotly)
  11. plot_ly(df, x = x, y = y, z = z, type = "scatter3d", mode = "markers")

2.使用scatterplot3d包

  1. s3d<-scatterplot3d(x,y,z)
  2. lm.xyz<-lm(z~x+y)
  3. s3d$plane3d(lm.xyz) #添加拟合平面
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注