Monthly Archives: January 2018

Classrooom Management at the University Level

Classroom management is different at the university level when compared to K-12. Often the problem is not behavioral in nature (with the exception of cell phones). Rather a lot of the classroom management problems at a university are academically related. In the classroom, the problem is often inattentiveness or idleness. In general, the challenge is completing assignments and being prepared for assessments.

Clear Syllabus

Making sure the syllabus is clear is critical for better performance of students. The syllabus includes the calendar, assignment requirements, rules, etc. When these are laid out in advance expectations are set the students strives to reach.

If the syllabus is unclear it normally means the expectations are unclear and even that the teaching is unclear. Most universities have a standard format for their syllabuses but it is still the teacher responsibility to explain clearly the expectations

Stick to the Syllabus

When the course has begun the commitments and expectations stipulated in the syllabus should be fully committed to. It is better to think of the syllabus as a binding contract between two parties. Once it is distributed and discuss there is nothing left to negotiate.

Related to this is the need to actually enforce rules. If there is a late policy it must be enforced otherwise students will think that you are not serious and the students will push for more concession. This can quickly snowball into chaos. If you actually have a rule against cellphones than it needs to be supported or you will develop students who have a disdain for people who don’t enforce their rules.

Provide Feedback

Perhaps one of the biggest problems in academia is a lack of feedback. Many professors may only have three assignments in a course per year. Given that there is almost always a mid-term and final in many courses and these are primarily summative assessment and not really for learn only. Many students have one assignment that extends beyond multiple choice.

This means that students need constant feedback. This allows for students to learn from their mistakes as well as provide them with motivation to complete their students. It is not always practical to mark every assignment. A shortcut would be to look at a sample of assignments and explain common errors to the class.

Mix Teaching Styles 

The last useful strategy will help to reduce daydreaming and listlessness. The most common teaching approach is usually lecture or direct-instruction. The problem is that if everyone does this it becomes really boring for any students. Therefore, lecturing is only bad if this is the only instructional model being used.

To maintain engagement means to used different teaching methodologies. While the syllabus should be structured and unchanging good teaching often has a flair and a slight degree of unpredictability that makes the classroom interesting

Conclusion

Teaching at any level is hard. However, classroom management at the university level can be challenging as this is not the most widely discussed topic. For, success a professor needs to commit to the syllabus while being flexible in their delivery of content.

Classroom Management Ideas

One of the greatest challenges in teaching is classroom management. Students are always looking for ways and opportunities to test the limits of acceptable behavior. For teachers, these constant experimentation with the boundaries of how to act are extremely tiresome.

However, there are several strategies that teachers can use to limit poor behavior. Some of these ideas include the following.

  • Setting routines
  • Rehearsing transitions
  • Anticipating behavior
  • Non-Verbal cues

Set Routines

Establishing clear routines will help to regulate the behavior of students tremendously. When everybody knows their role and what to do there is usually less curiosity for a student to see what they can get away with.

Routine need to be explained, demonstrated, and practice in order for students to master them. Once a routine is established most students enjoy the predictability of having set actions that they need to perform and certain times of the day. While instruction should be varied and exciting routines provide a sense of stability and security to brilliant teaching.

Rehearse Transitions

A specific form of routine are transitions. Transitions are those moments in class when you have to move from one activity to another. An example would be going out to recess or coming in from recess, etc.

It is at moments like these that everyone is active. With so many moving parts and actions taking place, this is when the most breakdowns in behavior can often take place. Therefore the teacher needs to be extra diligent during the moments and make sure the routines are thoroughly drilled to avoid near absolute chaos.

Anticipation

Anticipating has to do with seeing what might happen before it actually happens. An analogy would be to an athlete who sees an opportunity to make a great play because of the actions of his opponent. A teacher must be able to read the class and be one-step ahead of the students.

A term related to this is called withitness which means to have a constant awareness of what is happening in the classroom. Or in other words to have eyes in the back of your head. As a teacher gets to know their students it becomes easier to predict their actions and to make adjustments beforehand. This can greatly reduce behavioral problems.

