Advertisement
Five_NT

R / Laborator 5

May 10th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.89 KB | None | 0 0
  1. I.1
  2. z_test=function(alfa,p_mean,s_mean,n,sigma, ipoteza)
  3. {
  4.   z_score = (s_mean - p_mean)/(sigma/sqrt(n))
  5.   if(ipoteza == 1) {
  6.       critical_z = qnorm(alfa)
  7.     }
  8.   if(ipoteza == 2) {
  9.     critical_z = qnorm(1 - alfa)
  10.     }
  11.     if(ipoteza == 3) {
  12.       critical_z = qnorm(1 - alfa/2)
  13.     }
  14.  
  15.   if(ipoteza == 1) {
  16.     if(z_score > critical_z) {
  17.         print("H0 respinsa")
  18.       }
  19.       else {
  20.           print("Nu se poate calcula")
  21.       }
  22.   }
  23.  
  24.   if(ipoteza == 2) {
  25.     if(z_score > critical_z) {
  26.       print("H0 respinsa")
  27.     }
  28.     else {
  29.       print("Nu se poate calcula")
  30.     }
  31.   }
  32.  
  33.   if(ipoteza == 3) {
  34.     if(abs(z_score) > abs(critical_z)) {
  35.       print("H0 respinsa")
  36.     }
  37.     else {
  38.       print("Nu se poate calcula")
  39.     }
  40.   }
  41.   print(z_score)
  42.   print(critical_z)
  43. }
  44.  
  45. I.2
  46. z_test(0.01, 90, 90, 49, sqrt(144), 1)
  47.  
  48. I.3
  49. z_test(0.01, 75, 85, 36, sqrt(17), 3)
  50.  
  51. I.4
  52. z_test(0.01, 21, 20.5, 100, 2.5, 2)
  53.  
  54. I.5
  55. z_test(0.05, 1000, 970, 100, 85, 1)
  56. z_test(0.01, 1000, 970, 100, 85, 1)
  57.  
  58. I.6
  59. z_test(0.01, 22, 20, 16, 3, 3)
  60.  
  61.  
  62. II.1
  63. t_test=function(filename,alfa,p_mean)
  64. {
  65.   a=citire(filename)
  66.   b=calcul(a);n=b[1]
  67.   s_mean=b[2]
  68.   sigma=b[3]
  69.   if(p_mean>s_mean)
  70.   {
  71.     critical_t = qt(alfa,n-1)
  72.     t_score = (s_mean - p_mean)/(sigma/sqrt(n))
  73.     }
  74.   else
  75.   {
  76.     critical_t = qt(1- alfa,n-1)
  77.     t_score = (s_mean - p_mean)/(sigma/sqrt(n))
  78.     }
  79.   if(t_score>critical_t)
  80.   {
  81.     cat("H0 respinsa")
  82.   }
  83.   else
  84.   {
  85.     cat("H0 acceptata")
  86.   }
  87.   cat("\n")
  88.   print(t_score)
  89.   print(critical_t)
  90. }
  91.  
  92. calcul=function(a)
  93. {
  94.   n=length(a)
  95.   media=mean(a)
  96.   s=sd(a)
  97.   b<-c(n,media,s)
  98. }
  99.  
  100. citire=function(fisier)
  101. {
  102.   a<-scan(fisier)
  103. }
  104.  
  105. II.2
  106. t_test("vector.txt",0.01,34)
  107.  
  108. II.3
  109. z_test(0.01,11.4,11.9,100,0.25)
  110. z_test(0.05,11.4,11.9,100,0.25)
  111.  
  112. II.4
  113. t_test("sample1.txt",0.01,80)
  114. t_test("sample1.txt",0.05,80)
  115.  
  116. II.5
  117. z_test(0.01,49,52,64,sqrt(89.5))
  118.  
  119. II.6
  120. z_test(0.05,30,29,40,sqrt(5))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement