Advertisement
Randomsurpriseguy

R_Blatt02

Apr 20th, 2021
1,651
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.45 KB | None | 0 0
  1. #Aufgabe 1 ----
  2. #(a)----
  3. N <- 42
  4. v1 <- 0:N
  5. r1 <- 0.5^v1
  6. r2 <- 2*(1-1/(2^(v1+1)))
  7.  
  8. #(b)----
  9. n <- 42
  10. p <- 1/2
  11.  
  12. W <- function(nIn,pIn,i){
  13.   return(choose(nIn,i)*pIn^i*(1-pIn)^(nIn-i))
  14. }
  15.  
  16. P <- function(nIn,pIn,i){
  17.   return(sum(W(n,p,0:i)))
  18. }
  19.  
  20. vW <- W(n,p,0:n)
  21. vP <- cumsum(W(n,p,0:n)) #Vektor der P_i Werte
  22. #folgende ignorieren:
  23. vW1 <- dbinom(0:n,n,p)
  24. vP1 <- pbinom(0:n,n,p)
  25. #Aufgabe 2 ----
  26. x <- c(0.61,  0.79,  0.83,  0.66,  0.94,  0.78,  0.81,  0.60,  0.88,  0.90,  0.75,  0.86,  0.74,  0.84)
  27. y <- c(1.01,  0.13,  1.73,  0.67,  0.56,  0.99,  0.49,  0.72,  0.13,  0.48,  0.98,  0.08,  1.23 , 0.87)
  28. x_order=order(x) # (a)----
  29. paste("x(",1:14,":14) = ",x[order(x)],sep="") # (b)----
  30. y_coorder <- y[x_order] # (c)----
  31. paste("(x(",1:14,":14), y[",1:14,":14) = (",x[order(x)],",",y[order(x)],")",sep="") #(d)----
  32. paste("(x(",format(1:14,justify="right"),":14), y[",format(1:14,justify="right"),":14) = (",format(x[order(x)],digits = 2),",",format(y[order(x)],digits=2),")",sep="") #(e)----
  33.  
  34.  
  35. #Aufgabe 3----
  36. eruptions <- faithful$eruptions
  37. wait <- faithful$waiting
  38. sd(wait)#(a)----
  39. mean(wait)
  40. max(wait)
  41. min(wait)
  42. (1:length(wait))[wait==max(wait)]#(b)----
  43. (1:length(wait))[(wait==min(wait))]
  44. quantile(wait,probs=0.3)#(c)----
  45. wait[wait<= 60]#(d)----
  46. length(wait)#(e)----
  47. length(wait[wait<=60])
  48. eruptions[wait<=60]#(f)----
  49. mean(wait[wait<=60])#(g)----
  50. mean(eruptions[wait<=60])
  51. sum(eruptions[wait<=60]>=2.5)#(h)----
  52. plot(wait,eruptions)#(i)----
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement