Monthly Archives: October 2015

Using program in Casio fx-9860Gii for matrix operation

To implement the Wald test as previously done in the TI Nspire CX CAS on the Casio 9860, some programming can help achieve building the matrices more easily. In the Casio Basic, list and matrix are accessed in index and by looping through for loops, values from formula calculation can be assigned. This result in the same matrix constructed in using the constructMat() function in the Nspire.

wald-casio3

The rest of calculations are the same.

wald-casio1

wald-casio2

Advertisements

Wald Test for Logistic Regression

The Wald test can be demonstrated using example from the previous post on the likelihood test for logistic regression. Again, assuming a confidence level of 95%. The hypothesis setting is a little different because this test targets individual parameter in the regression model:

Null hypothesis: A1=0
Alternative hypothesis: A1≠0

To test the hypothesis, the statistic below is obtained using the following equation:

( ma × mb × ma)-1

where ma and mb are matrices and defined as below.

ma consists of the x1 and x2 variables as first and second row, and all 1s as the third row. In the TI Nspire, the function colAugment is convenient to construct matrix from multiple lists.

wald1

The next step involved determining the y hat values from the regression model for each data row.wald2

Once determined, the matrix mb can be defined as below. It is a diagonal matrix with values correspond to the equation of y_hat × (1 - y_hat). Notice how constructMat worked with the piece-wise expression for this diagonal matrix.

wald3

The calculation can then be performed. The final results as shown in the second equation below is then used for determination of the P-value of χ² distribution in 1 degree of freedom.

wald4

Since the value is less than 0.05, the conclusion is to reject the null hypothesis A1=0 and accept the alternative hypothesis A1≠0.

Likelihood ratio test for Logistic Regression

Using a previous example on logistic regression, the likelihood ratio can be calculated for an estimate of goodness of fit of the parameters in the regression model. Assuming a confidence level of 95%, and hypothesis setting below:

Null hypothesis: A1=A2=0.
Alternative hypothesis: Not A1=A2=0.

Firstly, recall the parameters of the logistic regression are obtained by the Nelder-Mead method:

lr-likelihood-ratio1

Since the maximum likelihood approach is used, the maximum likelihood value, L, is obtained:

lr-likelihood-ratio2

The success and failure count are obtained, and then substituted into the equation below together with the maximum likelihood.

lr-likelihood-ratio3

Finally, the χ² distribution for the value obtained above is determined, with degree of freedom of 2.

lr-likelihood-ratio4

Since P-value is smaller than 0.05, therefore the conclusion is reject the null hypothesis A1=A2=0 and accept Not A1=A2=0.

Re-mounting an AWS EBS Volume to another instance

This is handy for a lot of reasons, like rescuing disk data or fixing boot configuration. The detail is here at the Amazon documentation. The outline of steps is below:

  1. Stop the original instance.
  2. Detach the volume from the stopped instance.
  3. Create a new instance of similar type to the original instance and assign the same security group.
  4. Start the new instance.
  5. Attach the detached original volume to the new instance as /dev/xvdf
  6. Login to the new instance, create mount point and mount the original volume.
  7. Once completed, umount the original volume and detach from the new instance.
  8. Attach the original volume to the original instance as /dev/sda1
  9. Start the original instance.

Essential commands for this, based on Ubuntu. Some steps above are done in the AWS Console GUI.

ubuntu:~$ lsblk
 NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
 xvda 202:0 0 8G 0 disk
xvda1 202:1 0 8G 0 part /
 xvdf 202:80 0 10G 0 disk
xvdf1 202:81 0 10G 0 part
ubuntu:~$ sudo file -s /dev/xvdf
 /dev/xvdf: x86 boot sector
ubuntu:~$ sudo mkdir /rescue
ubuntu:~$ sudo mount /dev/xvdf1 /rescue

Useful R commands and techniques

A collection of some frequently used R commands.

Creating column for categorical group assignment. Shown below is to assign A/B/C according to some existing values.
R-Technique1-grouping

Similarly for new column for derived values from existing column.
R-Technique2-new-dependent-column

Sampling using the sampling package with strata.
R-Technique5a-sampling

With R Studio, view command can be invoked from clicking the variable under the Environment tab, and the frame will then be listed nicely in a tabular format in the data frame window.
R-Technique4-view

Data frame at a glance – head, str, summary.R-Technique3-head-str-summary