the Air Vent

Because the world needs another opinion

Another Use for R

Posted by Jeff Id on July 2, 2014

So how about something different.   I learned R programming here for climate software.   Plotting, fitting curves, calculating stats and all kinds of linear algebra.   Prior to that I had programmed in various forms of C, Basic, a few other arcane languages, assembly/machine, etc…  I had written my own matrix multipliers and inverters multiple times. It was all low level engineering style languages for equipment integration, calculation and a literal ton of other applications.   R turns out to be very flexible for most of what I had done in other languages, and could have handled a large portion of the problems with a much reduced development time.

Over the past couple of years, I’ve expanded my use of R to some unique applications.   I have used the R algorithms to calculate some fairly sophisticated lenses, but interestingly have adopted the software to perform material requirement planning to a level difficult to find in commercial software.   The ability to work with large matrices makes R well suited to the task.   Lean manufacturing requires just in time delivery of components.  Inventory is a significant cost to a company and is paid for in after-tax dollars so it must be controlled to a high degree for a company to succeed.    In a mid-sized company as ours has become, we have over two thousand part numbers which turn into about 600 finished goods of various types.   In our business case, these finished goods need to be stocked at appropriate levels to service our customers within a fixed range of part numbers.

So what we have is:

Forecast usage based on history and customer provided expectations

Target inventory levels for components

Manufacturing time for various processes

Shipment time for components

From those basic numbers and a variety of other information including bills of material (list of subcomponents in an assembly), lead times and manufacturing location, we use R software to calculate our manufacturing schedule, component ordering, required delivery dates and note any problems in the delivery time.  Just in case you think this might be simple, our supply chain is quite long, sometimes as much as 13 weeks with various steps happening at planned points along the process.

A common example for us is where electronic components are ordered in the US, shipped overseas in 1 week, 1 week allowed for assembly to circuit boards, ship back to US by air 1 week, final assembly in us 1 week.  In the meantime, other components for the same finished product, might be built to arrive at the same time as the circuit boards from another facility with a longer 3 week production time and those might be intended to ship by sea over 5 weeks to arrive simultaneously with the stock requirement of the circuit boards such that a production build happens on the correct date.   Now even that isn’t terribly complicated but we utilize the same components in multiple part numbers. Each one forecast and stocked on independent schedules such that economic quantities of components must be delivered in time for the first of what sometimes is multiple builds.  Expand that problem over two thousand active part numbers and that is our situation.

The software calculates its recommended orders and writes a huge 20,000 plus line file into excel, highlighting orders to be placed and even writes live equations into the cells such that if the buyer decides that the order needs to be altered, projected inventory is recalculated on the fly.   Warning symbols are also generated by live equations in excel such that inventory overstock or under stock situations are highlighted.

It’s pretty interesting to me and a commercial version, which we have purchased but not yet implemented, is surprisingly expensive.   While many people will tell you that their software can handle it, there are only a few on the market which perform these calculations to the level that our company has been able to implement and operate with for two years now.

And it was done in R.

The ability to program and plan like this gives us the ability to take our projected stock level as a matrix, multiplied by a vector of the true component costs to achieve our projected inventory value for the next 3.5 months with two lines like this:

totalinventorycost =  sweep(projectedinventory,2,cost,”*”)


Slide that information into your cash flow planning and you have closed the loop between future inventory levels and expected cash needs for the next 3 months.

We have R software that calculates sales commissions for outside reps, checks delivery status and manufacturing status, recommends orders, designs lenses, calculates component usage, and a few tax related routines as well.   In addition to that, I use it for all kinds of math driven electrical and mechanical engineering related tasks.

I’m pretty certain that the creators of R didn’t expect their statistical software to be abused in such a capitalistic manner.  However, I do consider it a positive impact of the climate change nonsense the boys at Real Climate exposed all of us to.   I also must give credit to Mr. McIntyre as it was his continued promotion of the language that got me started down this path.









10 Responses to “Another Use for R”

  1. Jeff Id said

    It’s a climate blog jeff!

    • Gary said

      Air Vents supply both warm and cool air. This one is definitely cool.

      How much programming effort went into all these business applications?

      • Jeff Id said

        Thanks Gary. I don’t really know how long all of it took. The material planning came together in a weekend but it took a few more sessions to fully debug it. It was definitely more complex than it sounds and it is pretty neat to see the planning it creates.

  2. j ferguson said

    It’s good to see this, especially for some of us who were worried during your family and day job during your periods of prolific posting. I would be delighted to read whatever you may be comfortable sharing about how you run your company. For example, to what degree does your market leverage depend on design innovation? On a particular product how long does the edge last? How price sensitive are your customers? Do they have other sources? Always? What part of your output is designed to customer spec? Are some products designed in close development with customers’ engineering?

    How often do you look at each manufacturing process for outsourcing or bringing home? Is any significant part of your production captive in the sense of one product or family of products for a single customer?

    I suppose most of this is proprietary, or ought to be, but it would be interesting to read your observations on some of this. I’d also be nice to see if anyone else wants to read these things.

    I ask because a guy i met while we were changing oil in our small planes 40 years ago at PWK has grown a niche manufacturing business in Wheeling into a very large operation which dominates his industry. I believe his edge is proprietary manufacturing processes, very quick turn-around in quantity of customer specced product, mostly in-house production from basic materials (wouldn’t work with products requiring assembly), design innovation – development of sister products which can be made on same machinery, And there are other things which make it difficult for someone new to his niche to compete. So far no-one else has really ever gotten a foothold on his shore, including the far east.

    A lot of this is a result of 40 years of constant worrying about what can be done differently, what can be improved, what they shouldn’t do (especially this), and care of their customers, not just the biggest ones, but ALL of them.

    I suppose a lot of this is obvious, but it was one of the great pleasures of being an industrial architect. I could eat lunch with our customers’ engineers and enjoy discussing the problems they faced and where they thought they were going.

    Sorry to belabor this, but you’ve offered some insights I, for one would love to see, expanded.

    best luck with it all, john

    • Jeff Id said


      I do need to be careful how much I write. We are definitely innovation heavy and rely on unique technologies to give us an advantage. The LED world is a bit like computers were in that it changes rapidly with improvements in the base technology. We have custom captive products as well as a standard product line so that depends on the customer. In general, we take a very service-oriented approach to business where the customer needs come first.

      You might find it interesting that I believe very strongly in the development of fairly rigid processes for every part of the supply chain, how SO’s are entered, product receipt, manufacturing, shipment, invoicing. Every step is documented and repeated in the most similar manner possible. It is founded on a very idealistic approach to business where every process is broken down until everything is processed in the same way. Any material receipt RGA, PO or in the case of a sales order, even when there are different types of payments, is processed with all of the same steps. The goal is to have the entire company run in almost computer like fashion. No guessing, just follow the process.

      The reason for it all is because a growing company will explode into chaos quite easily when people are all trying to help each other out to get the job done. The situation is the opposite of what many people think but you may already know, employees default to giving themselves more work in general such that managers in our company are consistently refocusing people on their own jobs. If you don’t do that, people naturally want to help others and each time they see a problem, they will step in. It actually leads to lack of trust but worse than that it leads to huge inefficiencies that prevent rather than promote growth.

      When you grow 50% every year, the challenge is just to keep people following the basic process. An even bigger challenge is keeping the process from growing bigger with extra steps, as it is quite standard in my experience. e.g. –Oops, you missed that line in the PO so lets just put check marks next to every one and initial the bottom so we can make sure it doesn’t go wrong again. Or maybe we should staple the invoice to the PO which requires a second filing step. All of a sudden you find yourself paying for the writing of many thousands of check marks every week or 3 hours of filing for potentially dubious reasons.

      It does keep us busy.

      • j ferguson said

        Thanks much for sharing your thoughts. Amazing things can happen in larger organizations. One of the most astonishing was a many-paged form which Xerox required tour small computer system house to complete to resell their scanner/ocr system which used Kurzweil learning algorithms. We came to a page which required that our business address be filled in twice- that is twice on the very same page. I couldn’t see any way the addresses could ever be different – for anyone – so i called Xerox’s sales office in Boston and eventually found the author of this requirement.

        “Those addresses are for two different departments.”

        Had this person worked for me – unlikely – he would have been gone within seconds of the above conversation. I hope you will avoid having an HR department and be able to quickly, and fairly, prune your staff as the provocation warrants.

        again, highest regards,


      • j ferguson said

        I’ve been puzzling over this:

        The reason for it all is because a growing company will explode into chaos quite easily when people are all trying to help each other out to get the job done. The situation is the opposite of what many people think but you may already know, employees default to giving themselves more work in general such that managers in our company are consistently refocusing people on their own jobs. If you don’t do that, people naturally want to help others and each time they see a problem, they will step in. It actually leads to lack of trust but worse than that it leads to huge inefficiencies that prevent rather than promote growth.

        I cannot remember a company culture (where I worked) with quite the characteristics you describe. It seems wonderful that people pitch in to get the thing done regardless of their role, or the expected method. The risk is obvious as well as the need for discipline, especially as the culture in your place is evolving. It will be harder to influence when your company grows beyond a few hundred employees. Is there any chance that you have over-hired in the sense that you have people more capable than their jobs require?

        You don’t need and probably shouldn’t want everyone to be management material. Rewarding innovation can have its risks.

        I apologize for relating another story, but it’s to the point, true, and I hope to God doesn’t slander any of your readers.

        I worked in an outfit which did experimental psychology in the mid-’60s. Two of my fellows had done this sort of work for a defense contractor. The Navy had come to them for a solution to losses of Shore Patrol personnel in Japan. The losses occurred when two SPs were sent to retrieve an AWOL sailor. Typically, the sailor was shacked up with a local. The recommended method was for one SP to knock on the door. If a non-Japanese male likely to be a sailor answered the door, he was to be immediately subdued with a billy club and hauled to the brig. This was what was supposed to happen.

        Too often for the comfort of the service, the AWOL guy was attacking the SP or even killing them. It appeared that instead of immediately subduing him as per the protocol, the SPs were trying to reason with him, probably out of sympathy. No amount of “training” was effective in reducing this problem.

        The solution turned out to be picking candidates from the bottom of the test score pile. Less intelligent, less imaginative types tended to follow the protocol. Once the SP constituency for these errands was so adjusted, the problem was much diminished.

        Facetiously, you could always unionize.

        A reader named Bernie1815 used to comment here. I think he might have other insights into the problem of getting people to follow protocols reliably.

  3. j ferguson said

    sorry, I see some excursions from accepted English above, “worried about your family” not “worried during your family” and fewer commas, for sure.

  4. Kenneth Fritsch said

    JeffID, I wholeheartedly agree with you on the applications of R. I did little programming in my work career but was spurred on to learn R from Steve McIntrye’s initiatives and examples using R- as it appears you were. RomanM helped me in my early use of R with a couple email exchanges and probably a lot more than he realizes. He made a statement to the effect that R learning becomes easier the more you use it and learn about it. That has been very true and to the point now where I have good confidence of finding R functions and being able to code together useful programs. R has also helped me visualize some statistical concepts. I am currently learning Bayesian statistical inference/analysis using R in conjunction with BUGS.

    I had a career dealing with large manufacturing companies, but always thought I might be better suited in a smaller operation in an ownership position but never made the jump. Even as I went up the management ladder I always had superiors that allowed me reasonably free reign on how I operated and I often stayed close to the engineering and development of products and processes.

    Interesting what you say about workers wanting (too much) to help others. I found in a large company that a there was a major resistance of personnel at the engineering and engineering management levels to work or at least have a good knowledge of areas outside their smaller groups and departments. I always jumped at the opportunity to try something new in the way of taking on different responsibilities. It kept things interesting and was great learning experience.

  5. I have a colleague and the boss of one of our divisions starting off on R as of yesterday. Mainly little biostatistics stuff, but still.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: