RCaller: Is Tree Height and Tree Width Correlated?

Liz Sanderson
Liz Sanderson
  • Updated

FME Version

Introduction

The RCaller allows users to run R scripts in FME. In this demo, we would like to determine whether or not there is a correlation between the height of trees and the diameter of trees.

 

Source Data

The CSV file, PublicTrees.csv, contains various attributes regarding trees in a city.

sourcedata.jpg

Source CSV data viewed with Data Inspector

 

Step-by-step Instructions

The download Correlation_Tree_Height_Diameter.fmwt is the complete workspace. If you would like to create the workspace yourself, please download PublicTrees.csv, and follow the steps below to create it.

1. Read Source Data

Read the PublicTrees.csv using a CSV Reader.

2. Add a RCaller

For the RScript, please specify the following:

Correlation=cor(CSV$Diameter, CSV$Height, method = "pearson")

fmeOutput<-data.frame(Correlation)

The cor() function will calculate the correlation between tree height and tree diameter. If desirable to work with the attribute created during the R Script, in this case Correlation, it is necessary to expose it in the Attributes to Expose parameter, or in an AttributeExposer transformer following the RCaller.

Please expose the attribute Correlation in the Attributes to Expose parameter.

rcallerparameters.jpg

RCaller parameters

 

3. Examine the result

Add a logger after the RCaller and run the workspace. In the log file, the Correlation is reported as 0.48002325189223527. This value indicates a moderate relationship between tree height and tree diameter. A value closer to 1 or -1 would indicate stronger correlation between height and diameter. Tree genus or species may be a factor to consider, and it is possible to filter based on either. This may indicate that some tree genus or species has a stronger correlation between tree height and tree diameter.

rcaller-logger-log.jpg

Logged RCaller output

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.