Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is the R code when we have one column has missing values, we replace NA vs mu value, but how modifying the code when

This is the R code when we have one column has missing values, we replace NA vs mu value, but how modifying the code when we have three columns has missing values

#3.1

#Note I'm replacing missing values with mu.tilda now.

for(j in 1:n){ if(sum(is.na(data[j,])) > 0){ data1[j,1] = mu.tilda[1] + sig.tilda[1,2:3]%*%solve(sig.tilda[2:3,2:3])%*%t(as.matrix(data[j,2:3] - mu.tilda[2:3])) } }

# only one column has missing values #3.4

for(j in 1:n){ if(sum(is.na(data[j,])) > 0){ x1x1.imp = sig.tilda[1,1] - sig.tilda[1,2:3]%*%solve(sig.tilda[2:3,2:3])%*%sig.tilda[2:3,1] + data1[j,1]^2 x1x2.imp = data1[j,1]*as.matrix(data[j,2:3]) x2x2 = t(as.matrix(data[j,2:3]))%*%as.matrix(data[j,2:3]) temp = matrix(0,3,3) temp[1,1] = as.matrix(x1x1.imp) temp[1,2:3] = x1x2.imp temp[2:3,1] = x1x2.imp temp[2:3,2:3] = x2x2 xtx[[j]] = temp } else{ xtx[[j]] = t(as.matrix(data[j,]))%*%as.matrix(data[j,]) } }

How to write the function if we are missing 1 variable then create 2x2 matrix, if missing 2 variables and create 1x1 matrix instead of 6 cases???

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Mathematics questions