The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

jkuusik (6) [Avatar] Offline
#1
Hi!
Can You please provide some advanced examples for readers about cast() function?

I am missing function for calculating trend of given x (slope of regression line for time series, which will be aggregated).

For example:
y = c(1.3, 1.6, 2.3, 4.5) - this vector will be aggregated - response variable
x = c(1,2,3,4) - just lenght(y) - explanatory variable

I am missing formula for regression slope (beta_1) with arbitrary length of y

some working examples from me:

M_mean<-cast(melt_data, ID_1+ID_2~variable, mean)
M_median<-cast(melt_data, ID_1+ID_2~variable, median)
M_std<-cast(melt_data, ID_1+ID_2~variable, sd)
M_range<-cast(melt_data, ID_1+ID_2~variable, function(x) max(x) - min(x))
M_skew<-cast(melt_data, ID_1+ID_2~variable, function(x) sum((x-mean(x))**3/sqrt(var(x))**3)/length(x))
M_kurtosis<-cast(melt_data, ID_1+ID_2~variable, function(x) sum((x-mean(x))**4/var(x)**2)/length(x) - 3)


Regards,
Jüri Kuusik
e-mail: kuusik@neti.ee