psData icon indicating copy to clipboard operation
psData copied to clipboard

S4 development branch

Open briatte opened this issue 11 years ago • 8 comments

Hi,

Here's a draft S4 class that creates a subclass of data.frame to implement functions for panel data and time series manipulation, or for any dyadic data.

Contents

  • CountryID by @christophergandrud (wraps around countrycode by @vincentarelbundock, with edits)
  • MoveFront from DataCombine by @christophergandrud
  • class-HomogList and subclass_homog_list from DataFrameConstr by @jrnold
  • class-psData (hacked from DataFrameConstr by @jrnold)
  • constrained_data_frame from DataFrameConstr by @jrnold
  • debt.rda (demo Reinhart and Rogoff data)
  • get_data and a bunch of get (download) functions for e.g. Polity 4 and QOG data
  • panel with functions by @zmjones
  • utils (with snippets by more authors)

I'm sure many more people have written useful code for working with panel data, including for visualization purposes—the package should probably also look in that direction, and the draft includes a Reinhart and Rogoff plot.

Output

# install
devtools::install_github("briatte/psData")
library(psData)

# example
data(debt)

The object is of class data.frame:

> head(debt)
    Country Year    growth     ratio
1 Australia 1946 -3.557951 190.41908
2 Australia 1947  2.459475 177.32137
3 Australia 1948  6.437534 148.92981
4 Australia 1949  6.611994 125.82870
5 Australia 1950  6.920201 109.80940
6 Australia 1951  4.272612  87.09448

Now add panel design variables to quickly create a psData panel object:

> as.panel(debt, "Country", "Year")
 Panel data frame [ 1171 rows x  4 columns, 20 Country x 64 Year ]

    Country Year    growth     ratio
1 Australia 1946 -3.557951 190.41908
2 Australia 1947  2.459475 177.32137
3 Australia 1948  6.437534 148.92981
4 Australia 1949  6.611994 125.82870
5 Australia 1950  6.920201 109.80940
6 Australia 1951  4.272612  87.09448

The object is now a data.frame to which the package can pass functions similar to the xt and ts commands in Stata. Country codes and basic date formats are automatically detected and usable for safe merges between multiple panel data.

briatte avatar Mar 05 '14 05:03 briatte

Excellent work. Sorry I've been a bit remiss lately because of other projects.

However, I just added the work you did into a new branch to the main rOpenGov/psData repo. It's called devPanel.

If it's ok with you, I think we should focus development around this branch.

christophergandrud avatar Mar 05 '14 08:03 christophergandrud

Your listed as collaborator on the repo so you should be able to push and pull freely. Let me know if you have any issues.

christophergandrud avatar Mar 05 '14 08:03 christophergandrud

One more thing. I added the email address listed on your website to the .travis.yml. So you'll get updates of whether or not each commit passes. Let me know if you don't want this and we could just take it out.

christophergandrud avatar Mar 05 '14 08:03 christophergandrud

@christophergandrud I'm good with all suggestions, will continue development at end of March (writing up before that).

briatte avatar Mar 06 '14 20:03 briatte

Thanks. I'll have to take a closer look at this when I have some time. I'm curious about the ropengov project.

Sorry that I didn't notice that you were using dataframeconstr earlier. You should look at my package checker. It is the continuation of the package; though I'd have to remind myself of what I changed and updated in the code.

Jeff

I'm good with all suggestions, will continue development at end of March (writing up before that).

Reply to this email directly or view it on GitHub.

jrnold avatar Mar 07 '14 19:03 jrnold

@jrnold don't worry about timing, I forked your repo just a few days ago :)

It's likely that my hack of your class can be improved in many ways. Please feel free to point inadequacies, there are many, as I am new to S4 classes overall.

briatte avatar Mar 07 '14 19:03 briatte

Thanks. Again sorry for my delay. What I was saying is that you should look at my package https://github.com/jrnold/r-checker. It is an updated version of dataframeconstr; I should have probably removed this package. I'd need to look back over my code to remind myself what changed, but I must have improved some things.

Jeff

@jrnold https://github.com/jrnold don't worry about timing, I forked your repo just a few days ago :)

It's likely that my hack of your class can be improved in many ways. Please feel free to point inadequacies, there are many, as I am new to S4 classes overall.

Reply to this email directly or view it on GitHubhttps://github.com/rOpenGov/psData/issues/7#issuecomment-37060114 .

jrnold avatar Mar 16 '14 03:03 jrnold

@jrnold thanks for the details — I'll update psData to that version of your S4 class next week.

briatte avatar Mar 16 '14 19:03 briatte