[R] [Johns Hopkins] R Programming -- week 4
2024-09-13 05:23:41
#Generating normal distribution (Pseudo) random number
x<-rnorm(10)
x x2<-rnorm(10,2,1)
x2 set.seed()
#Generating Poisson data rpois(10,1)
rpois(10,2)
rpois(10,20) ppois(2,2) #Cumulative distribution ##P r(x <= 2) 平均發生率為2
ppois(4,2) #Cumulative distribution ##P r(x <= 4) 平均發生率為4 #線性 y = B0+B1X+e
#e~N(0,2^2) 標準差為2正態分布
#assume x~N(0,1^2) B0=o.5 B1=2
set.seed(20)
x <- rnorm(100)
e <- rnorm(100,0,2)
y <- 0.5 + 2 * x + e
summary(y)
plot(x,y) # 若x為binary ex性別
set.seed(20)
x <- rbinom(100,1,0.5) #得到1的機率為0.5
e <- rnorm(100,0,2)
y <- 0.5 + 2 * x + e
summary(y)
plot(x,y) #廣義線性模組可能服從poisson分布 Y~Poisson(m)
#log mu = B0 + B1X #log mu 服從線性
#B0 = 0.5 B1 =0.3 #y服從 平均值為mu 的 PD
set.seed(20)
x <- rnorm(100)
log.mu <- 0.5 + 0.3 * x
y <- rpois(100,exp(log.mu))
summary(y)
plot(x,y) # sample(range vector, numbers)
# sample(range vector) 重新排列
# sample(range vector, replace = T) 重複性抽樣 #Profiler profiling is better than guessing
#Premature optimization is the root of all evil
system.time() #proc_time (class)
#user time: time charged to the CPU(s) for this expression
#elapsed time: "wall clock" time 運行時間
#parallel processing via parallel package ##elapsed time > user time
system.time(readlines("http://www.google.com")) #elapsed time < user time
hilbert <- function(n){
i <- 1:n
1/outer(i -1, i, "+")
}
x <- hilbert(1000)
system.time(svd(x)) # svd 多線程線性代數
最新文章
- .NET 的 WebSocket 开发包比较(转)
- Windows Azure Service Bus (2) 队列(Queue)入门
- AC日记——质因数分解 1.5 43
- 网页元素定位神器之Xpath详解
- Windows Azure 微软公有云体验(一) 网站、SQL数据库、虚拟机
- SVN eclipse插件错误
- jquery的uploadify上传jsp+servlet
- 以程序的方式操纵NTFS的文件权限(陈皓)
- http://riddle.arthurluk.net walkthrough
- 《JavaScript高级程序设计》读书笔记 ---创建对象
- java原装代码完成pdf在线预览和pdf打印及下载
- JAVA入门[9]-mybatis多表关联查询
- [Vijos 1143]三取方格数
- Spring Cloud 2-Hystrix DashBoard仪表盘(五)
- C# - 什么是事件绑定?
- [ZOJ 4020] Traffic Light
- Python&#160;再谈变量作用域与变量引用
- linux4.10.8 内核移植(二)---初步裁剪、分区修改和文件系统
- Unity3d 之 理解Gameobject ,gameObject,Transform,transform的区别和关联
- MySQL使用root用户授权出现错误ERROR 1045 (28000) at line 2: Access denied for user &#39;root&#39;@&#39;%&#39; (using password: YES)解决办法