## Question

How to use your newly computed v and d to calculate u on the second half of the data?

You asked us the following:

#Download the subscriptions dataset. Select NbrNewspapers, TotalDiscount, TotalPrice, and TotalCredit and perform an svd on the

#first half of the dataset. Then, use your newly computed v and d to calculate u on the second half of the data.

This is my question:

How do you use the newly computed v and d to calculate u on the second half of the data?

This is my code and output:

subs <- read.table(URL_subs,

header=TRUE, sep=";")

subs <- subs[,c("NbrNewspapers", "TotalDiscount","TotalPrice","TotalCredit")]

if (!require("imputeMissings")) {

install.packages('imputeMissings',

repos="https://cran.rstudio.com/",

quiet=TRUE)

require('imputeMissings')

}

subs.imp <- impute(subs)

subs_mat <- as.matrix(subs.imp)

s_full <- svd(subs_mat)

s_1st_half <- svd(subs_mat[1:113,1:4])

s_2nd_half <- svd(subs_mat[114:227,1:4])

head(subs_mat %*% s_1st_half$v %*% solve(diag(s_1st_half$d)))

[,1] [,2] [,3] [,4]

[1,] -0.03544355 -0.038401648 -0.04863225 0.03483562

[2,] -0.01878869 0.081475211 -0.07519979 0.01591364

[3,] -0.12731758 -0.002753235 0.07964934 -0.03396345

[4,] -0.12484944 0.022215819 0.11986740 -0.09968578

[5,] -0.12731758 -0.002753235 0.07964934 -0.03396345

[6,] -0.12484944 0.022215819 0.11986740 -0.09968578

How can I get the code to predict 114 rows instead of 6?

## Answers and follow-up questions

** Answer or follow-up question 1** Dear student,

'How do you use the newly computed v and d to calculate u on the second half of the data?'

Please note that you are repeating back the question that I asked you to solve.

If I answer this question I am solving the assignment for you. However, here are two hints:

You need to use subsetting.

Look closely at this line: subs_mat %*% s_1st_half$v %*% solve(diag(s_1st_half$d))

'How can I get the code to predict 114 rows instead of 6?'

The head function means 'display only the first six rows'.

Michel Ballings

Sign in to be able to add an answer or mark this question as resolved.