Bing Maps API for driving distance in R

Adding to my earlier post about finding a workaround for errors encountered while using the Bing Maps API option of the georoute function in the taRifx.geo package:

In specific, this error is what I attribute to the package no longer being updated:

BingFail

ERROR: “Bing Maps API return status code 404 – Not Found”.

This code is hopefully self-explanatory. Make sure to insert your Bing key for the bingkey value after acquiring it from Microsoft [LINK].

library(tidyverse)
library(geosphere)
library(taRifx.geo)
# North Carolina SNAP-accepting retailers
# downloaded from https://www.fns.usda.gov/snap/retailerlocator
snapNC <- read.csv('SNAP_RetailerLocator_NC.csv')
rowct <- nrow(snapNC)
for (k in 1:rowct){
tryCatch({
outfil_snap <- snapNC %>% slice(k)
from_mat <- t(c(outfil_snap$Latitude, outfil_snap$Longitude))
from_mat_in <- apply(from_mat, 1, paste0, collapse=",")
# same values because each location will be mapped to every other one
to_mat <- from_mat
to_mat_in <- from_mat_in
xmat <- rbind(from_mat, to_mat)

distunit <- 'mi'
bingkey <- 'PLACE_YOUR_KEY_HERE_AS_ACQUIRED_FROM_https://www.bingmapsportal.com/'
starturl <- 'http://dev.virtualearth.net/REST/V1/Routes?wp.0='
fromtourl <- str_c(starturl, from_mat_in, '&wp.1=', to_mat_in, '&distanceUnit=', distunit, '&key=', bingkey)
# do not map same location
if (!identical(from_mat, to_mat)){
u1 <- RCurl::getURL(fromtourl)
u2 <- RJSONIO::fromJSON(u1, simplify=FALSE)
outfil_snap$travelDistance <- u2$resourceSets[[1]]$resources[[1]]$travelDistance

if (k == 1){
outfil_snap_dist <- outfil_snap
} else {
outfil_snap_dist <- rbind(outfil_snap_dist, outfil_snap)
}
}
message(str_c("completed k iteration: ", k))
},
warning = function(w) {
print (str_c('Warning on iteration', k))
}, error = function(e) {
print (str_c('Error on iteration', k))
}
)
}
Bing Maps API for driving distance in R

Marquel Russell review – online coaching

As I continue to consult with a variety of persons and organizations who are either helping me understand my options for recouping at least some of the thousands I gave business and Internet marketing coach, Marquel Russell, or who are already performing their own investigations that will likely not yield any direct reward to me, I simply want to encourage any prospective client of his, or any coach, to:

    1. Read contracts carefully and ask questions. Do not allows yourself to be rushed into an expensive decision. Think about the implications! Ask: Why is this person rushing me to a decision and / or not communicating details? Does this person understand my personality and particular objectives? Does this person seem like someone who will work hard to help me think through complex challenges?

Why does this contract disallow refunds under any circumstances? Why does it have forced arbitration language? Why is a state’s laws presented in the contract that is not my own or the coach’s? How has this coach achieved their purported great success without any reviewer commenting on qualities that some view negatively?

      1. Trust your intuition.
      2. Reach out to clients not featured on the testimonial pages.
      3. First, deeply explore more affordable options for Internet marketing / branding assistance. As I hopefully made clear in my Matrixx review / “Laugh At My Pain” post, cost does not predict quality in the coaching / personal development space. Rick Mulready’s free podcast, “The Art of Paid Traffic“, is an amazing resource that offers the same ideas you might pay thousands to learn from someone else, augmented by Rick and his guests’ novel discoveries. Someone also suggested exploring the materials of “Private Label Rights“, although as we see so often in this industry, there’s obvious deception. Let’s just say what I see on this page looks very familiar but it costs less than $100.
      4. Approach marketing of any kind as a risky endeavor, and so, while success may come, anyone presenting examples of “rapid success” is likely presenting atypical success. Similarly, a “fail proof system” likely has produced unsatisfying results for many.
      5. If a coach says anything about their status, such as being “world-renowned”, research whether this appears to be accurate. For example, Russell Brunson may be the most famous Internet marketing expert, does a possible “world-renowned” digital marketing coach appear online to be anywhere as popular as Mr. Brunson? Compare a coach’s claims about their status and expertise to their online presence versus others in their field. This is a must! For example, Alexa rankings will give you a hint of the popularity of their website.
      6. Review what the Federal Trade Commission has said about business coaching.
      7. Consider that a coach who deceives might encourage you to do the same. I was advised by Marquel to call myself a “world-renowned” relationship expert. This could have put me at legal risk and damaged my personal reputation. I have no qualifications or professional experiences to justify such a descriptor. Sure, I like helping friends with romantic relationship concerns and would love to earn money to do so, but no one has ever paid me or considered my language that of an authority.
      8. Watch for mixed messages. Does the person say online in some places that he / she cannot help you get rick quickly but in other places say he helps clients quickly earn a lot of money? Does the speak to acting ethically and yet your intuition is that ethics are not of high-value to the person?

Contracts I signed with a company of Marquel Russell’s, Global Wealth Firm, have non-disparagement language. My intent here is to communicate lessons learned after (1) my experiences with his company, (2) conferring with a number of clients of his, and (3) researching the “turn your passion into a profit” business coaching industry.

Have you had a bad experience with a coach but not expressed yourself publicly because of contractual language? Consumers’ honest reviews are protected by the Consumer Review Fairness Act, regardless of contractual language. Writers for law firm Morrison & Forrester state in this gratitude-inspiring article:

The FTC has cautioned companies that a consumer’s pure opinion is not likely to meet the “clearly false or misleading standard.”

I certainly cannot offer legal advice but I believe if you have engaged in a transaction with a U.S. business, you are probably protected.

Marquel Russell review – online coaching

Attending the “Matrixx” by PGI – a poor decision (it seems)

It thus far appears that attending the Matrixx, organized by the Proctor Gallagher Institute AKA PGI, was the worst decision of my adult life.

The following is intended to be fair. I understand that some will interpret my poor results in this context as merely an indicator of my personal weaknesses rather than finding fault with any opportunity or it’s marketing.

Hey, maybe you’re right.

***********************************************

I paid $18000 or $18500 to become a consultant for PGI and the experience was not what I dreamed it to be while in the more open, and gullible, state of mind I adopted at the Matrixx. It was there that I committed to becoming a consultant.

Running through what we have now given PGI: I think my wife and I paid a total of $27,500 to attend the Matrixx, and then there’s the aforementioned consultant fee ($18,00), and then there’s a $4000+ non-refundable (why?) deposit for something called the “1% club” that she lodged into her heart but did not attend. We could not afford the full cost of that seminar.

I have certainly learned a lot from this painful experience and have met some interesting people. PGI is certainly not afraid to ask for money. The company charges an annual fee after becoming a consultant, and then attending the training in Toronto is required (complimentary but one has to pay for travel and a place to stay), and then if in about 8 months you do not meet some requirements such as securing enough clients then there is a fee to extend the deadline, and then in the Facebook group I have seen invitations by the company to pay for additional training.

So the company continues to charge people who are out in the world advertising for the company. This would be fine if not for my impression that few consultants do well in this profession, despite the opportunity being sold as a “business in a box” with the implicit likelihood of success one would expect from an offering by “America’s greatest prosperity teacher”, Bob Proctor.

Watch “Going To Zero” on Netflix before jumping into any “business in a box” opportunity. Many have lost a lot of money to Herbalife and it seems only a few have earned a nice compensation. Reminiscent of my current impression of PGI, people are dazzled into jumping into the opportunity by an appeal to their sense of awe. “Wow, I am a spiritual being who can do it all!” the person may think, and Bob Proctor says the right people and opportunities will come to you when you need them. I’m in!

Then you go home, are encouraged to take responsibility for your life, including the expensive business decision, and maybe you pull others into the opportunity, or maybe you blame yourself for not selling something you do not find sufficiently valuable.

This has been a humbling experience and I continue to work through my thoughts. I hope to publish more thoughts as I converse with other PGI consultants. I do know there are other disappointed consultants, maybe quite a few. Based on our weekly emails, it does not appear very many individuals are activating clients. Maybe 30 consultants per week activate a client out of the ~550 consultants, and I’m thinking many consultants reappear in almost each email. Setting up an analysis to confirm those numbers would take some time.

I know at least a few consultants love what they do, such as those repeater activators. My wife is still selling the personal development program we can sell as PGI consultants, which PGI describes (in my view) as a panacea for all : “Thinking Into Results”. Activating a client means getting someone to purchase the program (~$3000-$10000), which is expected to include some kind of consultation with the consultant – often a group Internet video-call but some consultants do one-to-ones.

The state-of-mind my wife and I adopted during and shortly after The Matrixx caused me to trust, again as Bob Proctor said, that the right people would come to me when I needed them. So we, perhaps in a poor interpretation of Bob’s ideas, jumped into two expensive business coaching opportunities to assist with Facebook marketing (more on that one in the future).

It turns out all three of these programs had redundant elements, particularly with respect to Facebook marketing and a sales technique that focuses on making a client believe you are an authority who has the answer for whatever key problem they have.

I am working towards forgiving myself. Part of that process includes helping others avoid the pain we have experienced while allowing that some may see opportunity in these words. My wife thinks “Thinking Into Results” (TIR) is ethical to sell to the right person. Conjoined with her consultation, TIR has helped at least two clients overcome important hurdles.

My wife and I certainly have some salient personality differences. I am not ready to explore that topic yet.

Some people attend The Matrixx multiple times. I may correspond with a few of those individuals and comment on what I learn. My guess is that Matrixx attendees that are happy with the $15,000 cost ($12,500 as I recall for a second member in a pairing) are those able and willing to adopt a worldview in which they feel less guilt about taking money from people in exchange for a good, service, or opportunity that [EDIT: a personality like mine would predict] would likely lead to disappointment. The satisfied attendee, in my clumsy generalization, may not even think about probabilities. “Statistics is for losers,” the celebrity Steve Harvey once said in an inspiring speech that suggested he was a believer in the Law of Attraction.

The Law of Attraction: your thoughts attract the results you want in life by the sequence (1) thoughts, (2) feelings, (3) actions, (4) results. This is one of the supposedly universal laws presented in “Thinking Into Results”, the popular success tome “Think And Grow Rich”, and other similar works.

Sounds good, right? Visualize yourself with a large amount of money and you will take the actions to earn it. Fail to earn the money you wanted? Your fault. Your results reflect your thinking by this law. And it’s a universal law, so you can look across history and space and apply it. Holocaust victims and trafficked children, did they just have the wrong thoughts?

I hope I have this wrong.

Watch for a philosophy that communicates paramount individual responsibility and a devaluing of concern for others. This philosophy is strong in “personal development” circles including those of network marketing, “law of attraction” devotees, and “business coaching” as a category. Practitioners will say things like, “Focus on the use value of what you are offering”, which means focusing on the potential longoterm impact of a good, service, or opportunity even if in the short-to-middle term, most experience disappointment. The freeing feature of such a philosophy is that one can always say: Eventually, a person or company that pays you for something will derive more value than they paid. You do not have to see this play out, just trust. You also need not ask how people are doing. Just keep adding clients and trust the process.

“Spirit is always for expansion and fuller expression.”
– Bob Proctor

By that philosophy, perhaps I should thank PGI and those two business coaches for taking so much of my money and making me a more cautious consumer. I will say that PGI and the two coaching companies did offer something of motivational value, and if all had worked as my wife and I had hoped, maybe I would not be typing this post. However, given what I know now, I am sure that I would still be questioning whether my most ethical action would be writing my impression that most will not get a sufficient return on their investment into:
1. the Matrixx
2 becoming a PGI consultant
3. purchasing business coaching from anyone who dubiously calls him or herself “the most sought after digital marketing coach on the planet”. I know, I know…I made an embarrassing decision.

What I do not recall any of these three entities (PGI + two coaches) expressing is that I was investing in a high-risk opportunity given, as far as I can tell, most investors fail miserably. That “most sought after…coach” actually said in his advertising that most of his clients earned back more than their investment in the first month, which would have been $6000. I am extremely doubtful about that claim’s truth but I cannot conclusively falsify it. Perhaps authorities will.

Concealing and / or ignoring historic failure appears to be a persistent element in business. For example, most restaurants fail and yet people develop the faith to keep trying. People approach others about business opportunities all the time without communicating risk of failure unless pressed, and even then they may bias their remarks towards the optimistic.

We need to speak more often about ethics to avoid distrust fracturing our system.

Great confidence should not be assumed in these words because I am asking myself and others a lot of questions. I am appreciating more than ever the power of faith and indeed, if one maintains a belief in ideas such as:

“I am a creator like God so I can create the reality I want for myself” (paraphrasing Bob Proctor)

then a powerful motivation to take risks will be sustained.

I overhear my wife helping others to maintain their belief in their dreams and keep taking action. It sounds helpful and righteous.

On the other hand, this belief can also lead others to blame themselves and act destructively when things do not go well:

“Something must be wrong with me. I thought this would fix my problems.”

Exacerbating the problem, the communities that form around what I’ll call “coaching programs” have descriptions that speak to being positive and there’s the threat of being kicked out for being otherwise. This helps explain why I have rarely seen complaints or heavy-hearted concerns in those communities (Facebook closed groups in particular). In talking with others and sharing my shameful experiences, I have discovered others’ pain. Our shame has lightened through conversation.

Speaking to the healthiness of acknowledging negative emotions, a fellow PGI consultant today mentioned how helpful the book “The Subtle Art of Not Giving a F…” by Mark Manson was in healing her pain after having invested so much in the PGI consultant business venture and having told friends and family of her upcoming material success. She described Manson’s work as the “anti-self-help book for the ages”, a book that encourages one to acknowledge the full spectrum of their emotions and then with that more balanced sense of self, focusing one’s energy on their priorities. I loved her adoption of values less focused on material wealth and more on what work she would find holistically valuable at this time, teaching in schools.

There’s an opportunity here: A personal development program that prominently connects (1) material success to the (2) spiritual while communicating (3) ethical values and (4) social interconnectedness. When comedian Dave Chappelle said in a recent interview, “We are either fighting with each other, or against each other”, it did not sound like a false dichotomy.

***********************************************

Returning to The Matrixx: I do recall that there were a surprising number of people in attendance who were involved with network marketing. Common to network marketing, at least insofar as I have experienced that field, companies like the Proctor Gallagher Institute charismatically present material that stimulate the imagination of a life with greater wealth and therefore more happiness.

I say: Guard your dreams and your wallets.

I may have to delete this post because I am waiting to hear from a PGI leader whether my contract allows a consultant to post such thoughts. If I change my mind after further study and conversation and results, then I will offer my mea culpa.

I think all three of the programs into which I entered have contracts that restrict negative language although I read of a recent law that allows negative opinions to be expressed regardless of certain contractual language. I am grateful that a free country allows consumers to know about others’ experiences.

I hope this post contributes to a better assessment of PGI, “Thinking Into Results”, business coaching, any kind of marketing coaching, and investing thousands to become a consultant for the Proctor Gallagher Institute or attend their Matrixx seminar.

Attending the “Matrixx” by PGI – a poor decision (it seems)

Driving distance between many locations (#rstats)

I wanted to use R to calculate the driving distance between many locations and wanted to avoid the Google Maps API 2,500 query limit. My goal was to explore a relationship between a patient subgroup and SNAP-accepting food / beverage retailers, but for this discussion: Let’s explore the distances between SNAP retailers.

I looked to Bing Maps, but even there, I was concerned that I would hit its limit. BTW, I am not sure what that limit is but it apparently exceeds the 52,000 hits I used.

I decided to:

  1. Use the distHaversine function of the geosphere R package to get the Haversine distance (“as the crow flies”) between all retailers
  2. Use the Bing Maps API to get the driving distance between only the 5 retailers nearest each retailer
  3. Then select the nearest destination retailer among those 5 to each retailer

Unfortunately, the Bing Maps API R package I found, appears to no longer be maintained and generated a variety of errors including:
Error in function (type, msg, asError = TRUE) :
Failed to connect to dev.virtualearth.net port 80: Timed out

I instead used the RCurl and RJSONIO package and the following worked BUT today, I am seeing the aforementioned error. It worked this past weekend so I will return soon and try again.

## Using the coordinates from this StackOverflow question:

## https://stackoverflow.com/questions/42928677/calculating-driving-distance-for-70000-different-locations-by-using-only-longitu

from_mat_in <- '50.666, 13.795'

to_mat_in <- '47.50827271, 16.48046829'

distunit <- 'mi'
bingkey <- 'PLACE_YOUR_KEY_HERE_AS_ACQUIRED_FROM_https://www.bingmapsportal.com/'
starturl <- 'http://dev.virtualearth.net/REST/V1/Routes?wp.0=&#039;
fromtourl <- str_c(starturl, from_mat_in, '&wp.1=', to_mat_in, '&distanceUnit=', distunit, '&key=', bingkey)
u1 <- RCurl::getURL(fromtourl)
u2 <- RJSONIO::fromJSON(u1, simplify=FALSE)

travelDistance <- u2$resourceSets[[1]]$resources[[1]]$travelDistance

 

Notes

You can download SNAP data at https://www.fns.usda.gov/snap/retailerlocator (at the bottom, click the dropdown box to the right of “Download Information” to select the U.S. “nationwide” or a state)

Register for a Bing Maps developer account (more queries!) at https://www.bingmapsportal.com/

Driving distance between many locations (#rstats)

fbadstats R package

I finally released the first fully functional development version of my R package to assist with analyzing Facebook Ads Manager data exported as a CSV file: fbadstats [LINK].

Its only function so far, fbadGstats, has quite a few parameters that I will document better. I love Jenny Bryan’s googlesheets Github readme, (thanks @beeonaposy Caitlin Hudon for suggesting) which is quite readable and features:

  1. Vignette links
  2. Overview of functions
  3. “What the Hell do I do with this?”

Ari Lamstein, creator of the popular choroplethr.

mapping package, is also giving me thoughts about increasing awareness of its existence. Given that this is my first R package and I do not yet have a close network of other Facebook marketers, I aim to get plenty of feedback about the usefulness of the package and suggested code revisions (e.g., possibly replacing grid.arrange + tableGrob with ggplot2::facet, if that will print a figure / table combo like what I use in fbadGstats.

In short, fbadGstats aggregates data in CSV files exported from Facebook Ads Manager and displays the best and worst performing breakdown groups (e.g., age ranges) for either a specified variable (e.g., “Website Registrations Completed”) or, if present, one of Link Clicks or Results (Results refers to the selected objective for a Facebook advertisement so among exported ads, a variety of summarized results could be subsumed by Results.

The function is intended to be easy to use, particularly for those not familiar with R, while also providing plenty of parameters for more advanced use. Facebook advertising is vastly popular, helping to explain why at the time of this writing the stock (F) has done quite well over the last 6 months:

Latest 6 months (Nasdaq FB : real-time from Google Finance)

[Sidebar: I warned my mother against buying Facebook stock about 8 months ago. She forgave me, and I now admit to know little about stocks.]

Finally, developing this package forced me to develop plenty of new skills in R. When I saw a Hadley Wickham tweet about the innovation of quosures (non-standard evaluation) in the dplyr package, I thought they would be perfect for my package. While it may have been a product of a misunderstanding, I do use a quosure in the program.

The problem I faced was how to refer to a column in a dplyr group_by function that will vary in its name depending on the CSV provided. I wanted my program to work with a wide variety of data one might pass into it from Facebook Ads Manager.

After many hours of failed experiments and questioning whether I should be using quosures in the first place, I locked-in on this dplyr solution:

  1. Capture the names of the columns in the CSV file using colnames
  2. Use as.name on the fourth column, which the program (hopefully) ensures will always have the breakdown group variable (e.g., “Age Group 18-24”)
  3. Use the quo function on the unquoted as.name variable from 2
  4. Use the variable from 3, but unquoted, as the group_by variable

R code:


grpfunc <- function(newvar) {
grpvar <- quo(!!newvar)
return(grpvar)
}
## The 4th column in the dnams2 vector varies depending on the file used by the user
grpvar <- grpfunc(newvar = as.name(dnams[4]))

dmafbgrp <- dmafb %>% group_by(!!grpvar)

I do not know why this works. I plan to study the functions I used. At the moment, I am wondering if I could have just used as.name in the group_by. That’s something to try after lunch.

fbadstats R package

#rstats Careful with NA column names and dplyr filter function (tidyverse)

Hadley Wickham’s famous and beloved tidyverse does not like unusual column names like NA and does not yet return an error clearly indicating such, although Kirill Müller said on Github that this feature is coming.
## The assignment operator and other code are not printing when I use the code tag.

I worked for more than an hour to reproduce a problem I experienced during work without using confidential information. Curiously, this works even though a column is named NA.

R_Error.png

CATEGORY in the above includes a value of NA because the join on ‘x’ does not find a value of 1 in data frame b.

This could happen in practice if you had a list for categorizing entries and a new entry was not on the list.

I was able to replace the NAs with 0 using my dummy data, so I have apparently missed an important nuance present in my real data.

Nevertheless, removing the NA column made sense in my real world case:

R_solution

Notice the use of backquotes AKA backticks around NA. I believe working in the tidyverse has given me first exposure to using this character (top-left of the keyboard, above which is a tilde.

#rstats Careful with NA column names and dplyr filter function (tidyverse)

F# Data Visualization for a Neophyte – CDC Open Data

This post is part of the F# Advent Calendar in English 2016. Be sure to check out the other posts!

The following introductory post tells how I went from ignorance to reproducing in F# what I’ll call the “Hospital Discharges from Diabetes by Year” graph from this CDC (Centers for Disease Control) website.

Background

My wife, Ryan Pack, and I have committed to doing challenging stuff that scares us as part of a plan of personal development that will propel us towards helping others massively. We listen to Earl Nightingale, Bob Proctor, and Sean Croxton’s excellent podcasts “Quote of the Day” and “The Sessions”, read affirmations aloud in a mirror (not in the same room), and habitually behave such that positively transformative ideas are embedded in our subconscious.

This is working.

A Twitter opportunity arose from Sergey Tihon to take one of the remaining “F# Advent 2016” slots and I quickly volunteered. I then had a week to write a blog post about the programming language F# (“F Sharp”). Yet my anxiety rose everyday because I know little about F#, or .NET and blogging. I regularly use SAS and R as a data scientist.

I chose the CDC “Hospital Discharges from Diabetes by Year” data because many I follow in the health sphere associate deleterious health outcomes with compromised blood sugar regulation. Loosely, “open data” refers to electronically stored information that is publicly available and can be used freely. Please refer to the Data Foundation website for the eight dpen data tenets. The Data Foundation was referenced by Data.gov and so is presumed credible.

Tutorial and code

Visual Studio 2015 Community was installed because I had some exposure to the Visual Studio IDE in a prior position, all of the F# prerequisites were included, and the software was free.

Under File -> New -> Project -> Visual F#, I discovered a Microsoft-provided “Tutorial”. After clicking OK, I found a tutorial in the form of code and comments in the script Tutorial.fsx (“.fsx” is an F# script file extension). This allowed me to practice executing code in the immediate feedback-providing REPL (Read Evaluate Print Loop) with ALT-ENTER, a shared shortcut with R Studio.

However, I needed examples for downloading data from a website’s HTML. I experimented with a variety of websites’ example code in a new script I created and saved with the default name (“Script1.fsx”):
File -> New -> File -> General -> F# Script File

Errors were quickly experienced because websites were using ellipses references such as the following that did not work:

#r "../../../bin/FSharp.Data.dll"

Studying the code in Jamie Dixon’s “Mastering .NET Machine Learning” (2016), I realized the need to install the FSharp.Data package and reference the DLL’s location. I could then use the popular HtmlProvider method to read data from the CDC website.

Installing packages in Visual Studio is of a similar ease as installing packages in R (#rstats). Just open the Nuget Package Manager console in Visual Studio under

Tools -> Nuget Package Manager -> Package Manager Console

then type in the bottom window and hit ENTER to execute:

install-package Fsharp.Data

The following could finally be typed in an Fsharp script without error:

#r "../Tutorial1/packages/FSharp.Data.2.3.2/lib/net40/FSharp.Data.dll"
open FSharp.Data

Intellisense in Visual Studio then allowed me to see what methods and objects were detected as available based on the code under the cursor. R users will recognize this feature as one shared with R Studio.

I then spent hours failing to make progress, taking wrong turns that included “Namespaces”. I finally figured out that while the author of “Why F# is the best language for web scraping” was able to use HtmlProvider without GetSample(), I had to match Edgar Sánchez’s work.

I had been mislead by intellisense provided evidence of seeing the chart data via display of column headers from the data table such as “Year”. However, the inclusion of GetSample() eliminated the red squiggles that dogged me.

The comments included in the code make reasonable ending the play-by-play account. Some of these were copied from the “Why F# is the best language for web scraping” post with permission.

</pre>
<pre>// First use Nuget to acquire FSharp.Data.dll
// Tools -> Nuget Package Manager -> Package Manager Console
// then execute: install-package Fsharp.Data
#r "../Tutorial1/packages/FSharp.Data.2.3.2/lib/net40/FSharp.Data.dll"
open FSharp.Data

// Configure the type provider
type NugetStats =
HtmlProvider<"http://www.cdc.gov/diabetes/statistics/incidence/fig1.htm">

// load the live package stats, you get intellisense for this
// Discovered the need to use GetSample function to avoid error
// Experimenting with the aid of intellisense ultimately revealed that Tables.Table1
//  captured the nameless table from the CDC website. I knew the table lacked a name because
//  of a study of the website's source [In Firefox, Right Click then select View Source]
let rawStats = NugetStats.GetSample().Tables.Table1

// group by minor version and calculate download count
let stats =
rawStats.Rows
|> Seq.groupBy (fun r ->
r.Year)
|> Seq.map (fun (k, xs) ->
k, xs |> Seq.sumBy (fun x -> x.``Number (in Thousands)``))

// Load the FSharp.Charting library
#load "../Tutorial1/packages/FSharp.Charting.0.90.14/FSharp.Charting.fsx"
open FSharp.Charting

// Visualize the package stats
// Chart.Bar inverted the axes from what I wanted, placing years on the y-axis
Chart.Column(stats,Title="Annual Number (in Thousands) of New Cases of Diagnosed Diabetes Among Adults Aged 18-79 Years, United States, 1980-2014",XTitle="Year",YTitle="Number (in Thousands)")

diabetesdiagnosisI would like to learn how to offset the title and I also plan to present a related statistical analysis in the next month with more open data. However, having joined the more F# experienced Anthony Lloyd in the first day of blog writing for F# Advent 2016, I will count this a success:

“If you do not see yourself as a winner, then you cannot perform as a winner.” – Zig Ziglar

F# Data Visualization for a Neophyte – CDC Open Data