support@w4writers.com +44 7743 307695
Apr 30, 2024

Questions

1. Sequence Consider the sequence (xn) defined by the formula:

  • xn = a + d ⇥ (n 1) ( xn2 xn1 )(xn1⇥1.1) xn1
  • for n = 3, 10000 and where x1 = 1, x2 = 2. Constants a and d are provided in Table 1.

Task

Write R code for the sequence xn.

(a) Compute and report the values of x500 and x5000 rounded to two decimal places (both in R and the PDF).

(b) Plot the sequence xn with proper labeling for the axes, plot title, and legend.

(c) Calculate P1000 n=1 xn, the median, and the standard deviation of xn.

Matrices

(a) Define vectors y = [x100, x200, x300, ..., x10000] and z = [x99, x199, x299, ..., x9999]. Using y and z create two matrices Y and Z of dimension (10 ⇥ 10), ordering elements by row.

(b) Calculate matrix D as follows: D = Y 0 Z. Report the value of element D4,4.

Poisson Distribution

Let X Poisson(µ). Suppose there are 25 possible values for µ, which are the first 25 observations in vector y divided by 10. Initially, assign equal plausibility to each µ, and assume an observed value of X = 2.

(a) Create a table containing µ, the respective priors, likelihoods and the posteriors.

(b) Determine the value of µ that yields the highest posterior probability

Estimating the Proportion of Cat Lovers

You want to estimate the proportion of the population ⇡ that loves cats. To do so, you survey a random sample of people. Your survey from 15 people shows the answers: where Y- yes (like), N-no (dislike)

(a) Calculate the posterior mean and variance. Write a function that has the following inputs:

  • parameters of beta prior distribution
  • parameters of beta prior distribution n: number of trials y: number of successes

Write a function beta plot(). This function plots posterior and prior density on the same graph and has the following inputs: a, b: parameters of beta prior n: number of trials y: number of successes col pri: color of prior, set “orange” as the default color. col pos: color of posterior, set “black” as the default color.

Set your prior belief about mean and the standard deviation

(a) Find a conjugate prior that matches with your prior belief. Write a function to calculate prior parameters using prior mean and prior standard deviation as inputs.

(b) What is the prior probability P(⇡ > 0.2)? P(⇡ < 0>

(c) Calculate the posterior mean and variance.

(d) What is the posterior probability P(⇡|data > 0.2)? P(⇡|data < 0>

(e) Find 68%, 90%, 95%, and 99% equal-tailed Bayesian credible intervals. Compare them with the credible interval from normal approximation. Comment on the results.

(f) Test the hypothesis that for every 100 people, the number of people who love cats is fewer than or equal to 50 people (H0- null) at a 5% significance level.

(g) Prove that “Analyzing the observations sequentially one at a time” results in the same posterior distribution as “Analyzing the observations all together in a single step”.

(h) Plot the prior and the posterior density after each step “Analyzing the observations sequentially one at a time” on the same plot. Posterior density of every step should have a larger line width (i.e. smallest line width after the first observation and the largest line width after all observations).

(i) Comment on the results.

Data Manipulation

For this question, refer to the data provided in the Excel file ”Data LB”. This dataset encompasses key indicators of the Lithuanian banking sector’s activities for the third quarter of the years 2023, 2022, and 2021. Each sheet presents data in thousands of Euros (EUR).1 To simplify the task, I will provide guidance and examples. Ensure all figures have appropriate titles, you can modify or omit the x and y-axis labels. Use the ggplot2 package for plotting and dplyr, tidyverse for data manipulation. For all plots in this question, utilize the theme minimal() theme.

Subset Data for Specific Banks

Subset the data to include only the Swedbank, AB, AB SEB bankas, Revolut Bank, UAB, AB Siauliu bankas, UAB Medicinos bankas, AB ”Mano bankas”. Calculate the total assets of these banks and determine their share of the total banking sector assets (including foreign branches). Report and comment the results in the PDF

Plot Assets

by Bank and Year Plot the total assets (named ”Total assets” in the balance sheet) for the selected banks by bank and year using geom col() and position dodge(). Refer to the example figure provided below. Replicate the figure in R and include it in the PDF

Scatter plot

Using the full dataset, create a new column ‘Bank group‘, assigning ”Selected bank” for the banks indicated in task 3.5 and ”Other bank” for the remaining banks. Filter three balance sheet items: ”Total assets”, ”Total equity”, and”Profit (loss) of the current year”. Create a wide dataset using pivot wider() and calculate the’Profit to equity ratio’ and ’Profit to asset ratio’. Produce a scatter plot with ’Profit to equity ratio’ on the x-axis and ’Profit to asset ratio’ on the y-axis, differentiating between the Bank group.

Recent Post

Order this Assignment now

Total: GBP120

fables template