Non-Verbal Cues

Talk is cheap, especially with students. Non-verbal cues save the voice while getting students to do things. Every teacher should have several non-verbal commands that they use in their classroom. Examples may include ways to get the classes attention, to grant permission to go to the bathroom, to give permission get out of one’s seat, etc.

Most classes have a rule for students to raise their hand. However, non-verbal cues should not stop there. The more non-verbal cues the less talking. In addition, non-verbal cues reduce arguing because there were no words exchanged.

Conclusion

Behavior is a challenge but there are ways to overcome at least some of it. Teachers need to consider and employ ways to anticipate and deal with behavioral problems preferably before they become big problems.

Homeschooling Multiple Children

Homeschooling one child is challenging enough. Now imagine trying to teach more than one or even several. There are things that become more complex but also more efficient with the addition of each new member to the homeschooling context.

It Gets Easier Each Time

When you begin to teach the second child it is surprisingly easier. You have learned from the mistakes made teaching the first child and are familiar with the curriculum. The content is probably fresh in your mind and you’re no longer trying to remember how to do all of these basic skills that are now automatic for you such as reading and counting. You also have learned shortcuts and other tricks that make your teaching more efficient.

The second child has also probably watched you teach the first one. When this happens they learn a lot of the content almost through osmosis. I have seen three years playing with how to write when the older sibling could barely write at five years of age. Just watching the older sibling sped up the development of the younger one.

The second child is also more likely to be eager to learn from watching the older child be in school as well since there is a culture of learning in the house now. They can’t wait for their turn to learn and this also makes things easier. Combine this with an experience parent and adding an additional student is not as burdensome as it seems.

Working Together

To be efficient and not stressed out many families teach non-core subjects (history, science, art, PE, etc.) to all children at the same time. The reason for this is that often in non-core subject the order the content is learned is not as important or linear. For example, in science, if a second grader learns about the weather before learning about plants it probably will not cause too much damage in their development if any at all.

Core-subject (reading, math) are taught separately because the difference in skill in the subjects can be extensive and there is a clear linear development in these subjects. The exception to this would be to have the older sibling serve as a teacher or tutor for the younger one. This really helps everyone involve in developing a better understanding and reduces the stress on the parent.

Independence of the Senior Student

With the addition of the second child to the homeschool, this calls on the oldest to become more independent. There is less one-on-one time to support them with the time that is no given to other children. Therefore, the older child will have to sometimes figure things out on their own. The benefit of this is the development of autonomy which is a hard to find skill in this world.

Instead of watching everything they do the parent is now more of a monitor who drops by to check progress rather than watch every academic move. This places some of the burden of learning on the child which is good for developing a sense of responsibility.

Conclusion

With a combination of experience, efficiency, and the help of older children, homeschooling multiple children is highly doable. The key is to get everyone working together to achieve the educational goals of the family.

Supporting ESL Student’s Writing

ESL students usually need to learn to write in the second language. This is especially true for those who have academic goals. Learning to write is difficult even in one’s mother tongue let alone in a second language.

In this post, we will look at several practical ways to help students to learn to write in their L2. Below are some useful strategies

  • Build on what they know
  • Encourage coherency in writing
  • Encourage collaboration
  • Support Consistency

Build on Prior Knowledge

It is easier for most students to write about what they know rather than what they do not know.  As such, as a teacher, it is better to have students write about a familiar topic. This reduces the cognitive load on the students allows them to focus more on their language issues.

In addition, building on prior knowledge is consistent with constructivism. Therefore, students are deepening their learning through using writing to express ideas and opinions.

Support Coherency 

Coherency has to do with whether the paragraph makes sense or not. In order to support this, the teacher needs to guide the students in developing main ideas and supporting details and illustrate how these concepts work together at the paragraph level. For more complex writing this involves how various paragraphs work together to support a thesis or purpose statement.

Students struggle tremendously with these big-picture ideas. This in part due to the average student’s obsession with grammar. Grammar is critical after the student has ideas to share clearer and never before that.

Encourage Collaboration

Students should work together to improve their writing. This can involve peer editing and or brainstorming activities. These forms of collaboration give students different perspectives on their writing beyond just depending on the teacher.

Collaboration is also consistent with cooperative learning. In today’s marketplace, few people are granted the privilege of working exclusively alone on anything.  In addition, working together can help the students to develop their English speaking communication skills.

Consistency

Writing needs to be scheduled and happen frequently in order to see progress at the ESL level. This is different from a native speaking context in which the students may have several large papers that they work on alone. In the ESL classroom, the students should write smaller and more frequent papers to provide more feedback and scaffolding.

Small incremental growth should be the primary goal for ESL students. This should be combined with support from the teacher through a consistent commitment to writing.

Conclusion

Writing is a major component of academic life. Many ESL students learning a second language to pursue academic goals. Therefore, it is important that teachers have ideas on how they can support ESL student to achieve the fluency they desire in their writing for further academic success.

Videoconferencing in Online Course

Videoconferencing is a standard aspect of the professional world. Most large companies have some sort of video conferencing happening in terms of meetings and training. In terms of personal life, video conferencing is common as well. We probably have all used skype or google hangout at one time or another to talk with friends. However, video conferencing is not as common in education.

Video Conferencing Before Video Conferencing

Before video conferencing became common, many educators would upload videos to their online course or post them on youtube. This allowed the student to see the teacher and have more of a traditional classroom experience but real-time interaction was impossible. Instead, the interaction was asynchronous meaning not at the same time. As such communication was jilted at the least because of the lag time between interactions.

Things to Consider Before Video Conferencing

In order to have success with video conferencing you will need some sort of application that allows this. There are many different applications to choose from such as skype, google hangouts, and even Facebook. However, you want some sort of software that allows you to show your screen as well as control the flow of the conversation.

One app that allows this is called Zoom. This software allows you to schedule meetings. In addition, students do not need to download anything. Instead, the students are sent a web link that takes them to the online meeting. You can share your screen as well as monitor the discussion with the added benefit of being able to record the meeting for future use.

Pros and Cons of Video Conferencing

For whatever reason, video conferencing is engaging for students. The same discussion in class would lull them to sleep but through webcams, everyone is awake and stimulated. I am not sure what the difference is but this has been my experience

The biggest enemy to video conferencing is scheduling. This is particularly true if students are spread out all over the world. The challenges of time zones and other commitments make this hard.

This is one reason that recording a video conference is so important. It allows students who are not available to at least have an asynchronous learning experience. It also serves as a resource for students who need to see something again. Keep in mind you have to post the video either on your LMS or on youtube so that students have access to it.

Conclusion

Video conferencing provides a familiar learning experience in a different setting. It is able to give students who are not physically present an opportunity to interact with the instructor in meaningful ways. As such, the instructor must be aware of possibilities in how to use this tool in their online teaching.

Maintaining Student Focus During E-Learniing

Self-motivation is perhaps one of the biggest problems in e-learning. Students who are left to themselves to complete learning experience often just do not successfully finish the learning experiences prepared by the teacher. For whatever reason, often the internal drive to finish something such as an online class is missing for many people.

There are several strategies that an online teacher can use in order to help students who may struggle with self-motivation in an online context. These ideas include…

  • Brief Lessons
  • Frequency Assessment
  • Collaboration

Brief Lessons

Nothing is more discouraging to many students than having to read several pages of text or even several hours of video to complete a single lesson or module in an online course. Therefore, the teacher needs to make sure lessons are short. Completing many small lessons is much more motivating for many students than completing a handful of really large lessons. This is because frequent completion of small lessons is rewarding and indicates progress which the brain rewards.

How long a lesson should depend on many factors such as the age and expertise of the students. Therefore, it is difficult to give a single magic number to aim for. You want to avoid the extreme of lessons too short and lessons to long.

IN my own experience most people make their lessons too long so the majority of us probably need to reduce the content in an individual lesson and spread it over many lessons. All the content can be there it is just chunked differently so that students experience progress.

Frequency Assessment

Along with brief lessons should be frequent assessment. Nothing motivates like knowing something is going to be on the quiz or there is some sort of immediate application. Students need to do something with what they are learning in order to stay engaged. Therefore, constant assessment is not only for grades but also for learning. Besides the stress of a small quiz provides an emotional stimulus that many students need

The assessment also allows for feedback which helps the student to monitor their learning. In addition, the feedback provides more evidence of progress being made in a course which is itself motivating for many.

Collaboration

Nothing motivates the same as working together. Many people love to work in groups and get energy from this. In addition, it’s harder to quit and give a course when you have group members waiting for your contribution. In addition, interacting with students deepens understanding of the course material.

Communicating with other students online to complete assignments is one way of establishing community in an online class. It is similar to traditional classroom where everyone has to discuss and work together to have success.

Conclusion

Motivated students are successful students. IN order for this to happen in an elearning class studnets need to be engaged through brief lessons that inckude frequent assessment tjat includes social interaction.

Tips for Online Studying

Today it is common for students to study online. This has both pros and cons to it. Although e-learning allows students to study anytime and anywhere it also can lead to a sense of disconnection and frustration. This post will provide some suggestions for how to study online successfully.

Make a Schedule

In a traditional classroom, there is a fixed time to come to class. This regulated discipline helps many students to reach a minimum standard of knowledge even if they never study on their own. In e-learning, the student can study whenever they want. Sadly, many choose to never study which leads to academic failure.

Success in online studying requires a disciplined schedule in which the student determines when they will study as well as what they will do during the study time. As such, you will need to set-up some sort of a calendar and to do list that guides you through the learning experience.

It is also important to pace your studying. With flexible courses sometimes the assignments are due at the end of the course. This temptation leads to students who will do all their studying at the last minute. This robs the student of in-depth learning as well as the ability to complete assignment thoroughly. Learning happens best over time and not at the last minute,

Participate

In a traditional class, there are often opportunities to participate in class discussions or question and answer sessions. Such opportunities provide students with a chance to develop a deeper understanding of the ideas and content of the course. Students who actually participate in such two-way dialog usually understand the material of the course better than students who do not.

For the online student participation is also important and can render the same benefits. Participating in forums and chats will deepen understanding. However, I must admit that with the text-heavy nature of online forums reading the comments of peers can in many ways boost understanding without participation. This is because you can read other’s ideas at your own speed which helps with comprehension. This is not possible during an in-class discussion when people may move faster than you can handle.

Communicate with the Instructor

When a student is confused they need to speak up. For some reason, students are often shy to contact the instructor in an online course. However, the teacher is there to help you and expects questions and feedback. As such, reach to them.

Communicating with the instructor also helps to establish a sense of community which is important in online learning. It helps the instructor to establish presence and demonstrates that they are here to help you to succeed.

Conclusion

E-learning is a major component of the future of learning. Therefore, students need to be familiar with what they need to do in order to be successful in their online studies.

Tips for Teaching Online

Teaching online is a unique experience due in part to the platform of instruction. Often, there is no face to face interaction and all communication is in some sort of digital format. Although this can be a rewarding experience there are still several things to consider when teaching in this format. Some tips for successful online teaching include the following.

  • Planning in advance
  • Having a presence
  • Knowing your technology
  • Being consistent

Plan in Advance

All teaching involves advance planning. However, there are those teaching moments in a regular classroom where a teacher can change midstream to hit a particular interest in the class. In addition, more experienced teachers tend to plan less as they are so comfortable with the content and have an intuitive sense of how to support students.

In online teaching, the entire course should be planned and laid out accordingly before the course starts. It is a nightmare to try and develop course material while trying to teach online. This is partially due to the fact that there are so many reminders and due dates sprinkled throughout the course that are inflexible. This means a teacher must know the end from the beginning in terms of what the curriculum covers and what assignments are coming. Changing midstream is really tough.

In addition, the asynchronous nature of online teaching means that instructional material must be thoroughly clear or students will be lost. This again places an emphasis on strong preparation. Online teaching isn’t really for the person who likes to live in the moment but rather for the person who plans ahead.

Have Presence

Having presence means making clear that you are monitoring progress and communicating with students frequently. When students complete assignments they should receive feedback. There should be announcements made in terms of assignments due, general feedback about activities, as well as Q&A with students.

Many people think that teaching online takes less time and can have larger classes. This is far from the case. Online teaching is as time intensive as regular teaching because you must provide feedback and communication or the students will often feel abandon.

Know Your Technology

An online teacher must be familiar and a proponent of technology. This does not mean that you know everything but rather you know how to get stuff done. You don’t need a master in web design but knowing the basics of HTML can really help when communicating with the IT people.

Whatever learning management system you use should actually be familiar with it and not just a consumer. Too many people just upload text for students to read and provide several forums and call that online learning. In many ways, that’s online boredom, especially for younger students.

Consistency

Consistency is about the user experience. The different modules in the course should have the same format with different activities. This way, students focus on learning and not trying to figure out what you want them to do. This applies across classes as well. There needs to be some sense of stability in terms of how content is delivered. There is no single best way but it needs to similar within and across courses for the sake of learning.

Conclusion

These are just some of many ideas to consider when teaching an online course. The main point is the need for preparation and dedication when teaching online.

Blended Learning Defined

E-Learning is commonly used tool at most educational institutions. Often, the e-learning platform is fully online or a traditional model of face-to-face instruction is used. Blended learning is something that is available but not as clear in terms of what to do.

In this post, we will look at what  blended learning is and  what it is not

What Blended Learning is

Blended learning is an instructional environment in which online learning and traditional face-to-face instruction coexist and are employed in a course. There are at least six common models of blended learning.

  • Face-to-face driver – Traditional instruction is supported by online materials
  • Online driver –The entire course is completed online with teacher support made available
  • Rotation – A course in which students cycle back and forth between online and traditional instruction
  • Labs – Content is delivered online but in a specific location such as a computer lab on-campus
  • Flex – Most of the curriculum is delivered is online and the teacher is available for face-to-face consultation.
  • Self-blend – Students choose to augment their traditional learning experience with online coursework.

These models mentioned above can be used in combination with each other and are not mutually exclusive.

For a course to be blended, it is probably necessary for at least some sort of learning to happen online. The challenge is in defining learning. For example, the Moodle platform places an emphasis on constructivism. As such, there are a lot of opportunities for collaboration in the use of the modules available in Moodle. Through discussion and interaction with other students through forums, commenting on videos, etc., students are able to demonstrate learning.

For a more individualistic experience, if the course is blended the students need to do something online. For example, completing a quiz, add material to a wiki or database, etc. are all ways to show that learning is taking place without as much collaboration. However, a teacher chooses to incorporate blended learning the students need to do something online for it to truly be blended.

What Blended Learning is not

Many teachers will post there powerpoints online and have students submit assignments online and call this blended learning. While it is commendable that online tools are being used this is not really blended learning because there is no learning taking place anytime online. Rather this is an excellent example of using cloud sources to upload and download materials.

The powerpoints were seen in class and are available for review.  Uploading assignments are trickier to classify as online learning or not but if it required the students to complete a traditional assignment and simply upload it then there was no real online learning experience. The students neither collaborated nor completed anything online in order to complete this learning experience.

Conclusion

The definition here is not exhaustive. The purpose was to provide a flexible framework in which blended learning is possible. To make it as simple as possible, blended learning is the students actively learning online and actively learning in a traditional format. How much of each component depends on the approach of the teacher.

Benefits of Writing

There are many reasons that a person or student should learn to master the craft of writing in some form or genre. Of course, the average person knows how to write if they have a k-12 education but here it is meant excelling at writing beyond introductory basics. As such, in this post, we will look at the following benefits of learning to write

  • Makes you a better reader and listener
  • Enhances communication skills
  • Develops thinking skills

Improved Reading and Listening Skills

There seems to be an interesting feedback loop between reading and writing. Avid readers are often good writers and avid writers are often good readers. Reading allows you to observe how others write and communicate. This, in turn, can inspire your own writing. It’s similar to how children copy the behavior of the people around them. When you write it is natural to bring with you the styles you have experienced through reading.

Writing also improves listening skills, however, this happens through the process of listening to others through reading. By reading we have to assess and evaluate the arguments of the author. This can only happen through listening to the author through reading his work.

Communication Skills

Writing, regardless of genre, involves finding an audience and sharing your own ideas in a way that is clear to them. As such, writing natural enhances communication skills This is because of the need to identify the purpose or reason you are writing as well as how you will share your message.

When writing is unclear it is often because the writer has targeted the wrong audience or has an unclear purpose for writing. A common reason research articles are rejected is that the editor is convinced that the article is not appropriate for the journal’s audience. Therefore, it is critical that an author knows there audience.

Thinking Skills 

In relation to communication skills is thinking skills. Writing involves taking information in one medium, the thoughts in your head, and placing them in another medium, words on paper. Whenever content moves from one medium to another there is a loss in meaning. This is why for many people, there writing makes sense to them but to no one else.

Therefore, a great deal of thought must be placed into writing with clarity. You have to structure the thesis/purpose statement, main ideas, and supporting details. Not to mention that you will often need references and need to adhere to some form of formatting. All this must be juggled while delivering content that critically stimulating.

Conclusion 

Writing is a vehicle of communication that is not used as much as it used to be. There are so many other forms of communication and interaction that something writing is obsolete. However, though the communication may change, the benefits of writing are still available.

Local Regression in R

Local regression uses something similar to nearest neighbor classification to generate a regression line. In local regression, nearby observations are used to fit the line rather than all observations. It is necessary to indicate the percentage of the observations you want R to use for fitting the local line. The name for this hyperparameter is the span. The higher the span the smoother the line becomes.

Local regression is great one there are only a handful of independent variables in the model. When the total number of variables becomes too numerous the model will struggle. As such, we will only fit a bivariate model. This will allow us to process the model and to visualize it.

In this post, we will use the “Clothing” dataset from the “Ecdat” package and we will examine innovation (inv2) relationship with total sales (tsales). Below is some initial code.

library(Ecdat)
data(Clothing)
str(Clothing)
## 'data.frame':    400 obs. of  13 variables:
##  $ tsales : int  750000 1926395 1250000 694227 750000 400000 1300000 495340 1200000 495340 ...
##  $ sales  : num  4412 4281 4167 2670 15000 ...
##  $ margin : num  41 39 40 40 44 41 39 28 41 37 ...
##  $ nown   : num  1 2 1 1 2 ...
##  $ nfull  : num  1 2 2 1 1.96 ...
##  $ npart  : num  1 3 2.22 1.28 1.28 ...
##  $ naux   : num  1.54 1.54 1.41 1.37 1.37 ...
##  $ hoursw : int  76 192 114 100 104 72 161 80 158 87 ...
##  $ hourspw: num  16.8 22.5 17.2 21.5 15.7 ...
##  $ inv1   : num  17167 17167 292857 22207 22207 ...
##  $ inv2   : num  27177 27177 71571 15000 10000 ...
##  $ ssize  : int  170 450 300 260 50 90 400 100 450 75 ...
##  $ start  : num  41 39 40 40 44 41 39 28 41 37 ...

There is no data preparation in this example. The first thing we will do is fit two different models that have different values for the span hyperparameter. “fit” will have a span of .41 which means it will use 41% of the nearest examples. “fit2” will use .82. Below is the code.

fit<-loess(tsales~inv2,span = .41,data = Clothing)
fit2<-loess(tsales~inv2,span = .82,data = Clothing)

In the code above, we used the “loess” function to fit the model. The “span” argument was set to .41 and .82.

We now need to prepare for the visualization. We begin by using the “range” function to find the distance from the lowest to the highest value. Then use the “seq” function to create a grid. Below is the code.

inv2lims<-range(Clothing$inv2)
inv2.grid<-seq(from=inv2lims[1],to=inv2lims[2])

The information in the code above is for setting our x-axis in the plot. We are now ready to fit our model. We will fit the models and draw each regression line.

plot(Clothing$inv2,Clothing$tsales,xlim=inv2lims)
lines(inv2.grid,predict(fit,data.frame(inv2=inv2.grid)),col='blue',lwd=3)
lines(inv2.grid,predict(fit2,data.frame(inv2=inv2.grid)),col='red',lwd=3)

1

Not much difference in the two models. For our final task, we will predict with our “fit” model using all possible values of “inv2” and also fit the confidence interval lines.

pred<-predict(fit,newdata=inv2.grid,se=T)
plot(Clothing$inv2,Clothing$tsales)
lines(inv2.grid,pred$fit,col='red',lwd=3)
lines(inv2.grid,pred$fit+2*pred$se.fit,lty="dashed",lwd=2,col='blue')
lines(inv2.grid,pred$fit-2*pred$se.fit,lty="dashed",lwd=2,col='blue')

1

Conclusion

Local regression provides another way to model complex non-linear relationships in low dimensions. The example here provides just the basics of how this is done is much more complicated than described here.

Smoothing Splines in R

This post will provide information on smoothing splines. Smoothing splines are used in regression when we want to reduce the residual sum of squares by adding more flexibility to the regression line without allowing too much overfitting.

In order to do this, we must tune the parameter called the smoothing spline. The smoothing spline is essentially a natural cubic spline with a knot at every unique value of x in the model. Having this many knots can lead to severe overfitting. This is corrected for by controlling the degrees of freedom through the parameter called lambda. You can manually set this value or select it through cross-validation.

We will now look at an example of the use of smoothing splines with the “Clothing” dataset from the “Ecdat” package. We want to predict “tsales” based on the use of innovation in the stores. Below is some initial code.

library(Ecdat)
data(Clothing)
str(Clothing)
## 'data.frame':    400 obs. of  13 variables:
##  $ tsales : int  750000 1926395 1250000 694227 750000 400000 1300000 495340 1200000 495340 ...
##  $ sales  : num  4412 4281 4167 2670 15000 ...
##  $ margin : num  41 39 40 40 44 41 39 28 41 37 ...
##  $ nown   : num  1 2 1 1 2 ...
##  $ nfull  : num  1 2 2 1 1.96 ...
##  $ npart  : num  1 3 2.22 1.28 1.28 ...
##  $ naux   : num  1.54 1.54 1.41 1.37 1.37 ...
##  $ hoursw : int  76 192 114 100 104 72 161 80 158 87 ...
##  $ hourspw: num  16.8 22.5 17.2 21.5 15.7 ...
##  $ inv1   : num  17167 17167 292857 22207 22207 ...
##  $ inv2   : num  27177 27177 71571 15000 10000 ...
##  $ ssize  : int  170 450 300 260 50 90 400 100 450 75 ...
##  $ start  : num  41 39 40 40 44 41 39 28 41 37 ...

We are going to create three models. Model one will have 70 degrees of freedom, model two will have 7, and model three will have the number of degrees of freedom are determined through cross-validation. Below is the code.

fit1<-smooth.spline(Clothing$inv2,Clothing$tsales,df=57)
fit2<-smooth.spline(Clothing$inv2,Clothing$tsales,df=7)
fit3<-smooth.spline(Clothing$inv2,Clothing$tsales,cv=T)
## Warning in smooth.spline(Clothing$inv2, Clothing$tsales, cv = T): cross-
## validation with non-unique 'x' values seems doubtful
(data.frame(fit1$df,fit2$df,fit3$df))
##   fit1.df  fit2.df  fit3.df
## 1      57 7.000957 2.791762

In the code above we used the “smooth.spline” function which comes with base r.Notice that we did not use the same coding syntax as the “lm” function calls for. The code above also indicates the degrees of freedom for each model.  You can see that for “fit3” the cross-validation determine that 2.79 was the most appropriate degrees of freedom. In addition, if you type in the following code.

sapply(data.frame(fit1$x,fit2$x,fit3$x),length)
## fit1.x fit2.x fit3.x 
##     73     73     73

You will see that there are only 73 data points in each model. The “Clothing” dataset has 400 examples in it. The reason for this reduction is that the “smooth.spline” function only takes unique values from the original dataset. As such, though there are 400 examples in the dataset only 73 of them are unique.

Next, we plot our data and add regression lines

plot(Clothing$inv2,Clothing$tsales)
lines(fit1,col='red',lwd=3)
lines(fit2,col='green',lwd=3)
lines(fit3,col='blue',lwd=3)
legend('topright',lty=1,col=c('red','green','blue'),c("df = 57",'df=7','df=CV 2.8'))

1.png

You can see that as the degrees of freedom increase so does the flexibility in the line. The advantage of smoothing splines is to have a more flexible way to assess the characteristics of a dataset.

Polynomial Spline Regression in R

Normally, when least squares regression is used, you fit one line to the model. However, sometimes you may want enough flexibility that you fit different lines over different regions of your independent variable. This process of fitting different lines over different regions of X is known as Regression Splines.

How this works is that there are different coefficient values based on the regions of X. As the researcher, you can set the cutoff points for each region. The cutoff point is called a “knot.” The more knots you use the more flexible the model becomes because there are fewer data points with each range allowing for more variability.

We will now go through an example of polynomial regression splines. Remeber that polynomial means that we will have a curved line as we are using higher order polynomials. Our goal will be to predict total sales based on the amount of innovation a store employs. We will use the “Ecdat” package and the “Clothing” dataset. In addition, we will need the “splines” package. The code is as follows.

library(splines);library(Ecdat)
data(Clothing)

We will now fit our model. We must indicate the number and placement of the knots. This is commonly down at the 25th 50th and 75th percentile. Below is the code

fit<-lm(tsales~bs(inv2,knots = c(12000,60000,150000)),data = Clothing)

In the code above we used the traditional “lm” function to set the model. However, we also used the “bs” function which allows us to create our spline regression model. The argument “knots” was set to have three different values. Lastly, the dataset was indicated.

Remember that the default spline model in R is a third-degree polynomial. This is because it is hard for the eye to detect the discontinuity at the knots.

We now need X values that we can use for prediction purposes. In the code below we first find the range of the “inv2” variable. We then create a grid that includes all the possible values of “inv2” in increments of 1. Lastly, we use the “predict” function to develop the prediction model. We set the “se” argument to true as we will need this information. The code is below.

inv2lims<-range(Clothing$inv2)
inv2.grid<-seq(from=inv2lims[1],to=inv2lims[2])
pred<-predict(fit,newdata=list(inv2=inv2.grid),se=T)

We are now ready to plot our model. The code below graphs the model and includes the regression line (red), confidence interval (green), as well as the location of each knot (blue)

plot(Clothing$inv2,Clothing$tsales,main="Regression Spline Plot")
lines(inv2.grid,pred$fit,col='red',lwd=3)
lines(inv2.grid,pred$fit+2*pred$se.fit,lty="dashed",lwd=2,col='green')
lines(inv2.grid,pred$fit-2*pred$se.fit,lty="dashed",lwd=2,col='green')
segments(12000,0,x1=12000,y1=5000000,col='blue' )
segments(60000,0,x1=60000,y1=5000000,col='blue' )
segments(150000,0,x1=150000,y1=5000000,col='blue' )

1.png

When this model was created it was essentially three models connected. Model on goes from the first blue line to the second. Model 2 goes form the second blue line to the third and model three was from the third blue line until the end. This kind of flexibility is valuable in understanding  nonlinear relationship