/*
#
# Stat 202A - Homework 6
# Author: Anshita Mehrotra
# Date : 11/10/2016
# Description: This script implements sweep and QR
# operations in Rcpp
#
#
# INSTRUCTIONS: Please fill in the missing lines of code
# only where specified. Do not change functio
Stat 202a, Sta(s(cal Compu(ng. Prof. Rick Paik Schoenberg.
1. Administra(ve things.
2. R very basics.
3. Output in R.
4. Func(ons in R.
5. Logical operators in R.
6. Element selec(on and redeni(on in R.
7. Vector
Stat 202a, Sta(s(cal Compu(ng. Prof. Rick Paik Schoenberg.
1. Modes and lists.
2. Finding the sta(s(cal mode in R.
3. Working directories and libraries.
4. Input and output in R.
1. Modes and Lists
Two common pr
# Find sqrt(sum of 1/k^2.1), for k = 1, 2, 3, .n = 100000x = rep(1,n)for (k in 2:n)cfw_ x[k] = x[k-1] + 1/k^2.1y = sqrt(x)par(mfrow=c(1,2) # do this if you want two plots per page.plot(c(0,n),c(min(y),max(y),type="n",xlab="k", ylab="sqrtcfw_sum of 1/i^2.1
1. Hw etc.2. R Cookbook ch1-4, continued.3. R Cookbook ch5.4. R Cookbook ch6.1. HW2, etc.We will talk about kernel smoothing next week.Read up through ch7 in R Cookbook.Loading in the housing data.I took out the first line about the overrall county, I rem
Homework 2. Stat 202a. Due Tue Oct 28, 10:30am.
You must work on the homework INDEPENDENTLY! Collaborating with other students
on this homework will be considered cheating. Submit your homework by email to
stat202a@stat.ucla.edu. Late homeworks will not b
Homework 1. Stat 202a. Due Thu, Oct 16, 10:30am. Late hws will not be accepted!
You must work on the homework INDEPENDENTLY! Collaborating on this homework
will be considered cheating. Submit your homework via the CLCC website
https:/ccle.ucla.edu/course/
Overview
Before building
S3 classes
Building R Packages
An Introduction
David Diez
Biostatistics Dept
Harvard SPH
Packaging
Wrap-up
Overview
Before building
S3 classes
Packaging
Wrap-up
Original version and source
Original author: David M Diez
The product
Undergrad probability course
(not a poker strategy guide nor
an endorsement of gambling).
Standard undergrad topics +
random walks, arcsine laws, and
a few other specialized topics.
Instead of balls and urns, the
0. HW4.1. MLE.2. MLE for Hawkes point processes.3. MLE using optim().0. HW4 is now due Wed Nov 27 1030am instead of Tue Nov 26.1. MLE. Instead of minimizing the sum of squared residuals as in regression,one can estimate the parameters of a model by findin
0. Bonev's info.1. Projects.2. Bias in sample variance?3. Making R packages.4. Calling R from C.0. Bonev's Python and object oriented programming info.Boyan Bonev's email is bonev@ucla.edu.His slides are at http:/www.stat.ucla.edu/~boyan/python_stats202a.
0. Announcements.1. Matrices in C.2. Python and MySQL references.3. Generalized additive models.4. Bias in the sample SD.0. Announcements.Reminder, HW3 is due this Thursday, 11/14 by email.Thu 11/14 we will have a guest lecture on Python by Boyan Bonev.1.
Stat 202a, Sta(s(cal Compu(ng. Prof. Rick Paik Schoenberg.
1. Logical operators in R.
2. Element selec(on and redeni(on in R.
3. Vector arithme(c and order of opera(ons in R.
4. pi.r and hw1.
5. PloGng the sample
#
# Stat 202A - Homework 5
# Author: Anshita Mehrotra
# Date : 11/03/2016
# Description: This script implements factor analysis and
# matrix completion
#
#
# INSTRUCTIONS: Please fill in the missing lines of code
# only where specified. Do not change func
#
# Stat 202A - Homework 7
# Author: Anshita Mehrotra
# Date : 11/17/2016
# Description: This script implements PCA and logistic
# regression.
#
#
# INSTRUCTIONS: Please fill in the missing lines of code
# only where specified. Do not change function name
#
# Stat 202A - Homework 6
# Author: Anshita Mehrotra
# Date : 11/10/2016
# Description: This script implements QR decomposition
# and linear regression based on QR
#
#
# INSTRUCTIONS: Please fill in the missing lines of code
# only where specified. Do no
mySweep <- function(A, m)cfw_
#
#
#
#
#
Perform a SWEEP operation on A with the pivot element A[m,m].
A: a square matrix.
m: the pivot element is A[m, m].
Returns a swept matrix.
# Leave this function as is unless you want to make it
# more efficient!
n <
#
# Stat 202A - Homework 2
# Author: Anshita Mehrotra
# Date : 10/16/2016
# Description: This script implements ridge regression as
# well as piecewise linear spline regression.
#
#
# INSTRUCTIONS: Please fill in the missing lines of code
# only where spe
#
# Stat 202A - Homework 1
# Author: amehrotra
# Date : 10/04/2016
# Description: This script implements the sweep operator as
# well as Gauss-Jordan elimination in both plain and
# vectorized form
#
#
# INSTRUCTIONS: Please fill in the missing lines of c
"
Stat 202A - Homework 1
Author: Anshita Mehrotra
Date : 10/04/2016
Description: This script implements the sweep operator as
well as Gauss-Jordan elimination in both plain and
vectorized form
INSTRUCTIONS: Please fill in the missing lines of code
only wh
#
# Stat 202A - Homework 4
# Author: Anshita Mehrora
# Date : 10/24/2016
# Description: This script implements stagewise regression
# (epsilon boosting)
#
#
# INSTRUCTIONS: Please fill in the missing lines of code
# only where specified. Do not change fun
#
# Stat 202A - Homework 4
# Author: Anshita Mehrotra
# Date : 10/27/2016
# Description: This script implements stagewise regression
# (epsilon boosting)
#
#
# INSTRUCTIONS: Please fill in the missing lines of code
# only where specified. Do not change fu
#
# Stat 202A - Homework 3
# Author: Anshita Mehrotra
# Date : 10-20-2016
# Description: This script implements the lasso
#
#
# INSTRUCTIONS: Please fill in the missing lines of code
# only where specified. Do not change function names,
# function inputs
#
# Stat 202A - Homework 3
# Author: Anshita Mehrotra
# Date : 10/18/2016
# Description: This script implements the lasso
#
#
# INSTRUCTIONS: Please fill in the missing lines of code
# only where specified. Do not change function names,
# function inputs
0. Misc.1. Sum of squared differences from observations for each gridpoint.2. Kernel regression.3. Teetor ch. 11.4. Projects.0. Misc.Reminder, no class or OH Tue Nov 5.After today, you will have seen everything you need for all 4 homeworks in my opinion.
0. Final projects and other miscellaneous notes.1. Defining vectors and matrices within C.2. C functions communicating.3. Running C from terminal.4. Reading in from a file.0. Final projects and other misc notes.HW3 is due by email Thu Nov 14, 1030am.Group
Homework 3. Stat 202a. Due Thur, Nov 14, 10:30am.
You must work on the homework INDEPENDENTLY! Collaborating on this homework
will be considered cheating. Submit your homework by email to stat202a@stat.ucla.edu.
Late homeworks will not be accepted! Your h
Homework 1. Stat 202a. Due Tue, Oct 8, 10:30am.
You must work on the homework INDEPENDENTLY! Collaborating on this homework
will be considered cheating. Submit your homework to me by email to
stat202a@stat.ucla.edu. Your homework solution should be a sing
from numpy import *
def myqr(Aarr):
A = mat(Aarr)
nrow, ncol = A.shape
R = A.copy()
Q = mat(eye(nrow)
for k in range(ncol):
x = mat(zeros(nrow,1)
x[k:,0] = R[k:,k]
length = sqrt(x.T * x)[0,0])
x[k,0] = x[k,0] - length
# x switch to u
if length = 0:
contin
from numpy import *
def myqr(Aarr):
A = Aarr
nrow, ncol = A.shape
R = A.copy()
Q = eye(nrow)
for k in range(ncol):
x = zeros(nrow,1)
x[k:,0] = R[k:,k]
length = sqrt(dot(x.T, x)
x[k,0] = x[k,0] - length
# x switch to u
v = x / sqrt(dot(x.T, x)
R = dot(eye(