A list of terms which are most often annotated to the same proteins as the selected term, and the terms least often annotated to the same proteins.
Terms which are over-represented in the proteins annotated to selected term, sorted by probability ratio.
Compared term: this is compared to the selected term
Probability ratio
Ratio of probability of compared term given selected term to probability of compared term =(#together/selected)/(#compared/#all
Probability of term here estimated as fraction of proteins annotated to term.
Probability similarity ratio
Ratio of probability of both terms to probability of either term <=#together/(#selected+#compared-#together)
Probability of term here estimated as fraction of proteins annotated to term.
Count of proteins where both selected and compared terms are annotated
Count of proteins where compared term is annotated
Total count of proteins annotated to selected term
Total count of proteins
NOT is used to make an explicit note that the gene product is not associated with the GO term.GO Consortium documentation
'Contributes_to' appears in a GO annotation when a function of a protein complex is facilitated, but not directly carried out by one of its subunits. GO Consortium documentation
'Colocalizes_with' appears in a GO annotation to indicate a transient or peripheral association of the protein with an organelle or complex. GO Consortium documentation
Electronic annotation created from application of the InterPro to GO mapping over UniProtKB. GO Consortium documentation
Electronic annotation created from application of the Enzyme Commission number to GO mapping over UniProtKB. GO Consortium documentation
Electronic annotation created from application of the Swiss-Prot Keyword to GO mapping over UniProtKB. GO Consortium documentation
Manual annotation created when a curator has searched all the relevant literature for the annotated protein and found no information supporting an annotation to any GO term in a particular ontology. This reference can only be used with the three terms; Molecular Function GO:0003674, Biological Process GO:0008150 and Cellular Component GO:0005575. GO Consortium documentation
Electronic annotation created from the transfer of experimentally verified manual GO annotation data to orthologs using Ensembl orthology data. UniProt-GOA documentation
Electronic annotation created from application of the HAMAP to GO mapping over UniProtKB. GO Consortium documentation
Electronic annotation created from application of the UniProt Subcellular Location to GO mapping over UniProtKB. GO Consortium documentation
Inferred annotation created by the GO Consortium's Reference Genome Project from annotation of evolutionary trees from the PANTHER database. GO Consortium documentation
Inferred from experiment. See GO Consortium documentation.
Inferred by direct assay. See GO Consortium documentation.
Inferred from physical interation. See GO Consortium documentation.
Inferred from mutant phenotype. See GO Consortium documentation.
Inferred from expression pattern. See GO Consortium documentation.
Inferred from genetic interaction. See GO Consortium documentation
Inferred from reviewed computational analysis. See GO Consortium documentation.
Inferred from genomic context. See GO Consortium documentation.
Traceable author statement. See GO Consortium documentation.
Non-traceable author statement. See GO Consortium documentation.
Inferred by curator. See GO Consortium documentation.
No data. See GO Consortium documentation.
Inferred from sequence or structural similarity. See GO Consortium documentation.
Inferred from sequence orthology. See GO Consortium documentation.
Inferred from sequence alignment. See GO Consortium documentation.
Inferred from sequence model. See GO Consortium documentation.
Inferred by electronic annotation. See GO Consortium documentation.

For example, 'transcription' is a type of 'nucleic acid metabolic process'.
Term A part_of term B means that term A is always a part of term B.
For example, 'transcription' is always a part of 'gene expression'.
Term A regulates term B means that term A regulates term B, but term B may not always be regulated by term A.
A sub-relation of the 'regulates' relationship.
Term A positively_regulates term B means that term B is positively regulated by term A.
A sub-relation of the 'regulates' relationship.
Term A negatively_regulates term B means that term B is negatively regulated by term A.
has_part means that term B always has as part of it term A, but term A may exist independently of term B.
For example, 'protein binding trancription factor activity' always has as a part of it 'protein binding' but 'protein binding' may occur independently of transcription factor activity.
Note that has_part is not a transitive relationship, meaning there is NO implication that gene products annotated to term A could also be correctly associated with term B or any of its parent terms.
Has_part should be read in the opposite direction to the other relationships.
Documentation coming shortly...
The filtered annotation sets you have created can be exported from QuickGO in a number of formats.
The primary format used for annotation files by the GO Consortium. Fields are provided in a 17 column tab-delimited format. The GAF2.1 format specification is described here.
Described here.
The GO Consortium guidelines on the use of the Inferred from Sequence Similarity (ISS) evidence code recommends that the 'with' field be populated with a database identifier.
Where the 'with' field is populated with 'With:Not_supplied', the annotation group that created the annotation did not provide any entry for this field.


--- title: Services layout: default bodyClass: page-services-list ---
Our business helps hundreds of customers with their irrigation and sprinkler system needs needs each year.
Please click on the service area map to schedule on the correct day(s) for your area (West Denver scheduling not yet available):
Aurora, Centennial and South Denver


LV5048 - Last 36 Hours
Dashboard
Day
(current)
Week
Month
Year
{{time}}
Battery
Power Generation and Usage
Temperatures


We try the curves with no widgets
import math
import numpy as np
import matplotlib.pyplot as plt
# import ipywidgets as widgets
# # Hypotrochoid curves
#
# Implementation follows the parametric formulae which are are due https://en.wikipedia.org/wiki/Hypotrochoid:
# > A hypotrochoid is a roulette traced by a point attached to a circle of radius **r** rolling around the inside of a fixed circle of radius **R**, where the point is a distance **d** from the center of the interior circle.
#
# Provide these parameters:
# In[3]:
def get_x(R, r, d, phi):
return (R-r)*math.cos(phi) + d*math.cos(phi*(R-r)/r)
def get_y(R, r, d, phi):
return (R-r)*math.sin(phi) - d*math.sin(phi*(R-r)/r)
# In[4]:
def prepare_curve_data(R,r,d,steps):
multip = np.lcm(r, R)
phi_grid_rad = np.linspace(0, 2*math.pi*multip/R, steps)
#phi_grid_deg = [math.degrees(phi) for phi in phi_grid_rad]
coord_x = [get_x(R,r,d,phi_val) for phi_val in phi_grid_rad]
coord_y = [get_y(R,r,d,phi_val) for phi_val in phi_grid_rad]
return (coord_x, coord_y)
#
# In[5]:
# # line
# R = 6
# r = 3
# d = 3
# # circle
# R = 6
# r = 3
# d = 0
# R = 3
# r = 4
# d = 1
R = 8 # large circle
r = 5 # small circle
d = 4 # distance from the center of the interior circle (0 ... in its center; r ... at the circle; >r ... outside of it)
#get_ipython().run_line_magic('pwd', '')
#outfile = "_".join(['example', str(R), str(r), str(d)])+'.png'
steps = 200 # how many points are plotted; smaller value creates a smoother pattern with larger size
curve_data = prepare_curve_data(R,r,d,steps)
x_data = curve_data[0]
y_data = curve_data[1]
max_value = 1.1*max(max(x_data, key=abs), max(y_data, key=abs))
# In[7]:
fig, ax = plt.subplots(figsize=(10, 10))
ax.set_xlim([-max_value, max_value])
ax.set_ylim(ax.get_xlim())
ax.set_axis_off()
plt.plot(x_data, y_data, '--')
# plt.show() # does not work with pyscript
fig #works fine with pyscript


This week we will explore the powerhouse of web development, JavaScript. What it is, how it works, and how it fits into the base web site standards we all know and love, HTML and CSS.
JavaScript is an Object Oriented Scripting language, that at it's simplest adds interactivity to a website.
If we were to think of a website as a car, the various parts could be broken down as follows:
HTML would be the chassis and structural components of the car. The bits that hold everything together and make it what we know as a car.
This is as HTML works on a website, the HTML forms the skeleton, the bones on which the site is built.
The CSS would be the body of the car, the shell, the paint, the interior, everything about how the car looks.
Much as on a web site how everything is styled using CSS, the color scheme, layout, is all controlled by CSS.
The JavaScript (JS) is the engine, driveshaft, pedals and gearbox. It is the bit the enables the car to be driven. It is what tells the engine to accelerate when the driver presses the accelerator. It Lets the user interact and "control" the site.
JavaScript controls a website, by interacting with the DOM, or Document Object Model. In this, every element on a webpage from the browser window itself, to the individual element tags, are what are referred to as Objects.
Objects are essentially what you would think of as an object. A thing that you can identify, and which you "know" things about.
Take the above childrens building blocks toy. We know that these are building blocks just by looking at them, we know they are made of wood. We know that there are six of them.
This is much like an object in JavaScript, it is a "thing" which we know information about as it is stored inside. We could describe these childrens blocks in JavaScript as below.
// This format defines an object called Childrens Blocks
var childrensBlocks = {
description: "Toy blocks for a child",
contents: block,
quantity: 6
}
// This is creating a second object called block,
which is included in the childrensBlocks object as "contents"
var block = {
description: "A single block",
material: "Wood",
numSides: 6,
Length: 5,
Width: 5,
Height: 5
}
In the above example I demonstrated creating two objects in JavaScript, the first is the Toy "childrensBlocks", in here we have a description, of what "childrensBlocks" are, what is contained in the "childrensBlocks" toy, and how many of them are in the toy. You will notice that the contents of childrensBlocks is another object called "block". Which we have a description, material, how many sides and the dimensions of the sides which allow us to understand the shape of the block.
This is how objects work, they are organised "things" which have properties, which can be read, manipulated, or changed with JavaScript. The key is that EVERYTHING is an object, and has these properties. From ones that you create as above, to <p> tags, to the browser window. Everything is an object and can be manipulated with JavaScript.
Objects are far larger than what I have been able to briefly summarise here, they have endless possibilities in what they can do. As not only can you store data in "key":"value" pairs, but you can actually add functions/methods to an object definition which can be called on any object of that type that you create in the future.
A way of storing data that is different to an object is by using arrays.
An array is a list of items in a single variable. These items can be any format and any order. An example of an array is a shopping list, Where you write down a list of all of the things that you need to buy. When finding information in an array, you can find it one of two ways, you can read each line to find the one that matches the entry you are looking for, or if you know which line of the page your item is on, you can go directly to that line number to find it.
This is exactly how searching an array works, you have the option to loop through an array and search each entry for the item you are looking for, or if you know the index (line number) in the array you are looking for you can go directly there.
// Create Shopping List Array
var array = ["Apples", "Pears", "Cereal", "Bread", "Milk"];
// Create Search Toggle
var breadFound = false;
// Loop through Array while bread is not found
for (var i = 0; breadFound == false; i++){
// Check if current entry in array is bread
if (array[i] == "Bread"){
// Bread found, set toggle, and buy bread
breadFound = true;
buyBread();
}
}
// OR Access Bread directly
// We know bread is in the fourth position which is index 3
var bread = array[3];
You may be confused as to why we used index 3 when wanting to access the fourth property in the array. The reason for this is in programming, the first entry or item is always index 0, so while you may look at the shopping list array above and see Apples is in position 1, that is index 0. A general rule of thumb for this is to count through an array normally, and then subtract 1 to get your index number.
In the above two sections we touched on what an object is and what an array is. And while they both store groups of data, the two are very different. They are different both in how they function, and what they are designed for.
An array is a grouping of like information. It can store a lot of information and is extremely useful when storing a lot of items together. An object on the other hand is a single entity. This single entity can have a lot of properties defined about it, but it is a single element, as opposed to an array containing details of multiple elements.
As described above, to access data from an array you can loop through it or navigate to an index, with an object you have another method of accessing the data, because an object is defined using what is called a "key": "value" pair. So just as with an array you can call an array's index, you can call an objects value by calling the "key" that is associated with it. To use the block example above, if I wanted to know what the length of the block is I would call either block.length or block["length"]. Either of these would return the value associated with length from block.
If they are so similar why do we need both? We need both because they serve very different purposes. An Object can store a boat load of information about an object, it can store related functions, details and many other things. However each object is an individual identity. Just as we could have an object called "person", that person would have a name, an age, an address, and all sorts of other information which we could obtain by calling on the key. However it cannot be two people. If we wanted two people we would need a second object called "person2".
As you can imagine, once you start dealing with multiple people in a database, or a application, you could have an infinite number of people, and creating a new object for each one would be impossible. So how do we keep track? With an array of objects.
You can create an array, in which each entry in the array is a person. Each one of those entries has the exact same keys, the same values, and the same functions accessible to them, and this is why we need both.
As stated earlier, everything is an object, and this is why it is called the DOM, or the Document Object Model. Because everything in the "document" or web page is an object.
Everything from the browser window, the page content, and each element on the page is an object with properties associated with it, just like the childrensBlocks example above.
In order to interact with the DOM, we need to call or reference a top level object, and then navigate through the DOM to find the object we want, and then manipulate the content as we wish.
// This button is made using the following code
<button id="example" value="0">Clicked 0 times</button>
// The following changes the buttons text when we click it
// Add a "listener" to the button to detect when someone clicks on it
document.getElementById('example').addEventListener('click', updateText, false);
// Function called when button clicked
function updateText(clickedButton){
// Add 1 to the value of the button
clickedButton.target.value = parseInt(evt.target.value) + 1;
// Replace the content inside the HTML tags
clickedButton.target.innerHTML = "Clicked " + evt.target.value + " times";
}
Looking at the above example, you can see how you can access things in the DOM. Firstly, we created a button with an ID "example". We then needed to access the DOM to find that button and we used the call document.getElementByID('example'), this informed the browser that we were wanting to find an element with the ID property with the value of example, inside the "document"/web page. When we successfully found the object we are looking for, we added what is called an "Event Listener" to it. This is essentially just something that is waiting for input by the user. In this case the "event" we are "listening" for is a mouse click. And when the button is clicked, it put's its hand up to say "Hey I was clicked!" and lets the function updateText know that it need's to do it's thing.
Once the updateText function was called, it took the button, and performed some maths on it's value property to add 1 click to it, it then replaced all text between the <button></button> tags, with new text, reflecting the new value property.
Functions are a key part of JavaScript. They are a repeatable snippet of code that can be called over and over, whenever you need it. In the button example above you saw that we created a function called updateText, which was called every time that you clicked the button. This is just the tip of the iceberg on the usefulness of functions.
Functions exist everywhere in programming, and you will interact with functions on a daily basis. Any time you log in to a website or app, it will call a "log in" function, to perform the steps of logging a user in.
Functions exist in physical form all around you if you think about it. If you have a bottle of milk you want to make cold, you put it in the fridge and call the "Refrigerate" function. If you want to make ice, you put it in your freezer and call the "Freeze" function. When you want to start your car, you put the key in the ignition and turn it, calling 2 functions. The first being an authentication/permissions challenge in which it validates if the key is the correct key for the car, and thus is it allowed to start? And if it is allowed to start, it then starts the car.
The three everyday functions described here are examples of Control Flow. With the first two being sequential, and the starting a car being selective.
Control flow is an integral part of programming. Control flow is the umbrella name given to controlling logic and the decision making process that your code uses.
Control flow is broken down into three categories: Sequential, Selection and Repetition.
Sequential control flow is the default flow for a program. It is the sequential reading and processing each line of code from the top of the page to the bottom. It can be thought of similar to if you are driving your car from one city to another and following a GPS guidance system, the instructions it gives you, when to turn, where to go, are the instructions given to the program (you) and you follow them. Completing one before moving onto the next, from the moment you start, until the moment you reach your destination.
This too is how a sequential program works, you give it instructions, in a particular order, and it will complete each instruction before moving on to the next.
// Example program starts here
var number = 0;
// Program defines a variable called number, and sets the value to 0
number = 10;
// Program sets 10 to the variable called number
window.alert(number);
// Program creates an alert box with the value of 10
This is how much code is written, and all code is interpereted this way, unless you utilise one of the following methods to change the flow. However, even when you use one of the following methods, inside those methods you will have a sequential flow.
Selection control flow, is the process of choosing a direction for the flow to proceed. This is how a program can decide what to do based on the information provided it.
The way JavaScript handles this is through the use of If-then, If-then-else, and Switch statements.
If-then statements assess if a particular situation is true, and only if it is true, processes the subsequent code. It looks like this:
// Example If-Then statement
// Validate if the Mans Name is Henry
if (mansName == "Henry"){
// If the man's name is Henry, say hello
window.alert("Hello Henry");
}
You use this process often in your day to day life. From looking at the weather to see if it is raining, and if it is raining taking an umbrella, to seeing if your cars petrol tank is running low, and if you're nearly out of gas, going to the petrol station to fill it up.
These go one step further than if-then statements, as they also provide instructions on what to do if the situation is not true.
// Example If-Then-Else statement
// Validate if the Mans Name is Henry
if (mansName == "Henry"){
// If the man's name is Henry, say hello
window.alert("Hello Henry");
} else {
// If the man's name is not Henry, ask where he is
window.alert("Where's Henry?");
}
This statement is used when deciding between two or more things to do, depending on what is required. And is again a common logic case in day to day life.
Say for example you've woken up in the morning, are making cereal, and discover that the expiry date on the milk was yesterday. You will sniff the milk, and see if it smells off.
Switch statements are used when there are multiple possibilities based on a simple case, as it is a much cleaner, and less convoluted method than checking the same variable against options in the if-then-else-if-then-else loop that can bog down many developers.
A switch statement starts by identifying the value that will be tested, and then providing a list of options(cases) that it could be. If it matches a particular case, perform that task and then stop looking.
// Example Switch statement
// Determine who you are greeting
switch(person) {}
// If the person is your mum give her a hug
case "mum":
hug(); // Call Hug Function
break; // Case Matched, exit switch
// If the person is your dad shake his hand
case "dad":
shakeHands(); // Call shakeHands Function
break; // Case Matched, exit switch
// If the person is your friend give them a High-Five
case "friend":
highFive(); // Call HighFive Function
break; // Case Matched, exit switch
// If you don't know the person, say Hi
default: // Default is like Else. And is run if no match
alert("Hello Stranger");
}
As you can see this is a very powerful tool for checking a single variable against a list of possibilities and reacting accordingly. You make decisions just like the one in the example above when running into people, and deciding how to greet them.
Repetition is a key feature of flow control. Whether it is to repeat something a particular number of times, to iterate through an array to process the information stored in it, or any number of other possibilities.
There are many ways in which you can harness repetition, and they come in the form of loops. There are two main types of loops, for loops and do-while loops.
For loops are used to follow a prescribed procedure. And to only perform the enclosed code, if the check is true. To perform a for loop, you must initialise a variable, determine the logic of when to run the code, and determine how to modify the key variable if successful
// Example For Loop
// Obtain Age
var age = 17;
// Initialise variable at 0
// Check if variable is less or equal to the entered age
// Increment the variable by 1.
for (var i = 0; i < age; i++) {
// Announce the current age
window.alert(i);
} // Repeat
This simple code snippet will take an age variable, and announce all of the numbers up to the age variable. It will essentially count up to the provided age.
This is a very basic use case of a for loop, you will often use for loops to loop through the contents of an array and perform a specific task on all of the stored data.
An example of this would be if you went to the supermarket with your shopping list.  If any of them match the items on your list, you put them in your cart. And once you have crossed every item off your list you leave. This is exactly how a for loop works. You provide the supermarket, and your shopping list and it goes through the supermarket one item at a time, and performs the same action on each item that matches.
Do-while loops are very similar to a for loop, with the exception that a do while loop will always run at least one time. The reason for this is it performs the data validation at the end of the loop rather than the beginning, which means you will always have at least one run through, before the check is performed, and then if the check is still true it will repeat, if not it will exit.
// Example Do-While Loop
// Obtain Age
var i = 0;
// Start Do-While Loop
do {
// Add 1 to i
i++;
} while (i < 5) // Repeat this if i is less than 5
An example of this in real life is tying putting on your shoes. You put your shoes on, and then you tie them, up until the point that the end case is met, which is both shoes are tied, at which point you will stop tying your shoes.
All of the properties outlined in this blog, have barely scratched the surface on what all of this is, and all that it is capable of. I hope that you have found this information interesting, though if this has peaked your interest, feel free to read on with one of the below sites which go a lot more in depth, with a lot more details.


Employee ID: 1
<EMAIL_ADDRESS>Office Number:<PHONE_NUMBER>
Intern ID: 1
<EMAIL_ADDRESS>School: University of Texas
Intern ID: 2
<EMAIL_ADDRESS>School: Texas A&M University
Employee ID: 3
<EMAIL_ADDRESS>Github Name: bo1234


This tutorial is designed to show you how to use Loop Actions and If/Else Actions. In conjunction with this you will also see how movie clips can be used to sample properties and events in the background. This is a very powerful capability that allows movies to perform parallel processing (several computations going on at the same time, not in sequence).
This tutorial is intended for beginning Flash 4 users.
No previous tutorials are required.
Download the source files and have them unzipped for review during this tutorial.
Step-by-step
Overview:
Like it or not, if you want to get the most out of Flash 4, you will need to learn the Flash 4 programing language. So for all those graphic artists out there that may be knee-jerking to this, rest assured that anyone can learn programming, while only some will ever be good graphic artists.
What you will learn with this tutorial is the following:
How to make a movie clip follow the mouse.
How to use the Loop action.
How to use the If and Else actions.
Making your movie.
In this tutorial there are both foreground movie clips and background movie clips. Background movie clips are continuously running but they don't directly display anything. Foreground movie clips will have images, button etc. that can be seen.
Background movie will be used to keep track of the mouse position and the distance from the mouse to each bird. They will perform the check to see if the mouse is near a bird and set its visibility accordingly. The foreground movie clips will contain the birds and the Mouth Man image that follows the mouse. All other images will be placed directly on the stage. O.K. so let's get started.
Start Flash and set the movie properties Modify | Movie to Frame Rate = 20, Dimensions = 550x400, and Background=Black.
First we will make the Mouthman graphic follow the mouse.
Select Libraries | Graphic and then choose the Mouthman image.
Drag the Mouthman graphic onto the stage.
Double click on the Mouthman image to open the Instance Properties window.
Select Behavior | Movie Clip and give it an Instance Name of MouthMan
The first frame of the movie is a keyframe. Double click on this to open the Frame Properties window.
Select the Actions tab.
Add an action by clicking on the + sign and then choose Drag Movie Clip
The options for this action will appear on the right. TypeMouthMan in the window and select Lock Mouse to Center.
The action should look like this:
Start Drag ("MouthMan", lockcenter)
Finally, insert a blank frame F5 and give it a stop action.
Test your movie ( Control | Test Movie ) to see if the Mouthman follows the mouse. If not double check your steps and fix any problems until it works.
Now we will add the Birds
Select Libraries | Graphic and then choose the Bird image.
Drag the Bird graphic onto the stage.
Double click on the Bird image to open the Instance Properties window.
Select Behavior | Movie Clip and give it an Instance Name of Bird1
Repeat steps b, c, and d two more times, changing the bird number to 2 and 3 respectively.
You should have three birds on stage now named Bird1, Bird2, and Bird3.
Now for the programming part.
If your Library window isn't open then select Window | Library or press CTRL-L to open it.
Select Options | New Symbol in the library window.
Give it the name Bird Hit Detect and select Movie Clip for the behavior.
Highlight frame 2 and press F5 to insert another frame.
Double click on keyframe 1 to open the Frame Properties window.
Select the Actions tab.
The actions in this keyframe must accomplish two things:
It must have a Loop (a set of statements that are repeated) that checks each bird to see if the mouse is near or not, and
It must set the visibility to FALSE if the mouse near and TRUE if the mouse is not near. Think of it like this:
Loop over three birds
check if mouse is near a bird
set visibility
End Loop (i.e. Next Bird)
First the Loop. The Loop While and End Loop surrounds a set of statements that will be executed as long as the condition statement is TRUE.
In our case we will have a bird counter n that goes from 1 to 3. As long as n is less than or equal to 3 we will continue our loop. The first thing
we must do is to set n to 1 for the first bird. Then at the very bottom of our loop we will add 1 to it each time we finish the statements in the loop.
This looks like:
Set Variable: "n" = 1
Loop While (n<=3)
--- other statements will go here ----
Set Variable: "n" = n+1
End Loop
Determine if the mouse is near one of the birds. Sorry if this sounds a bit mathematical but once you understand it you can use it in many applications.
Basically, what we are doing is computing the distance the mouse is from each bird. If that distance is smaller than the size of the bird then we found the bird and we turn it off.
So, if we let the distance the mouse is from the bird be the variable dp and we let the size of the bird be the variable rad, then we have found a bird
whenever dp is less than rad. This is where the IF and ELSE actions come in.
In english: IF dp is less than rad set visibility to FALSE, ELSE (or otherwise) set visibility to TRUE.
This looks like this:
Set Variable: "n" = 1
Loop While (n<=3)
--- other statements will go here ----
If (dp < rad)
Set Property (bird, Visibility) = False
Else
Set Property (bird, Visibility) = True
End If
Set Variable: "n" = n+1
End Loop
Now we have to set (compute) the distance (dp) and the size (rad) variables. The distance squared between two points on the screen is the sum of the differences squared between their coordinates.
In other words:
distance^2 = (X2 - X1)^2 + (Y2 - Y1)^2
where X1 and Y1 is the location of the mouse and X2 and Y2 is the location of the bird.
To make our lives more easy we will just use the width of the bird image as its size (this is best for square images).
The actions for this Hit Detection now looks like this:
Set Variable: "n" = 1
Loop While (n<=3)
Set Variable: "bird" = "/Bird"&n
Set Variable: "dx" = GetProperty (bird,_x) - GetProperty ("/MouthMan",_x)
Set Variable: "dy" = GetProperty (bird,_y) - GetProperty ("/MouthMan",_y)
Set Variable: "dx" = dx*dx
Set Variable: "dy" = dy*dy
Set Variable: "rad" = GetProperty (bird,_width)
Set Variable: "rad" = rad*rad
Set Variable: "dp" = dx + dy
If (dp < rad)
Set Property (bird, Visibility) = False
Else
Set Property (bird, Visibility) = True
End If
Set Variable: "n" = n+1
End Loop
Remember, this is the Hit Detector and it must be placed on stage. It is a background movie clip. Drag it from your symbol library
and place it anywhere you like on stage.
 The remainder of this tutorial
deals with the display of the mouse position. This is not a necessary addition. It is included just for fun.
The technique used here to display the mouse position can also be used during development of the main movie
to display variables for debug and checkout. The idea is just a simple background movie that is constantly getting the
value of a variable and placing it in a display. The display elements or fields can be placed directly on stage of they can be part of the
movie clip that is sampling the mouse position. It this case the display fields will be placed directly on stage.
Select Text Tool and select the Text Field option.
Drag the Mouthman graphic onto the stage.
Drag and area on stage where you want to display the X position of the mouse.
Repeat the above step for the Y position display.
Using the Text Tool without the Text Field selected, give these fields a label, like "X = " or something.
Now using the Arrow Tool right click on one of the Text Fields and choose Properties.
In the Text Field Properties window type the Variable name xDisplay, and un-check the Draw Border and Background box. Then click OK.
Repeat the last two steps for the yDisplay.
Now for the background movie that will get the X and Y values and place them in the display.
On your symbol library window select Options | New Symbol and give it a name Clip Position and a Behavior of Movie Clip.
On the time line select the second frame and hit F5 to insert a blank frame. This forces the first frame to be executed over and over again when placed in the main movie.
Now double click on the first keyframe and choose the Actions tab.
There will be 4 actions, 2 for the x position (get the x position and display it) and 2 for the y position (same as x).
Set Variable: "xval" = GetProperty ("/MouthMan",_x)
Set Variable: "yval" = GetProperty ("/MouthMan",_y)
Set Variable: "/:xDisplay" = xval
Set Variable: "/:yDisplay" = yval
Note: that this can be accomplished with only two lines. The extra lines are here for illustration.
Now go back to your main scene and drop this movie clip somewhere on stage.
Need More Help?
[Download Source] Don't forget to get the source files and look them over.
Troubleshooting
It's safe to say that there are a number of potential pitfalls in building a Flash 4 movie of this type. Although this is a rather simple illustration of Flash 4 programming
it is filled with movie clip references and variables. My suggestion in making a movie of this type is to have
paper and pencil handy and define variables and movie clips before hand. Make notes as you work. Be consistent in your naming convention.


{{ partial "head" . }} {{ partial "announcement" . }}
Avoid the sleepless nights and pager duty panic with release management that gives you control over software delivery every step of the way.
Benefit from precisely-targeted user segments and phased release plans to control which users see what features and when.
Validate the health and business success of your software release with Vamp’s built-in observability system.
Automatically rollback a failed release. Sleep soundly in the knowledge there is an automated safety net in place to protect your business.
At Vamp we help customers put their DevOps strategy to work by adding an average of 30% business value to their current setup. Take this two minute survey to find out how increasing your DevOps maturity with release automation can increase your DevOps ROI.
Vamp provides developers with a cutting-edge working environment, combining proven standards with cutting-edge technology.
Graphical UI and dashboards for clear information and easy management
Integrated javascript based workflow system for flexible automation
Integrated metrics and events system exposed through API, SSE and websockets.
Automatic load balancing of scaled out services and containers
API gateway features such as URL rewrites and conditional redirects
CLI and REST API for integration with CI/CD pipelines


Go to the source code of this file.
Enumerations | |
| enum | sfHttpMethod { sfHttpGet, sfHttpPost, sfHttpHead, sfHttpPut, sfHttpDelete } |
| Enumerate the available HTTP methods for a request. More... | |
| enum | sfHttpStatus { sfHttpOk = 200, sfHttpCreated = 201, sfHttpAccepted = 202, sfHttpNoContent = 204, sfHttpResetContent = 205, sfHttpPartialContent = 206, sfHttpMultipleChoices = 300, sfHttpMovedPermanently = 301, sfHttpMovedTemporarily = 302, sfHttpNotModified = 304, sfHttpBadRequest = 400, sfHttpUnauthorized = 401, sfHttpForbidden = 403, sfHttpNotFound = 404, sfHttpRangeNotSatisfiable = 407, sfHttpInternalServerError = 500, sfHttpNotImplemented = 501, sfHttpBadGateway = 502, sfHttpServiceNotAvailable = 503, sfHttpGatewayTimeout = 504, sfHttpVersionNotSupported = 505, sfHttpInvalidResponse = 1000, sfHttpConnectionFailed = 1001 } |
| Enumerate all the valid status codes for a response. More... | |
Functions | |
| CSFML_NETWORK_API sfHttpRequest * | sfHttpRequest_create (void) |
| Create a new HTTP request. More... | |
| CSFML_NETWORK_API void | sfHttpRequest_destroy (sfHttpRequest *httpRequest) |
| Destroy a HTTP request. More... | |
| CSFML_NETWORK_API void | sfHttpRequest_setField (sfHttpRequest *httpRequest, const char *field, const char *value) |
| Set the value of a header field of a HTTP request. More... | |
| CSFML_NETWORK_API void | sfHttpRequest_setMethod (sfHttpRequest *httpRequest, sfHttpMethod method) |
| Set a HTTP request method. More... | |
| CSFML_NETWORK_API void | sfHttpRequest_setUri (sfHttpRequest *httpRequest, const char *uri) |
| Set a HTTP request URI. More... | |
| CSFML_NETWORK_API void | sfHttpRequest_setHttpVersion (sfHttpRequest *httpRequest, unsigned int major, unsigned int minor) |
| Set the HTTP version of a HTTP request. More... | |
| CSFML_NETWORK_API void | sfHttpRequest_setBody (sfHttpRequest *httpRequest, const char *body) |
| Set the body of a HTTP request. More... | |
| CSFML_NETWORK_API void | sfHttpResponse_destroy (sfHttpResponse *httpResponse) |
| Destroy a HTTP response. More... | |
| CSFML_NETWORK_API const char * | sfHttpResponse_getField (const sfHttpResponse *httpResponse, const char *field) |
| Get the value of a field of a HTTP response. More... | |
| CSFML_NETWORK_API sfHttpStatus | sfHttpResponse_getStatus (const sfHttpResponse *httpResponse) |
| Get the status code of a HTTP reponse. More... | |
| CSFML_NETWORK_API unsigned int | sfHttpResponse_getMajorVersion (const sfHttpResponse *httpResponse) |
| Get the major HTTP version number of a HTTP response. More... | |
| CSFML_NETWORK_API unsigned int | sfHttpResponse_getMinorVersion (const sfHttpResponse *httpResponse) |
| Get the minor HTTP version number of a HTTP response. More... | |
| CSFML_NETWORK_API const char * | sfHttpResponse_getBody (const sfHttpResponse *httpResponse) |
| Get the body of a HTTP response. More... | |
| CSFML_NETWORK_API sfHttp * | sfHttp_create (void) |
| Create a new Http object. More... | |
| CSFML_NETWORK_API void | sfHttp_destroy (sfHttp *http) |
| Destroy a Http object. More... | |
| CSFML_NETWORK_API void | sfHttp_setHost (sfHttp *http, const char *host, unsigned short port) |
| Set the target host of a HTTP object. More... | |
| CSFML_NETWORK_API sfHttpResponse * | sfHttp_sendRequest (sfHttp *http, const sfHttpRequest *request, sfTime timeout) |
| Send a HTTP request and return the server's response. More... | |
| enum sfHttpMethod |
Enumerate the available HTTP methods for a request.
| enum sfHttpStatus |
Enumerate all the valid status codes for a response.
| CSFML_NETWORK_API sfHttp* sfHttp_create | ( | void | ) |
Create a new Http object.
| CSFML_NETWORK_API void sfHttp_destroy | ( | sfHttp * | http | ) |
Destroy a Http object.
| http | Http object to destroy |
| CSFML_NETWORK_API sfHttpResponse* sfHttp_sendRequest | ( | sfHttp * | http, |
| const sfHttpRequest * | request, | ||
| sfTime | timeout | ||
| ) |
Send a HTTP request and return the server's response.
You must have a valid host before sending a request (see sfHttp_setHost). Any missing mandatory header field in the request will be added with an appropriate value. Warning: this function waits for the server's response and may not return instantly; use a thread if you don't want to block your application, or use a timeout to limit the time to wait. A value of 0 means that the client will use the system defaut timeout (which is usually pretty long).
| http | Http object |
| request | Request to send |
| timeout | Maximum time to wait |
| CSFML_NETWORK_API void sfHttp_setHost | ( | sfHttp * | http, |
| const char * | host, | ||
| unsigned short | port | ||
| ) |
Set the target host of a HTTP object.
This function just stores the host address and port, it doesn't actually connect to it until you send a request. If the port is 0, it means that the HTTP client will use the right port according to the protocol used (80 for HTTP, 443 for HTTPS). You should leave it like this unless you really need a port other than the standard one, or use an unknown protocol.
| http | Http object |
| host | Web server to connect to |
| port | Port to use for connection |
| CSFML_NETWORK_API sfHttpRequest* sfHttpRequest_create | ( | void | ) |
Create a new HTTP request.
| CSFML_NETWORK_API void sfHttpRequest_destroy | ( | sfHttpRequest * | httpRequest | ) |
Destroy a HTTP request.
| httpRequest | HTTP request to destroy |
| CSFML_NETWORK_API void sfHttpRequest_setBody | ( | sfHttpRequest * | httpRequest, |
| const char * | body | ||
| ) |
Set the body of a HTTP request.
The body of a request is optional and only makes sense for POST requests. It is ignored for all other methods. The body is empty by default.
| httpRequest | HTTP request |
| body | Content of the body |
| CSFML_NETWORK_API void sfHttpRequest_setField | ( | sfHttpRequest * | httpRequest, |
| const char * | field, | ||
| const char * | value | ||
| ) |
Set the value of a header field of a HTTP request.
The field is created if it doesn't exist. The name of the field is case insensitive. By default, a request doesn't contain any field (but the mandatory fields are added later by the HTTP client when sending the request).
| httpRequest | HTTP request |
| field | Name of the field to set |
| value | Value of the field |
| CSFML_NETWORK_API void sfHttpRequest_setHttpVersion | ( | sfHttpRequest * | httpRequest, |
| unsigned int | major, | ||
| unsigned int | minor | ||
| ) |
Set the HTTP version of a HTTP request.
The HTTP version is 1.0 by default.
| httpRequest | HTTP request |
| major | Major HTTP version number |
| minor | Minor HTTP version number |
| CSFML_NETWORK_API void sfHttpRequest_setMethod | ( | sfHttpRequest * | httpRequest, |
| sfHttpMethod | method | ||
| ) |
Set a HTTP request method.
See the sfHttpMethod enumeration for a complete list of all the availale methods. The method is sfHttpGet by default.
| httpRequest | HTTP request |
| method | Method to use for the request |
| CSFML_NETWORK_API void sfHttpRequest_setUri | ( | sfHttpRequest * | httpRequest, |
| const char * | uri | ||
| ) |
Set a HTTP request URI.
The URI is the resource (usually a web page or a file) that you want to get or post. The URI is "/" (the root page) by default.
| httpRequest | HTTP request |
| uri | URI to request, relative to the host |
| CSFML_NETWORK_API void sfHttpResponse_destroy | ( | sfHttpResponse * | httpResponse | ) |
Destroy a HTTP response.
| httpResponse | HTTP response to destroy |
| CSFML_NETWORK_API const char* sfHttpResponse_getBody | ( | const sfHttpResponse * | httpResponse | ) |
Get the body of a HTTP response.
The body of a response may contain:
| httpResponse | HTTP response |
| CSFML_NETWORK_API const char* sfHttpResponse_getField | ( | const sfHttpResponse * | httpResponse, |
| const char * | field | ||
| ) |
Get the value of a field of a HTTP response.
If the field field is not found in the response header, the empty string is returned. This function uses case-insensitive comparisons.
| httpResponse | HTTP response |
| field | Name of the field to get |
| CSFML_NETWORK_API unsigned int sfHttpResponse_getMajorVersion | ( | const sfHttpResponse * | httpResponse | ) |
Get the major HTTP version number of a HTTP response.
| httpResponse | HTTP response |
| CSFML_NETWORK_API unsigned int sfHttpResponse_getMinorVersion | ( | const sfHttpResponse * | httpResponse | ) |
Get the minor HTTP version number of a HTTP response.
| httpResponse | HTTP response |
| CSFML_NETWORK_API sfHttpStatus sfHttpResponse_getStatus | ( | const sfHttpResponse * | httpResponse | ) |
Get the status code of a HTTP reponse.
The status code should be the first thing to be checked after receiving a response, it defines whether it is a success, a failure or anything else (see the sfHttpStatus enumeration).
| httpResponse | HTTP response |


Chapter 5 Multivariate Time Series Modelling
This chapter is heavily based on Chapter 13 of Chatfield and Xing (2019) and Tsay (2013) .
5.1 Introduction
- Multivariate time series analysis considers observations taken simultaneously on two or more time series.
- Focus of multivariate time series analysis
- Study the dynamic relationships between variables
- Serial dependence within each series and the interdependence between series.
- Improve the accuracy of prediction
- Challengers with Multivariate models
- Model building process is more difficult for multivariate than univariate models
- More variables to measure (More chance of mistakes in the data)
- More parameters to estimate
- Wider pool of candidate models
- More vulnerable to specification than simpler univariate models.
- Balance between parsimonious modelling and accurate identification.
5.2 The Cross-Correlation Function
- Cross-correlation function is a key tool in multivariate time series analysis.
- Let \(\{\mathbf{X}_t\}\) is an m-variate multivariate process, where \(\mathbf{X}_t^T = (X_{1t}, X_{2t}, \dots, X_{mt})\)
Cross-covariance
- Let \(\symbf{\mu}_t\) be the vector of mean values of \(\{\mathbf{X}_t\}\) at time t.
- Then its \(i\)th component is \(\mu_{it}=E(X_{it})\).
- Let \(\Gamma(t,t+k)\) be the cross-covariance matrix of \(\mathbf{X}_t\) and \(\mathbf{X}_{t+k}\) such that its \((i,j)\)th element is the cross-covariance coefficient of \(X_{it}\) and \(X_{j, t+k}.\)
- A multivariate process is said to be second-order stationary if the mean and the cross-covariance matrices at different lags do not depend on time.
- Then \(\symbf{\mu}_t\) will be a constant (say \(\symbf{\mu}\)) and \(\Gamma(t,t+k)\) will be a function of the lag \(k\) only ( \(\Gamma(k)\)).
- Then \(\gamma_{ij}(k)\), the \((i,j)\)th element of (\(\Gamma(k)\)) can be written as
\[\gamma_{ij}(k)=\text{Cov}(X_{it},X_{j,t+k} )= E[(X_{it}-\mu_i)(X_{j,t+k}-\mu_j)]\]
- In the stationary case, the set of cross-covariance matrices, \(\Gamma(k)\) for \(k=0, \pm1, \pm2, \dots,\) is known as covariance matrix function.
- Since
\[\gamma_{ij}(k)= \text{Cov}(X_{it},X_{j,t+k} )= \text{Cov}(X_{j,t+k}, X_{it} ) = \gamma_{ij}(-k),\]
we have \[\Gamma(k)=\Gamma^T(-k), \quad k=0, \pm1, \pm2, \dots.\]
- It is not an even function of lag.
- The diagonal terms, \(\gamma_{ii}(k)\), are auto- rather than cross- covariances, and therefore have the property of being an even function of lags.
Cross-correlation
- Let \(R(k)\) be the cross-correlation matrix function of the process.
- The \((i,j)\)the element of \(R(k)\) is given by
\[\rho_{ij}(k)= \text{Corr}(X_{j,t+k}, X_{it} )=\gamma_{ij}(k)/\sigma_i\sigma_j\] where \(\sigma_i\) is the standard deviations of \(X_{it}\) (this can also be expressed as \(\sqrt{\gamma_{ii}(0)}.\))
- When \(k>0\), the correlation coefficient measures the linear dependence of \(X_{j, t+k}\) on \(X_{it},\) which occurs after time \(t\).
- If \(\rho_{ij}(k)\neq0\) and \(k>0\), the series \(X_{it}\) leads the series \(X_{jt}\) at lag \(k\).
Furthermore, we can write \[R(K)=R^T(-k), \quad \quad k=0, \pm1, \pm2, \dots.\]
Therefore, in practice, it is enough to consider the cross-correlation matrices \(R(k)\) for \(k>0\).
Sample cross-correlation coefficient
- Let \(T\) be the total number of observations collected on the \(m\) variables over the same time period.
- Then the sample cross-covariance coefficient of \(X_i\) and \(X_j\) at lag \(k\) is given by
\[ c_{ij}(k)= \begin{cases} \sum_{t=1}^{T-k}(x_{it}-\bar{x_i})(x_{j,t+k}-\bar{x_j})/ T,& \quad k=0, 1,2, \dots,(T-1)\\ \sum_{t=1-k}^{T}(x_{it}-\bar{x_i})(x_{j,t+k}-\bar{x_j})/ T,& \quad k=-1,-2, \dots,-(T-1). \end{cases} \]
- The sample cross-correlation coefficient of \(X_i\) and \(X_j\) at lag \(k\) is given by \[\gamma_{ij}(k)=c_{ij}(k)/s_is_j\] where \(s_i=\sqrt{c_{ii}(0)}\) is the sample standard deviation of observations on the \(i\)th variable.
Example
- Consider the daily returns of adjusted closing prices of the Standard & Poor’s 500 (S&P500), the Dow Jones Industrial Average and the Nasdaq Composite indices from January 4, 1995 to February 25, 2021 (Figure 5.1).
- These three market indices characterize the performance of the U.S. stock market from different perspectives and therefore they should be highly correlated.
# Tidy financial analysis
library(tidyquant)
#S&P 500 index
sp500 <- tq_get("^GSPC", from = "1995-01-04", to = "2021-02-25" )
print(sp500)
## # A tibble: 6,582 x 8
## symbol date open high low close volume adjusted
## <chr> <date> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 ^GSPC 1995-01-04 459. 461. 458. 461. 3.20e8 461.
## 2 ^GSPC 1995-01-05 461. 461. 460. 460. 3.09e8 460.
## 3 ^GSPC 1995-01-06 460. 462. 459. 461. 3.08e8 461.
## 4 ^GSPC 1995-01-09 461. 462. 460. 461. 2.79e8 461.
## 5 ^GSPC 1995-01-10 461. 465. 461. 462. 3.52e8 462.
## 6 ^GSPC 1995-01-11 462. 464. 459. 462. 3.46e8 462.
## 7 ^GSPC 1995-01-12 462. 462. 461. 462. 3.13e8 462.
## 8 ^GSPC 1995-01-13 462. 466. 462. 466. 3.37e8 466.
## 9 ^GSPC 1995-01-16 466. 470. 466. 469. 3.16e8 469.
## 10 ^GSPC 1995-01-17 469. 470. 468. 470. 3.32e8 470.
## # … with 6,572 more rows
# The Dow Jones Industrial Average (DJIA)
dji<- tq_get("^DJI", from = "1995-01-04", to = "2021-02-25" )
print(dji)
## # A tibble: 6,582 x 8
## symbol date open high low close volume adjusted
## <chr> <date> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 ^DJI 1995-01-04 3838. 3858. 3831. 3858.<PHONE_NUMBER>.
## 2 ^DJI 1995-01-05 3858. 3861. 3843. 3851.<PHONE_NUMBER>.
## 3 ^DJI 1995-01-06 3851. 3887. 3842. 3867.<PHONE_NUMBER>.
## 4 ^DJI 1995-01-09 3867. 3874. 3853. 3861.<PHONE_NUMBER>.
## 5 ^DJI 1995-01-10 3861. 3899. 3861. 3867.<PHONE_NUMBER>.
## 6 ^DJI 1995-01-11 3867. 3883. 3840. 3862.<PHONE_NUMBER>.
## 7 ^DJI 1995-01-12 3862 3864. 3851. 3859<PHONE_NUMBER>
## 8 ^DJI 1995-01-13 3859 3910. 3859 3908.<PHONE_NUMBER>.
## 9 ^DJI 1995-01-16 3908. 3937. 3907. 3932.<PHONE_NUMBER>.
## 10 ^DJI 1995-01-17 3932. 3935. 3916. 3931.<PHONE_NUMBER>.
## # … with 6,572 more rows
# The Nasdaq Composite
nasdaq<- tq_get("^IXIC", from = "1995-01-04", to = "2021-02-25" )
print(nasdaq)
## # A tibble: 6,582 x 8
## symbol date open high low close volume adjusted
## <chr> <date> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 ^IXIC 1995-01-04 745. 746. 740. 746. 2.90e8 746.
## 2 ^IXIC 1995-01-05 747. 748. 745. 746. 2.98e8 746.
## 3 ^IXIC 1995-01-06 746. 751. 746. 750. 3.13e8 750.
## 4 ^IXIC 1995-01-09 750. 753. 750. 752. 2.67e8 752.
## 5 ^IXIC 1995-01-10 754. 759. 754. 757. 3.54e8 757.
## 6 ^IXIC 1995-01-11 758. 760. 752. 756. 3.30e8 756.
## 7 ^IXIC 1995-01-12 756. 757. 755. 757. 3.02e8 757.
## 8 ^IXIC 1995-01-13 758. 762. 757. 762. 3.14e8 762.
## 9 ^IXIC 1995-01-16 762. 769. 762. 768. 3.01e8 768.
## 10 ^IXIC 1995-01-17 769. 772. 768. 772. 3.37e8 772.
## # … with 6,572 more rows
# Convert each assets raw adjusted closing prices to returns
sp500_return <- sp500 %>%
tq_transmute(select = adjusted,
mutate_fun = periodReturn,
period = "daily")
dji_return <- dji %>%
tq_transmute(select = adjusted,
mutate_fun = periodReturn,
period = "daily")
nasdaq_return <- nasdaq %>%
tq_transmute(select = adjusted,
mutate_fun = periodReturn,
period = "daily")
p1 <- sp500_return %>%
as_tsibble(index = date) %>%
autoplot(daily.returns) +
labs(x = "Day", y= "S&P500")
p2 <- dji_return %>%
as_tsibble(index = date) %>%
autoplot(daily.returns) +
labs(x = "Day", y= "Dow Jones")
p3 <- nasdaq_return %>%
as_tsibble(index = date) %>%
autoplot(daily.returns) +
labs(x = "Day", y= "Nasdaq")
p1 / p2/ p3
A function of computing sample cross correlation
- We use the
ccm
function of theMTS
package in R to obtain the cross-correlation plots for a dataset.
library(MTS)
data <- full_join(sp500_return, dji_return, by= "date" )
data <- full_join(data, nasdaq_return, by ="date" )
colnames(data) <- c("date", "sp500", "dji", "nasdaq")
ret <- data %>%
select(sp500, dji, nasdaq) %>%
as.matrix()
MTS::MTSplot(ret)
- The concurrent interdependence of the three series are very strong.
- However, the lead-lag effect among the three series is relatively weak.
5.3 Vector Autoregressive Models
- The most commonly used multivariate time series model is the vector autoregressive (VAR) model.
- To study the properties of VAR(p) models, we start with the simple VAR(1) model.
5.3.1 VAR(1) models
- Consider \(m\)-variate multivariate process, \(\{\mathbf{X}_t\}\), where \(\mathbf{X}_t^T=(X_{1t}, X_{2t}, \dots, X_{mt}).\)
- For simplicity, we restrict the attention to the case \(m=2.\)
- For stationary series, we may, without loss of generality, assume the variables have been scaled to have zero mean.
- Now the model allows the values of \(X_{1t}\) and \(X_{2t}\) to depend linearly on the values of both series at time \((t-1_).\)
- The resulting model for the two series then consist of two equations
\[ \begin{cases} X_{1t} = \phi_{11}X_{1,t-1}+ \phi_{12}X_{2,t-1}+\epsilon_{1t}\\ X_{2t} = \phi_{21}X_{1,t-1}+ \phi_{22}X_{2,t-1}+\epsilon_{2t}\\ \end{cases} \] where \(\{\phi_{ij}\}\) are constants.
- The two error terms, \(\epsilon_{1t}\) and \(\epsilon_{2t}\) are usually assumed to be white noise, but are often allowed to be correlated contemporaneously.
- Note: If coefficients, \(\phi_{12} = \phi_{21}=0\), then \(X_{1t}\) and \(X_{2t}\) are not dynamically correlated.
- If one of \(\phi_{12}\) and \(\phi_{21}\) is not zero, say \(\phi_{12}=0\) and \(\phi_{21}\neq 0,\) then \(X_{1t}\) does not depend on the lagged values of \(X_{2t}\).
Then the system of equations reduces to \[ \begin{cases} X_{1t} = \phi_{11}X_{1,t-1}+\epsilon_{1t}\\ X_{2t} = \phi_{21}X_{1,t-1}+ \phi_{22}X_{2,t-1}+\epsilon_{2t}. \end{cases} \]
- This indicates that, while \(X_{2t}\) depends on the lagged value of \(X_{1t},\) there is no feedback from \(X_{2t}\) to \(X_{1t}.\)
That is, any causality goes only in one direction and therefore \(X_{1t}\) can be considered as the input and \(X_{2t}\) can be considered as the output.
Vector Form
- The system of equation can be written in vector form as
\[\mathbf{X}_t=\Phi\mathbf{X}_{t-1}+\symbf{\epsilon}_t\]
where \(\symbf{\epsilon}_t^T=(\epsilon_{1t},\epsilon_{2t})\) and
\[ \Phi= \begin{pmatrix} \phi_{11} & \phi_{12}\\ \phi_{21} & \phi_{22} \end{pmatrix}. \]
- The above equation looks like and AR(1) model except that \(\mathbf{X}_t\) and \(\symbf{\epsilon}_t\) are now vectors instead of scalars.
- Since \(\mathbf{X}_t\) depends on \(\mathbf{X}_{t-1}\), this model is called a vector autoregressive model of order 1 (VAR(1)).
- The above equation can also be expressed as
\[(I-\Phi B)\mathbf{X}_t=\symbf{\epsilon}_t\] where \(B\) is the backward shift operator, and \(I\) is the \((2\times2)\) identity matrix and \(\Phi B\) represents the operator matrix
\[ \begin{pmatrix} \phi_{11}B & \phi_{12}B\\ \phi_{21}B & \phi_{22}B \end{pmatrix}. \]
- The necessary and sufficient condition for the stationarity of \(\mathbf{X}_t\) is that the roots of the determinant of \(I-\Phi B\) lie outside the unit circle.
5.3.2 VAR(p) models
- The above VAR(1) model can be generalized from two to \(m\) variables and from first-order auto-regression to \(p\)th order.
- A VAR model of order \(p\) (\(VAR(p)\)) can be written in the form
\[\Phi(B)\mathbf{X}_t=\symbf{\epsilon}_t\]
where \(\mathbf{X}_t\) is a \((m\times1)\) vector of observed variables, and \(\Phi\) is a matrix polynomial of order \(p\) in the backward shift operator \(B\) such that
\[\Phi(B)=I-\Phi_1B-\dots-\Phi_pB^p,\]
where \(I\) is the \((m\times m)\) identity matrix and \(\Phi_1, \Phi_2, \dots, \Phi_p\) are \((m\times m)\) matrices of parameters.
- Since we restrict attention to stationary processes, without loss of generality, we assume the variables have been scaled to have zero mean.
- The condition for stationarity is that the roots of the equation
\[\text{determinant}\{\Phi(x)\}=|I-\Phi_1x-\Phi_2x^2-\dots-\Phi_px^p|=0,\]
should lie outside the unit circle.
- Let \(\symbf{\epsilon}_t = (\epsilon_{1t}, \epsilon_{2t}, \dots, \epsilon_{mt})\) denote and \((m\times 1)\) vector of random variables.
- This multivariate time series is called a multivariate white noise if it is stationary with zero mean vector \(\mathbf{0}\), and if the values of \(\symbf{\epsilon}_t\) at different times are uncorrelated.
- Then the \((m\times m)\) matrix of the cross-covariances of the elements of \(\symbf{\epsilon}_t\) with that of \(\symbf{\epsilon}_{t+j}\) is given by
\[ \text{Cov}(\symbf{\epsilon}_t, \symbf{\epsilon}_{t+j}) \begin{cases} \Gamma_0 & j=0\\ 0_m & j\neq0, \end{cases} \]
where \(\Gamma_0\) denotes a \((m\times m)\) symmetric positive-definite matrix and \(0_m\) denotes an \((m\times m)\) matrix of zeros.
- Therefore, each component of \(\symbf{\epsilon}_t\) behaves like univariate white noise.
- Further, \(\Gamma_0\), the covariance matrix at lag zero, does not need to be diagonal, as an innovation at a particular time point could affect more than one measured variable at that time point.
- Therefore, we allow the components of \(\symbf{\epsilon}_t\) to be contemporaneously correlated.
5.3.3 Vector ARMA models
- As in the univariate case, the VAR models can also be generalized to include moving average (MA) terms as
\[\Phi(B)\mathbf{X}_t=\Theta(B)\symbf{\epsilon}_t\]
where \[\Theta(B)=I+\Theta_1 B-\dots-\Theta_qB^p,\]
is a matrix polynomial of order \(q\) in the backward shift operator \(B\) and \(\Theta_1, \Theta_2,\dots, \Theta_q\) are \((m\times m)\) matrices of parameters.
- Then \(\mathbf{X}_t\) follows a vector ARMA (VARMA) model of order \((p,q).\)
- The necessary and sufficient condition for the stationarity of \(\mathbf{X}_t\) is that the roots of the determinant of \(I-\Phi B\) lie outside the unit circle.
- The condition for invertibility is that the roots of the equation
\[\text{determinant}\{\Theta(x)\}=|I+\Theta_1x+\Theta_2x^2+\dots+\Theta_px^q|=0,\] lies outside the unit circle.
5.3.4 Vector ARIMA models
- If \(\Phi(B)\) includes a factor of the form \(I(1-B),\) then the model is not stationary and deal with the first differences of the components of \(\mathbf{X}_t\).
- Such a model is called a vector ARIMA (VARIMA) model.
- However, in practice, it may not be optimal to difference each component of \(\mathbf{X}_t\) in the same way and should consider the possible presence of co-integration before differencing multivariate data.
- VARMA models can be generalized further by adding terms, involving additional exogenous variables to the right hand side of the equation and they are known as VARIMAX models.
5.4 Fitting VAR and VARMA models
- The process involves assessing the order \(p\) and \(q\) of the model, estimating the parameter matrices and estimating the variance-covariance matrix of the noise components.
5.4.1 Forecasting
- Forecasts can be computed for VAR, VARMA and VARIMA models by a natural extension of methods used for univariate ARIMA models.
- Minimum mean square error (MMSE) forecasts can be obtained by replacing
- future values of white noise with zeros
- future values of \(\mathbf{X}_t\) with MMSE forecasts
- present and past values of \(\mathbf{X}_t\) with the observed values
- present and past values of \(\epsilon_t\) with the one step head forecast residuals.
Example- Analysis of macro-economic series
Here we consider the U.S. quarterly gross domestic product (gdp), the civilian unemployment rate (unrate) and consumer price index (cpi) for all urban consumers from the first quarter of 1948 to the third quarter of 2017.
data <- read.csv(here::here("data", "macrots.csv" ))
data$quarter <- as.Date(data$quarter)
data <- data %>%
select(-X) %>%
as_tsibble(index = "quarter")
p1<- data %>% autoplot(gdp) +
xlab ("Quarter")
p2<- data %>% autoplot(unrate) +
xlab ("Quarter")
p3<- data %>% autoplot(cpi)+
xlab ("Quarter")
p1/p2/p3
- All the series display some level of nonstationarity (Figure 5.2).
- Therefore we transform the data by calculating the rate of change or difference for each series (Figure 5.3).
n<-nrow(data)
# Change rate of GDP
data$gdprate <- c(NA,diff(data$gdp)*100/data$gdp[1:(n-1)])
# The difference of unemployment rate
data$unemdiff <- c(NA,diff(data$unrate))
# Measure of inflation
data$cpirate <- c(NA,diff(data$cpi)*100/data$cpi[1:(n-1)])
p1<- data %>% autoplot(gdprate) +
xlab ("Quarter")
p2<- data %>% autoplot(unemdiff) +
xlab ("Quarter")
p3<- data %>% autoplot(cpirate)+
xlab ("Quarter")
p1/p2/p3
- The scatterplot matrix in Figure 5.4 shows the cross-sectional dependence of the three series.
- Figure 5.4 shows a concurrent regression relationship between
gdprate
andunemdiff
,gdprate
andcpirate
, respectively.
- Then we check the sample cross-correlations to see whether there are any lead or lag effects among the three series (Figure ??.
data2 <- data %>%
as_tibble() %>%
select("gdprate", "unemdiff", "cpirate") %>%
as.matrix()
data2 <- data2[-1,]
MTS::ccm(data2, lags = 25)
- First, we consider a VAR(1) model for \(\mathbf{X}_t\).
- We use the
VARMA
function in theMTS
R package.
## Number of parameters: 9
## initial estimates: 0.7327 0.1979 0.251 -0.077 0.3654 0.1182 0.2389 0.2681 0.5174
## Par. lower-bounds: 0.6185 -0.1504 0.0784 -0.1156 0.2477 0.0599 0.1651 0.0429 0.4058
## Par. upper-bounds: 0.8469 0.5463 0.4237 -0.0384 0.483 0.1765 0.3127 0.4933 0.629
## Final Estimates: 0.7115 0.1508 0.2786 -0.06924 0.3811 0.1073 0.2309 0.2544 0.5149
##
## Coefficient(s):
## Estimate Std. Error t value Pr(>|t|)
## gdprate 0.71155 0.05652 12.590 < 2e-16 ***
## unemdiff 0.15075 0.17319 0.870 0.384046
## cpirate 0.27860 0.08492 3.281 0.001035 **
## gdprate -0.06924 0.01926 -3.595 0.000324 ***
## unemdiff 0.38114 0.05902 6.458 1.06e-10 ***
## cpirate 0.10733 0.02894 3.709 0.000208 ***
## gdprate 0.23086 0.03713 6.217 5.07e-10 ***
## unemdiff 0.25437 0.11379 2.235 0.025392 *
## cpirate 0.51490 0.05580 9.228 < 2e-16 ***
## ---
## Signif. codes:
## 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## ---
## Estimates in matrix form:
## AR coefficient matrix
## AR( 1 )-matrix
## [,1] [,2] [,3]
## [1,] 0.7115 0.151 0.279
## [2,] -0.0692 0.381 0.107
## [3,] 0.2309 0.254 0.515
##
## Residuals cov-matrix:
## [,1] [,2] [,3]
## [1,] 1.0500 -0.16146 0.20992
## [2,] -0.1615 0.12194 0.00262
## [3,] 0.2099 0.00262 0.45331
## ----
## aic= -3.138
## bic= -3.02
- We further consider fitting a VARMA model to the series \(\mathbf{X}_t\).

- Consider the bivariate VAR(1) model
\[ \begin{pmatrix} X_{1t} \\ X_{2t} \end{pmatrix} = \begin{pmatrix} \phi_{10} \\ \phi_{20} \end{pmatrix} + \begin{pmatrix} \phi_{11} & \phi_{12}\\ \phi_{21} & \phi_{22} \end{pmatrix} \begin{pmatrix} X_{1,t-1} \\ X_{2,t-1} \end{pmatrix} + \begin{pmatrix} \epsilon_{1t} \\ \epsilon_{2t} \end{pmatrix}. \]
- Consider the \(h\)-step ahead forecast \(X_t(h)\) based on \(F_t\) and the associated forecast error \(e_t(h)\).
- Let \(X_{j,t+h}|F_{-i,t}\) be the \(h\)-step ahead prediction of \(X_{j,t+h}\) based on \(F_{-i,t}\).
- Let \(e_{j,t+h}|F_{-i,t}\) be the associated forecast error where \(i \neq j.\)
- We say that \(X_{1t}\) causes \(X_{2t}\), if the bivariate forecast for \(X_{2t}\) is more accurate than its univariate forecast.
- That is, \(X_{1t}\) causes \(X_{2t}\) if \[Var[e_{2t}(h)]<Var[e_{2,t+h}|F_{-1,t}].\]
5.5.1 Test for Granger causality
- VAR models can be used to investigate lead-lag behaviour.
- The bivariate VAR(p) model can be expressed as
\[x_t = c_1+\sum_{i=1}^p\alpha_{1i}x_{t-i}+ \sum_{i=1}^p\beta_{1i}y_{t-i}+\epsilon_{1t}\]
\[y_t = c_2+\sum_{i=1}^p\alpha_{2i}x_{t-i}+ \sum_{i=1}^p\beta_{2i}y_{t-i}+\epsilon_{2t}\]
The test for Granger causality from \(x\) to \(y\) is an F-test for the joint significance of \(\alpha_{21},\dots, \alpha_{2p},\) in an OLS regression.
Similarly, Granger causality from \(y\) to \(x\) is an F-test for the joint significance of \(\beta_{11},\dots, \beta_{1p}\).
Test for Granger Causality in R
data3 <- data %>% as_tibble() %>%
select("gdprate", "cpirate") %>%
as.matrix()
data3 <- ts(data = data3, start=c(1948,1), frequency = 4 )
head(data3)
## gdprate cpirate
## [1,] NA NA
## [2,] 2.5262 2.76596
## [3,] 2.4185 0.86957
## [4,] 0.4147 -1.27258
## [5,] -1.8834 -0.58212
## [6,] -1.3357 0.04182
## Granger causality test
##
## Model 1: gdprate ~ Lags(gdprate, 1:3) + Lags(cpirate, 1:3)
## Model 2: gdprate ~ Lags(gdprate, 1:3)
## Res.Df Df F Pr(>F)
## 1 268
## 2 271 -3 2.35 0.072 .
## ---
## Signif. codes:
## 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## Granger causality test
##
## Model 1: cpirate ~ Lags(cpirate, 1:3) + Lags(gdprate, 1:3)
## Model 2: cpirate ~ Lags(cpirate, 1:3)
## Res.Df Df F Pr(>F)
## 1 268
## 2 271 -3 4.69 0.0033 **
## ---
## Signif. codes:
## 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## Granger causality test
##
## Model 1: cpirate ~ Lags(cpirate, 1:3) + Lags(gdprate, 1:3)
## Model 2: cpirate ~ Lags(cpirate, 1:3)
## Res.Df Df F Pr(>F)
## 1 268
## 2 271 -3 4.69 0.0033 **
## ---
## Signif. codes:
## 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## Granger causality test
##
## Model 1: data3[, 2] ~ Lags(data3[, 2], 1:3) + Lags(data3[, 1], 1:3)
## Model 2: data3[, 2] ~ Lags(data3[, 2], 1:3)
## Res.Df Df F Pr(>F)
## 1 268
## 2 271 -3 4.69 0.0033 **
## ---
## Signif. codes:
## 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Using MTS
package
Perform VAR(p) and constrained VAR(p) estimations to test the Granger causality. It uses likelihood ratio and asymptotic chi-square.
data3 <- data %>% as_tibble() %>%
select("gdprate", "cpirate") %>%
drop_na() %>%
as.matrix()
MTS::GrangerTest(data3,p=3,include.mean=T,locInput=c(1))
## Number of targeted zero parameters: 3
## Chi-square test for Granger Causality and p-value: 7.065 0.06986
## Constant term:
## Estimates: 0.7174 0.004604
## Std.Error: 0.1149 0.0751
## AR coefficient matrix
## AR( 1 )-matrix
## [,1] [,2]
## [1,] 0.4498 0.000
## [2,] 0.0924 0.315
## standard error
## [,1] [,2]
## [1,] 0.0600 0.000
## [2,] 0.0407 0.059
## AR( 2 )-matrix
## [,1] [,2]
## [1,] 0.2053 0.000
## [2,] 0.0198 0.117
## standard error
## [,1] [,2]
## [1,] 0.0647 0.0000
## [2,] 0.0429 0.0617
## AR( 3 )-matrix
## [,1] [,2]
## [1,] -0.1135 0.000
## [2,] 0.0679 0.236
## standard error
## [,1] [,2]
## [1,] 0.060 0.0000
## [2,] 0.041 0.0575
##
## Residuals cov-mtx:
## [,1] [,2]
## [1,] 0.8791 0.1577
## [2,] 0.1577 0.3619
##
## det(SSE) = 0.2932
## AIC = -1.162
## BIC = -1.045
## HQ = -1.115
- Different researches show different results about the causality between economic growth and inflation.
- Fisher (1993) shows that causality goes from inflation to economic growth.
- In contrast to Fisher’s findings, Umaru and Zubariu (2011) found that Nigeria’s GDP causes inflation and not inflation causing GDP using Granger causality test.
- Studies also show that the causality relation can be different in the short run and in the long run.
- A study conducted by Datta and Chanda(2011) on Malaysia shows that causality exist between inflation and economic growth in the short run and direction of causality is from inflation to economic growth but in the long run economic growth causes inflation.
5.6 Cointegration
This chapter is heavily based on Stock and Watson (2015).
- Two or more time series with stochastic trends can move together very closely over the long run.
- Two or more time series that have a common stochastic trend are said to be cointegrated.
Definition (Stock and Watson (2015))
Suppose \(X_t\) and \(Y_t\) are integrated of order one. If, for some coefficient \(\theta\), \(Y_t-\theta X_t\) is integrated of order zero, then \(X_t\) and \(Y_t\) are said to be cointegrated. The coefficient \(\theta\) is called the cointegrating coefficient.
That is, \(X_t\) and \(Y_t\) are \(I(1)\) and if there is a \(\theta\) such that \(Y_t-\theta X_t\) is \(I(0)\), \(X_t\) and \(Y_t\) are cointegrated
Put differently, cointegration of
\(X_t\) and \(Y_t\) means that \(X_t\) and \(Y_t\) have the same or a common stochastic trend and this trend can be eliminated by taking a specific difference of the series such that the resulting series is stationary.R functions for cointegration analysis are implemented in the package
urca
Example
Consider the the relation between 3-month treasury bills, U.S. 10-years treasury bonds and the spread in their interest rates.
- Interest rates on long-term and short term treasury bonds are closely linked to macroeconomic conditions.
- While interest rates on both types of bonds have the same long-run tendencies, they behave quite differently in the short run.
- The difference in interest rates of two bonds with distinct maturity is called the term spread.
# AER package Provides functions, data sets,
# examples, and demos for Applied Econometrics
library(AER)
# A quarterly multiple time series from 1947(1) to 2004(4) with 2 variables, GDP and T-bill
data("USMacroSW")
# tbill: 3-months Treasury bills interest rate
# tbond: 10-years Treasury bonds interest rate
USMacroSW <- USMacroSW %>% as_tsibble(pivot_longer = FALSE) %>%
select(index, tbill, tbond) %>%
mutate(TSpread = tbond - tbill) %>%
pivot_longer(cols = tbill:TSpread)
p <- USMacroSW %>% autoplot(value)
print(p)
- The figure suggests that long-term and short-term interest rates are cointegrated as both interest series seem to have the same long-run behavior.
- They share a common stochastic trend.
- The term spread, which is obtained by taking the difference between long-term and short-term interest rates, seems to be stationary.
5.6.1 Testing for Cointegration
- There are three ways to decide whether two variables can plausibly be modeled as cointegrated
- use expert knowledge and economic theory
- graph the series and check whether they appear to have a common stochastic trend
- perform statistical tests for cointegration
- The unit root testing procedures discussed so far can be extended to test for cointegration.
- The insight on which these tests are based is that if two series \(Y_t\) and \(X_t\) are cointegrated, the series obtained by taking the difference \(Y_t-\theta X_t\) must be stationary.
- If the series are not cointegrated,
\(Y_t-\theta X_t\) is nonstationary [\(I(1)\)]. - The hypothesis that \(Y_t\) and \(X_t\) are not cointegrated [i.e. \(Y_t-\theta X_t\) is \(I(1)\) ] therefore can be tested by testing the null hypothesis that \(Y_t-\theta X_t\) has a unit root.
- If the hypothesis is rejected, then \(Y_t\) and \(X_t\) can be modeled as cointegrated.
- The details of this test depend on whether the cointegrating coefficient \(\theta\) is known.
<IP_ADDRESS> Testing for cointegration when \(\theta\) is known
- In some situations expert knowledge or economic theory can be used to suggest values of \(\theta\).
- When \(\theta\) is known, the Dickey-Fuller and DF-GLS unit root tests can be used to test for cointegration by first constructing the series \(z_t=Y_t-\theta X_t\) and then testing the null hypothesis that \(z_t\) has a unit autoregressive root.
<IP_ADDRESS> Testing for cointegration when \(\theta\) is unknown
- If \(\theta\) is unknown, it must be estimated before the unit root test can be applied.
- This can be done by first estimating the cointegrating coefficient \(\theta\) by OLS estimation of the regression
\[Y_t = \alpha+\theta X_t+z_t.\]
- In the second step, a Dickey-Fuller \(t\)-test (with an intercept but no time trend) is used to test for a unit root in the residual from this regression, \(\hat{z_t}.\)
- This two-step procedure is called the Engle-Granger Augmented Dickey-Fuller test for cointegration or EG-ADF test.
Extensions to Multiple Cointegrated Variables
- If there are three variables, \(Y_t\), \(X_{1t}\) and \(X_{2t}\), each of which is \(I(1)\), then they are cointegrated with cointegrating coefficients \(\theta_1\) and \(\theta_2\) if \(Y_t-\theta_1 X_{1t} -\theta_2X_{2t}\) is stationary.
- When there are three or more variables, there can be multiple cointegrating relationships.
- The EG-ADF procedure for testing a single cointegrating relationship among multiple variables is the same as for the case of two variables, except that the regression equation is modified so that both \(X_{1t}\) and \(X_{2t}\) are regressors.
- Tests for multiple cointegrating relationships can be performed using the system methods, such as Johansen’s (1988) method.
5.6.2 Vector Error Correction Models
- In the previous chapters, we eliminated the stochastic trend in an \(I(1)\) series \(Y_t\) by computing its first difference, \(\Delta Y_t.\)
- The problem created by stochastic trends were then avoided by using \(\Delta Y_t\) instead of \(Y_t\) in time series regression.
- However, if \(X_t\) and \(Y_t\) are cointegrated, there is another way to eliminate the common trend from the difference.
- Because the term \(Y_t - \theta X_t\) is stationary, it too can be used in regression analysis.
- In fact, if \(X_t\) and \(Y_t\) are cointegrated, the first differences of \(X_t\) and \(Y_t\) can be modeled using a VAR, augmented by including \(Y_{t-1} - \theta X_{t-1}\) as an additional regressor:
\[\Delta Y_t = \beta_{10} +\beta_{11}\Delta Y_{t-1}+\dots+\beta_{1p}\Delta Y_{t-p}+\gamma{11}\Delta X_{t-1}+\dots+\gamma_{1p}\Delta X_{t-p}+\alpha_1(Y_{t-1}-\theta X_{t-1}) + u_{1t}\]
\[\Delta X_t = \beta_{20} +\beta_{21}\Delta Y_{t-1}+\dots+\beta_{2p}\Delta Y_{t-p}+\gamma{21}\Delta X_{t-1}+\dots+\gamma_{2p}\Delta X_{t-p}+\alpha_2(Y_{t-1}-\theta X_{t-1}) + u_{2t}\]
- The term \(Y_t - \theta X_t\) is called the error correction term.
- The combined model in the above two equations is called a vector error correction model (VECM).
- In a VECM, past values of \(Y_t - \theta X_t\), help to predict future values of \(\Delta Y_t\) and/or \(\Delta X_t\).
Example: Application to Interest Rates
- According to the visual representation, the spread of 10-year and 3-month interest rates looks stationary
It suggests that long-term and short-term interest rates are cointegrated with a cointegration coefficient of \(\theta = 1.\)
- We continue by using formal tests (the ADF and the DF-GLS test) to see whether the individual interest rate series are integrated and if their difference is stationary (for now, we assume that \(\theta = 1\) is known).
- Both is conveniently done by using the functions
ur.df()
for computation of the ADF test andur.ers()
for conducting the DF-GLS test. - We employ models that include a drift term. (If
type
argument is set to “none” neither an intercept nor a trend is included in the test regression. If it is set to “drift” an intercept is added and if it is set to “trend” both an intercept and a trend is added.) We set the maximum lag order to 5 and use the AIC for selection of the optimal lag length.
library(urca)
# Test for nonstationarity of 3-month treasury bills using ADF test
data("USMacroSW")
TB3MS <- USMacroSW[,"tbill"] %>% as.ts()
r1 <- ur.df(window(TB3MS, c(1957, 1), c(2005, 1)),
lags = 5,
selectlags = "AIC",
type = "drift")
summary(r1)
##
## ###############################################
## # Augmented Dickey-Fuller Test Unit Root Test #
## ###############################################
##
## Test regression drift
##
##
## Call:
## lm(formula = z.diff ~ z.lag.1 + 1 + z.diff.lag)
##
## Residuals:
## Min 1Q Median 3Q Max
## -7.114 -0.386 -0.060 0.481 4.100
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.3962 0.1712 2.31 0.0218 *
## z.lag.1 -0.0696 0.0279 -2.49 0.0135 *
## z.diff.lag1 -0.0953 0.0735 -1.30 0.1964
## z.diff.lag2 -0.1906 0.0710 -2.69 0.0079 **
## z.diff.lag3 0.2386 0.0715 3.34 0.0010 **
## ---
## Signif. codes:
## 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.02 on 182 degrees of freedom
## Multiple R-squared: 0.165, Adjusted R-squared: 0.147
## F-statistic: 9.01 on 4 and 182 DF, p-value: 1.16e-06
##
##
## Value of test-statistic is: -2.494 3.123
##
## Critical values for test statistics:
## 1pct 5pct 10pct
## tau2 -3.46 -2.88 -2.57
## phi1 6.52 4.63 3.81
# Test for nonstationarity of 10-years treasury bonds using ADF test
TB10YS <- USMacroSW[,"tbond"] %>% as.ts()
r1 <- ur.df(window(TB10YS, c(1957, 1), c(2005, 1)),
lags = 6,
selectlags = "AIC",
type = "drift")
summary(r1)
##
## ###############################################
## # Augmented Dickey-Fuller Test Unit Root Test #
## ###############################################
##
## Test regression drift
##
##
## Call:
## lm(formula = z.diff ~ z.lag.1 + 1 + z.diff.lag)
##
## Residuals:
## Min 1Q Median 3Q Max
## -6.676 -0.475 -0.016 0.513 4.581
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.3592 0.1799 2.00 0.047 *
## z.lag.1 -0.0578 0.0266 -2.17 0.031 *
## z.diff.lag1 -0.1335 0.0741 -1.80 0.073 .
## z.diff.lag2 -0.1123 0.0737 -1.52 0.129
## z.diff.lag3 0.1665 0.0726 2.29 0.023 *
## ---
## Signif. codes:
## 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.03 on 181 degrees of freedom
## Multiple R-squared: 0.0999, Adjusted R-squared: 0.08
## F-statistic: 5.02 on 4 and 181 DF, p-value: 0.000733
##
##
## Value of test-statistic is: -2.175 2.365
##
## Critical values for test statistics:
## 1pct 5pct 10pct
## tau2 -3.46 -2.88 -2.57
## phi1 6.52 4.63 3.81
- Note that the function
ur.df()
reports two test statistics when there is a drift in the ADF regression. - The first of which (the one we are interested in here) is the t-statistic for the test that the coefficient on the first lag of the series is 0.
- The second one is the t-statistic for the hypothesis test that the drift term equals 0.
Test for nonstationarity using DF-GLS test
# Test for nonstationarity of 3-month treasury bills using DF-GLS test
r1 <- ur.ers(window(TB3MS, c(1957, 1), c(2005, 1)),
model = "constant",
lag.max = 6)
summary(r1)
##
## ###############################################
## # Elliot, Rothenberg and Stock Unit Root Test #
## ###############################################
##
## Test of type DF-GLS
## detrending of series with intercept
##
##
## Call:
## lm(formula = dfgls.form, data = data.dfgls)
##
## Residuals:
## Min 1Q Median 3Q Max
## -7.295 -0.280 0.109 0.544 3.864
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## yd.lag -0.04945 0.02314 -2.14 0.0340 *
## yd.diff.lag1 -0.09776 0.07449 -1.31 0.1910
## yd.diff.lag2 -0.22004 0.07462 -2.95 0.0036 **
## yd.diff.lag3 0.24177 0.07600 3.18 0.0017 **
## yd.diff.lag4 0.00428 0.07681 0.06 0.9556
## yd.diff.lag5 0.13176 0.07384 1.78 0.0761 .
## yd.diff.lag6 0.08177 0.07367 1.11 0.2686
## ---
## Signif. codes:
## 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.02 on 179 degrees of freedom
## Multiple R-squared: 0.17, Adjusted R-squared: 0.137
## F-statistic: 5.22 on 7 and 179 DF, p-value: 1.93e-05
##
##
## Value of test-statistic is: -2.137
##
## Critical values of DF-GLS are:
## 1pct 5pct 10pct
## critical values -2.58 -1.94 -1.62
# Test for nonstationarity of 10-years treasury bonds using DF-GLS test
r1 <- ur.ers(window(TB10YS, c(1957, 1), c(2005, 1)),
model = "constant",
lag.max = 6)
summary(r1)
##
## ###############################################
## # Elliot, Rothenberg and Stock Unit Root Test #
## ###############################################
##
## Test of type DF-GLS
## detrending of series with intercept
##
##
## Call:
## lm(formula = dfgls.form, data = data.dfgls)
##
## Residuals:
## Min 1Q Median 3Q Max
## -6.749 -0.346 0.102 0.612 4.565
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## yd.lag -0.0384 0.0217 -1.77 0.078 .
## yd.diff.lag1 -0.1494 0.0746 -2.00 0.047 *
## yd.diff.lag2 -0.1117 0.0754 -1.48 0.140
## yd.diff.lag3 0.1583 0.0755 2.10 0.037 *
## yd.diff.lag4 0.0594 0.0760 0.78 0.435
## yd.diff.lag5 -0.0133 0.0751 -0.18 0.860
## yd.diff.lag6 0.0510 0.0737 0.69 0.490
## ---
## Signif. codes:
## 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.03 on 179 degrees of freedom
## Multiple R-squared: 0.0962, Adjusted R-squared: 0.0609
## F-statistic: 2.72 on 7 and 179 DF, p-value: 0.0104
##
##
## Value of test-statistic is: -1.773
##
## Critical values of DF-GLS are:
## 1pct 5pct 10pct
## critical values -2.58 -1.94 -1.62
We conclude that it is plausible to model both interest rate series as I(1).
Next, we apply the ADF and the DF-GLS test to test for nonstationarity of the term spread series, which means we test for non-cointegration of long-term and short-term interest rates.
# Test if term spread is stationairy
#(cointegration of interest rates) using ADF
r1 <- ur.df(window(TB10YS, c(1957, 1), c(2005, 1)) - window(TB3MS, c(1957, 1), c(2005 ,1)),
lags = 6,
selectlags = "AIC",
type = "drift")
summary(r1)
##
## ###############################################
## # Augmented Dickey-Fuller Test Unit Root Test #
## ###############################################
##
## Test regression drift
##
##
## Call:
## lm(formula = z.diff ~ z.lag.1 + 1 + z.diff.lag)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.6094 -0.1929 -0.0407 0.1737 1.7226
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.2324 0.0483 4.81 3.1e-06 ***
## z.lag.1 -0.3796 0.0661 -5.74 3.8e-08 ***
## z.diff.lag -0.0535 0.0738 -0.73 0.47
## ---
## Signif. codes:
## 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.359 on 183 degrees of freedom
## Multiple R-squared: 0.203, Adjusted R-squared: 0.194
## F-statistic: 23.3 on 2 and 183 DF, p-value: 9.85e-10
##
##
## Value of test-statistic is: -5.742 16.49
##
## Critical values for test statistics:
## 1pct 5pct 10pct
## tau2 -3.46 -2.88 -2.57
## phi1 6.52 4.63 3.81
# test if term spread is stationairy
# (cointegration of interest rates) using DF-GLS test
r1 <- ur.ers(window(TB10YS, c(1957, 1), c(2005, 1)) - window(TB3MS, c(1957, 1), c(2005, 1)),
model = "constant",
lag.max = 6)
summary(r1)
##
## ###############################################
## # Elliot, Rothenberg and Stock Unit Root Test #
## ###############################################
##
## Test of type DF-GLS
## detrending of series with intercept
##
##
## Call:
## lm(formula = dfgls.form, data = data.dfgls)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.5303 -0.1333 0.0215 0.1957 1.6996
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## yd.lag -0.21283 0.07299 -2.92 0.004 **
## yd.diff.lag1 -0.19499 0.09027 -2.16 0.032 *
## yd.diff.lag2 -0.16075 0.08797 -1.83 0.069 .
## yd.diff.lag3 -0.09994 0.08723 -1.15 0.253
## yd.diff.lag4 -0.00339 0.08454 -0.04 0.968
## yd.diff.lag5 -0.12079 0.07981 -1.51 0.132
## yd.diff.lag6 -0.12379 0.07432 -1.67 0.098 .
## ---
## Signif. codes:
## 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.362 on 179 degrees of freedom
## Multiple R-squared: 0.206, Adjusted R-squared: 0.175
## F-statistic: 6.64 on 7 and 179 DF, p-value: 5.41e-07
##
##
## Value of test-statistic is: -2.916
##
## Critical values of DF-GLS are:
## 1pct 5pct 10pct
## critical values -2.58 -1.94 -1.62
- Both tests reject the hypothesis of nonstationarity of the term spread series at the 1% level of significance, which is strong evidence in favor of the hypothesis that the term spread is stationary, implying cointegration of long-term and short-term interest rates.
- Since theory suggests that \(\theta = 1\), there is no need to estimate \(\theta\).
- Therefore, it is not necessary to use the EG-ADF test which allows \(\theta\) to be unknown.
- However, since it is instructive to do so, we compute this test statistic. The first-stage OLS regression is
\[TB10YS_t = \beta_0 + \beta_1 TB3MS_t + z_t\]
library(dynlm)
# Estimate first-stage regression of EG-ADF test
FS_EGADF <- dynlm(window(TB10YS, c(1957, 1), c(2005, 1)) ~
window(TB3MS, c(1957, 1), c(2005, 1)))
FS_EGADF
##
## Time series regression with "ts" data:
## Start = 1957(1), End = 2005(1)
##
## Call:
## dynlm(formula = window(TB10YS, c(1957, 1), c(2005, 1)) ~ window(TB3MS,
## c(1957, 1), c(2005, 1)))
##
## Coefficients:
## (Intercept)
## 0.365
## window(TB3MS, c(1957, 1), c(2005, 1))
## 1.044
- Thus, we have
\[\hat{TB10YS_t} = 0.365 + 1.044 \times TB3MS_t\]
where \(\hat{\theta} = 1.044.\)
- Next, we take the residual series \(\hat{z_t}\) and compute the ADF test statistic.
# compute the residuals
z_hat <- resid(FS_EGADF)
# compute the ADF test statistic
r1 <- ur.df(z_hat, lags = 6, type = "none", selectlags = "AIC")
summary(r1)
##
## ###############################################
## # Augmented Dickey-Fuller Test Unit Root Test #
## ###############################################
##
## Test regression none
##
##
## Call:
## lm(formula = z.diff ~ z.lag.1 - 1 + z.diff.lag)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.8904 -0.1775 -0.0307 0.1742 1.8503
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## z.lag.1 -0.4649 0.0712 -6.53 6.3e-10 ***
## z.diff.lag -0.0043 0.0737 -0.06 0.95
## ---
## Signif. codes:
## 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.364 on 184 degrees of freedom
## Multiple R-squared: 0.234, Adjusted R-squared: 0.225
## F-statistic: 28 on 2 and 184 DF, p-value: 2.35e-11
##
##
## Value of test-statistic is: -6.528
##
## Critical values for test statistics:
## 1pct 5pct 10pct
## tau1 -2.58 -1.95 -1.62
- Sometimes lower power of the EG-ADF test can be observed due to the estimation of \(\theta.\)
- When \(\theta =1\) is the correct value, we expect the power of the ADF test for a unit root in the residuals series \(\hat{z}= TB10YS_t-TB3MS_t\) to be higher than when some estimate \(\hat{\theta}\) is used.
<IP_ADDRESS> Estimation of Cointegrating coefficient using Dynamic OLS Estimator (DOLS)
- If \(X_t\) and \(Y_t\) are cointegrated, then the OLS estimator of the coefficient in the cointegrating regression
\[Y_t=\alpha +\theta X_t+z_t\]
is consistent.
- However, in general the OLS estimator has a non-normal distribution and therefore the inferences derived from its t-statistics can produce misleading results. -There are many other alternative estimators of the cointegrating coefficient, such as dynamic OLS (DOLS) estimator (Stock and Watson, 1993).
- The DOLS is a modified version of the above equation that includes, past, present and future values of the change in \(X_t:\)
\[Y_t=\beta_0 +\theta X_t+\sum_{j=-p}^{p}\delta_j\Delta X_{t-j}+u_t.\]
- Sometime cointegration test can be misleading.
- They can improperly reject the null hypothesis of no cointegration more frequently than they should, and frequently they improperly fail to reject the null hypothesis.
- Therefore, if it important to consider economic theory, institutional knowledge and common sense when estimating and using cointegrating relationships.
A Vector Error Correction Model
- When \(Y_t\) and \(X_t\) are cointegrated, then forecasts of \(\Delta Y_t\) and \(\Delta X_t\) can be improved by augmenting a VAR of \(\Delta Y_t\) and \(\Delta X_t\) by the lagged value of the error correction term, that is, by computing forecasts using VECM.
\[\Delta Y_t = \beta_{10} +\beta_{11}\Delta Y_{t-1}+\dots+\beta_{1p}\Delta Y_{t-p}+\gamma{11}\Delta X_{t-1}+\dots+\gamma_{1p}\Delta X_{t-p}+\alpha_1(Y_{t-1}-\theta X_{t-1}) + u_{1t}\]
\[\Delta X_t = \beta_{20} +\beta_{21}\Delta Y_{t-1}+\dots+\beta_{2p}\Delta Y_{t-p}+\gamma{21}\Delta X_{t-1}+\dots+\gamma_{2p}\Delta X_{t-p}+\alpha_2(Y_{t-1}-\theta X_{t-1}) + u_{2t}\]
- In the application to the two interest rates, theory suggests that \(\theta =1\).
- The unit root tests also support modelling the two series as cointegrated with a cointegrating coefficient of 1.
TB10YS <- window(TB10YS, c(1957, 1), c(2005 ,1))
TB3MS <- window(TB3MS, c(1957, 1), c(2005 ,1))
# Set up error correction term
VECM_ECT <- TB10YS - TB3MS
# Estimate both equations of the VECM using 'dynlm()'
VECM_EQ1 <- dynlm(d(TB10YS) ~ L(d(TB3MS), 1:2) + L(d(TB10YS), 1:2) + L(VECM_ECT))
summary(VECM_EQ1)
##
## Time series regression with "ts" data:
## Start = 1957(4), End = 2005(1)
##
## Call:
## dynlm(formula = d(TB10YS) ~ L(d(TB3MS), 1:2) + L(d(TB10YS), 1:2) +
## L(VECM_ECT))
##
## Residuals:
## Min 1Q Median 3Q Max
## -6.557 -0.477 0.031 0.599 4.090
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.1908 0.1476 1.29 0.20
## L(d(TB3MS), 1:2)1 -0.0481 0.2345 -0.20 0.84
## L(d(TB3MS), 1:2)2 -0.3184 0.2155 -1.48 0.14
## L(d(TB10YS), 1:2)1 -0.1353 0.2384 -0.57 0.57
## L(d(TB10YS), 1:2)2 0.1275 0.2192 0.58 0.56
## L(VECM_ECT) -0.3242 0.2086 -1.55 0.12
##
## Residual standard error: 1.04 on 184 degrees of freedom
## Multiple R-squared: 0.0782, Adjusted R-squared: 0.0531
## F-statistic: 3.12 on 5 and 184 DF, p-value: 0.00996
##
## Time series regression with "ts" data:
## Start = 1957(4), End = 2005(1)
##
## Call:
## dynlm(formula = d(TB3MS) ~ L(d(TB3MS), 1:2) + L(d(TB10YS), 1:2) +
## L(VECM_ECT))
##
## Residuals:
## Min 1Q Median 3Q Max
## -6.956 -0.381 0.054 0.523 3.776
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.0167 0.1503 -0.11 0.912
## L(d(TB3MS), 1:2)1 -0.1520 0.2388 -0.64 0.525
## L(d(TB3MS), 1:2)2 -0.4163 0.2194 -1.90 0.059 .
## L(d(TB10YS), 1:2)1 -0.0354 0.2427 -0.15 0.884
## L(d(TB10YS), 1:2)2 0.1668 0.2232 0.75 0.456
## L(VECM_ECT) 0.0156 0.2123 0.07 0.942
## ---
## Signif. codes:
## 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.06 on 184 degrees of freedom
## Multiple R-squared: 0.0951, Adjusted R-squared: 0.0705
## F-statistic: 3.87 on 5 and 184 DF, p-value: 0.00235
# coefficient summaries using HAC standard errors
coeftest(VECM_EQ1, vcov. = NeweyWest(VECM_EQ1, prewhite = F, adjust = T))
##
## t test of coefficients:
##
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.1908 0.1754 1.09 0.28
## L(d(TB3MS), 1:2)1 -0.0481 0.2521 -0.19 0.85
## L(d(TB3MS), 1:2)2 -0.3184 0.2740 -1.16 0.25
## L(d(TB10YS), 1:2)1 -0.1353 0.3302 -0.41 0.68
## L(d(TB10YS), 1:2)2 0.1275 0.2273 0.56 0.58
## L(VECM_ECT) -0.3242 0.2925 -1.11 0.27
##
## t test of coefficients:
##
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.0167 0.1533 -0.11 0.91
## L(d(TB3MS), 1:2)1 -0.1520 0.3154 -0.48 0.63
## L(d(TB3MS), 1:2)2 -0.4163 0.3231 -1.29 0.20
## L(d(TB10YS), 1:2)1 -0.0354 0.3778 -0.09 0.93
## L(d(TB10YS), 1:2)2 0.1668 0.2675 0.62 0.53
## L(VECM_ECT) 0.0156 0.2575 0.06 0.95
- If \(X_t\) and \(Y_t\) are cointegrated, then the DOLS estimator is efficient in large samples.
- Heteroskedasticity, autocorrelation invalidates the usual standard error formulas as well as heteroskedasticity-robust standard errors since these are derived under the assumption that there is no autocorrelation.
- When there is both heteroskedasticity and autocorrelation, heteroskedasticity and autocorrelation-consistent (HAC) standard errors need to be used.
- For example, the t-statistic constructed using DOLS estimator with HAC standard errors has a standard normal distribution in large samples.
Further Reading: Pfaff, B. (2008). Analysis of integrated and cointegrated time series with R. Springer Science & Business Media.
5.7 References:
Chatfield, C., & Xing, H. (2019). The analysis of time series: an introduction with R. CRC press.
Kleiber, C., & Zeileis, A. (2008). Applied econometrics with R. Springer Science & Business Media.
Pfaff, B. (2008). Analysis of integrated and cointegrated time series with R. Springer Science & Business Media.
Stock, J. H., & Watson, M. W. (2015). Introduction to econometrics.
Tsay, R. S. (2013). Multivariate time series analysis: with R and financial applications. John Wiley & Sons.
References
Chatfield, Chris, and Haipeng Xing. 2019. The Analysis of Time Series: An Introduction with R. CRC press.
Stock, James H, and Mark W Watson. 2015. Introduction to Econometrics.
Tsay, Ruey S. 2013. Multivariate Time Series Analysis: With R and Financial Applications. John Wiley & Sons.


Trump Throws Twitter Tantrum Right Before The Fifth Day Of Impeachment Hearings
It’s getting to him.
In the hours leading up to the fifth day of impeachment hearings, President Trump threw a tantrum in a series of tweets Thursday morning.
The President’s Thursday morning tweets mainly took aim at what he calls a “phony impeachment hoax” and labeled Democrats “human scum.”
Trump doubled down on his reaction to the public testimony of EU Ambassador Gordon Sondland, which Trump said was “fantastic” and proved that he “did absolutely nothing wrong,” despite how Sondland’s testimony was damning.
Trump also appeared to reference a call between himself and Sondland in which Trump allegedly asked about the status of “investigations.”
Trump then pivoted to railing against former Special Counsel Bob Mueller.
A few minutes later, Trump went back to tweeting about the impeachment hearings and reiterated his argument that “the calls (transcripts) were perfect, there was nothing said that was wrong.”
The President then elaborated on the “great corruption and dishonesty” by House Intelligence Chair Adam Schiff (D-CA).


An anchor in an iframe
An anchor in an
nested
element in an iframe
Click me, I go nowhere
I load elsewhere
Click Me


Here's how Ranveer Singh is prepping for his anniversary
by FilmfareIt feels like only yesterday when Deepika Padukone and Ranveer Singh announced their marriage on social media with some beautiful pictures from their wedding. But believe it or not, the power couple is only a day away from their first anniversary and we’re counting hours before their big day.
 After that, the couple will head to Amritsar to visit Golden Temple. But before the couple rings in their first wedding anniversary, they spent their day prepping for celebration. Deepika Padukone shared a picture on Instagram of Ranveer Singh wearing a face pack. She captioned the picture, “Ranveer Singh in preparation for his first wedding anniversary.”
After a day of spa and some pampering, the two have flown to Tirupati. Well, we’re not surprised Ranveer Singh has a beauty routine before his vacation. After all, it’s not easy being the most gorgeous couple in B-town, right?


Sukiyaki2 browser distributed training client
Training setting:
CL Batch division size:
Setup network
Control server uri:
Variable server uri:
Run training


Interface CsvCallback<T>
- Type Parameters:
T
-
- All Known Implementing Classes:
DefaultCsvCallback
public interface CsvCallback<T>
You can provide your own CsvCallback implementation to customise the CSV processing. It is expected that the DefaultCsvCallback provides a good base class that you can extend.
-
Method Summary
Modifier and Type Method Description void
begin(EbeanServer server)
The processing is about to begin.void
end(int row)
The processing has ended successfully.void
endWithError(int row, Exception e)
The processing has ended due to an error.void
processBean(int row, String[] line, T bean)
Called for each bean after it has been loaded from the CSV content.boolean
processLine(int row, String[] line)
Check that the row should be processed - return true to process the row or false to ignore the row.void
readHeader(String[] line)
Read the header row.
-
Method Details
-
begin
The processing is about to begin.Typically the callback will create a transaction, set batch mode, batch size etc.
-
readHeader
Read the header row.This is only called if
CsvReader.setHasHeader(boolean, boolean)
has been set to true.- Parameters:
line
- the header line content.
-
processLine
Check that the row should be processed - return true to process the row or false to ignore the row. Gives ability to handle bad data... empty rows etc and ignore it rather than fail. -
processBean
Called for each bean after it has been loaded from the CSV content.This allows you to process the bean however you like.
When you use a CsvCallback the CsvReader *WILL NOT* create a transaction and will not save the bean for you. You have complete control and must do these things yourself (if that is want you want).
- Parameters:
row
- the index of the content being processedline
- the content that has been used to load the beanbean
- the entity bean after it has been loaded from the csv content
-
end
The processing has ended successfully.Typically the callback will commit the transaction.
-
endWithError
The processing has ended due to an error.This gives the callback the opportunity to rollback the transaction if one was created.
- Parameters:
row
- the row that the error has occured one
- the error that occured
-