User Tools

Site Tools


expected_value_and_variance_properties

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
expected_value_and_variance_properties [2025/09/06 09:45] – [e.gs in R] hkimscilexpected_value_and_variance_properties [2025/09/06 10:28] (current) – [e.gs in R] hkimscil
Line 193: Line 193:
 # variance theorem 4-1, 4-2 # variance theorem 4-1, 4-2
 # http://commres.net/wiki/variance_theorem # http://commres.net/wiki/variance_theorem
 +
 # need a function, rnorm2 # need a function, rnorm2
-rnorm2 <- function(n,mean,sd) { mean+sd*scale(rnorm(n)) }+rnorm2 <- function(n,mean,sd) {  
 +    mean+sd*scale(rnorm(n))  
 +}
  
-m <- 50+m <- 50  
 v <- 4 v <- 4
 n <- 100000 n <- 100000
Line 204: Line 207:
 x3 <- rnorm2(n, m, sqrt(v)) x3 <- rnorm2(n, m, sqrt(v))
  
-m.x1 <- round(mean(x1),3) +# Note: x1, x2, x3는 평균과 표준편차를 
-m.x2 <- round(mean(x2),3) +# 같은 값으로 갖는 (공유하는독립적인  
-m.x3 <- round(mean(x3),3+# 집단
-m.x1 +
-m.x2 +
-m.x3+
  
 y1 <- 3*x1 +5  y1 <- 3*x1 +5 
Line 216: Line 216:
 exp.y1 exp.y1
 exp.3xplus5 exp.3xplus5
- 
-v.x1 <- var(x1) 
-v.x2 <- var(x2) 
-v.x3 <- var(x3) 
-v.x1 
-v.x2 
-v.x3 
  
 var(x1)  var(x1) 
 var((3*x1)+5) var((3*x1)+5)
 3^2 * var(x1) 3^2 * var(x1)
-var(y1)  # 9 * var(x)+var(y1)  # 9 * var(x) 위와 동일
  
 v.12 <- var(x1 + x2) v.12 <- var(x1 + x2)
 v.12 v.12
 +
 ###################################### ######################################
 ## v.12 should be near var(x1)+var(x2) ## v.12 should be near var(x1)+var(x2)
 ###################################### ######################################
-## 정확히 2*v가 아닌 이유는 x1, x2가  +# 정확히 2*v가 아닌 이유는 x1, x2가  
-## 아주 약간은 (random하게) dependent하기 때문  +# 아주 약간은 (random하게) dependent하기 때문  
-##(혹은 상관관계가 있기 때문) +# (혹은 상관관계가 있기 때문, covariance가  
-## theorem 5-1 에서  +있기 때문) 
-## var(x1+x2) = var(x1)+var(x2)+ (2*cov(x1,x2))+# theorem 5-1 에서  
 +# var(x1+x2) = var(x1)+var(x2)+ (2*cov(x1,x2))
  
 cov.x1x2 <- cov(x1,x2) cov.x1x2 <- cov(x1,x2)
Line 261: Line 256:
 </code> </code>
  
- 
-  
expected_value_and_variance_properties.txt · Last modified: 2025/09/06 10:28 by hkimscil

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki