Tell me more ×
Cross Validated is a question and answer site for statisticians, data analysts, data miners and data visualization experts. It's 100% free, no registration required.

Hello after struggling with using R for the last couple of days I was hoping someone could help me with a statistical analysis I am completing for an environmental science honours project. Using R statistics is not something we have been taught and I am worried that I may have bitten of more then I can chew, however my whole project is based around the hierarchical partitioning method and the exhaustive search multiple regression analysis method.

The hier.part package was installed along with gtools.

I have converted my dataset to a .csv file with seven independent variables and one dependant variable with around 400 replicates (my intention is to do this analysis on eight datasets in total with different amounts of replicates and another dependant variable, but I am starting with this one). The dependant variable is GPP, the independent variables are, NDVI, Temperature, Precipitation, Solar Radiation, Nutrient Availability and Soil Available Water Capacity.

Secondly I imported the .csv file into R using the script

GPPANDDRIVER <- read.table("C:\\etc, header=T, sep=",")

This works fine and I can edit the table using

edit(GPPANDDRIVER)

After looking at the hier.part package documentation available here it seems like I need to define Y which in the script below is the dependent variable and define scan which is the independent variables (mentioned before).

hier.part(y, xcan, family = "gaussian", gof = "RMSPE", barplot = TRUE)

I was defining the dependant y vector as

y <- as.vector(GPPANDDRIVER["GPP"])

This also works fine and I have my y vector. However I am not sure how to load independent variables onto the xcan dataframe part of the script. I have tried typing in two scripts but they have not worked.

xcan <- as.vector(GPPANDDRIVER[-GPP])
## AND
xcan <- data.frame(GPPANDDRIVER[-GPP])

If anyone could help me find the right script for representing my independant variables as xcan that would be greatly appreciated. Also once defined if I entered in the hier.part script mentioned above would R then show me results of the analysis after processing? I will be moving onto to the regression analysis after this if anyone can shed some light on this first problem.

*information on hier.part arguments.*

**Arguments**

y a vector containing the dependent variables

xcan a dataframe containing the n independent variables

family family argument of glm

gof Goodness-of-fit measure. Currently "RMSPE", Root-mean-square ’prediction’

error, "logLik", Log-Likelihood or "Rsqu", R-squared

print.vars if FALSE, the function returns a vector of goodness-of-fit measures. If TRUE, a data frame is returned with first column listing variable combinations and the
second column listing goodness-of-fit measures.
share|improve this question

1 Answer

up vote 2 down vote accepted

The example in the package reference on pages 5-6 is pretty straightforward. If your original data frame is named GPPANDDRIVER, one could make new dataframes to pass to hier.part as follows;

GPP <- GPPANDDRIVER$GPP
IND_VARS <- subset(GPPANDDRIVER, select = -GPP)

The making of the IND_VARS can be done many ways, see the answers to this question on stackoverflow for a few examples of how it can be done. For instance, if you do not want all of the variables minus GPP in the IND_VARS data frame you can specify exactly what columns you do want.

Then to be clear in what we are doing, lets be explicit in assigning our arguments to specific objects in the call to hier.part.

hier.part(y = GPP, xcan = IND_VARS, family = "gaussian", gof = "RMSPE", barplot = TRUE)

If that isn't clear (or doesn't work) please provide an entirely reproducible example.

share|improve this answer
thank you very much! worked like a charm, I would rate it up but I cannot since its my first post. – Richard Belcher Apr 15 '12 at 16:20
1  
Good to know Richard. You should be able to at least accept my answer, welcome to the site. Although to note in the future, the content of this question would be better suited for Stackoverflow than here. See the FAQ of here for more explicit details of what is on or off topic. – Andy W Apr 15 '12 at 16:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.