Package 'TimeVarConcurrentModel'

Title: Concurrent Multivariate Models with Time-Varying Coefficients
Description: Provides a hypothesis test and variable selection algorithm for use in time-varying, concurrent regression models. The hypothesis test function is also accompanied by a plotting function which will show the estimated beta(s) and confidence band(s) from the hypothesis test. The hypothesis test function helps the user identify significant covariates within the scope of a time-varying concurrent model. The plots will show the amount of area that falls outside the confidence band(s) which is used for the test statistic within the hypothesis test.
Authors: Adriano Zambom [aut], Chance Vandergeugten [aut, cre]
Maintainer: Chance Vandergeugten <[email protected]>
License: GPL (>= 2)
Version: 1.0
Built: 2025-02-22 03:23:59 UTC
Source: https://github.com/cran/TimeVarConcurrentModel

Help Index


Fitting Beta Functions with Confidence Bands

Description

This function plots the beta function for each covariate along with its corresponding confidence bands. The area being summed for the calculation of the p-values are also highlighted within the plots so that the viewer can see the points in time where 0 is not within the confidence bands.

Usage

FitBandsPlot(x,y,t,n.basis,covnames)

Arguments

x

Array containing the data from the different covariates.

y

Matrix containing the data from the response variable

t

Variable used for time. For example, if the data is observed daily, then T will denote the total oberved number of days.

n.basis

Number of bases used for the bootstrapping process

covnames

Column vector containing the names of all the covariates in x array. These names should be in the same order as they appear in the x array.

Details

This function will plot the beta functions with their corresponding confidence bands. Each plot will be labeled accordingly based on the argument "covnames". The beta values for each covariate will be represented on the y-axis, while the variable of time will be represented on the x-axis. Each plot will shade the area that is being computed by the integrals in the the hypothesis test function. The intercept function will not include this shading.

Value

FitBandsPlot will output n+1 plots, where n is the number of covariates in the x array.

Author(s)

Adriano Zambom Chance Vandergeugten

References

fitbetaplot function originally from fda package. Written by J. O. Ramsay, , Hadley Wickham, Spencer Graves, Giles Hooker Edited by Chance Vandergeugten and renamed myfitbetaplot

Examples

library(fda)
library(Bolstad2)


country = c(rep("Brazil",365), rep("US",365), rep("Canada",365), rep("UK",365))
cases = c(1:365, 2*(1:365), 9*(1:365), 7*(1:365))
stringency  = c(seq(10,20,length.out = 365), 10 + sin(1:365), 10 + cos(1:365), abs(tan(1:365)))
stringency2  = c(seq(10,20,length.out = 365)+rnorm(365),
10 + sin(1:365)+abs(rnorm(365)), 10 + cos(1:365)+abs(rnorm(365)), abs(tan(1:365))+ abs(rnorm(365)))
data = data.frame(country, cases, stringency, stringency2)

n = dim(data)[2]
t = dim(data)[1]/dim(data)[2]

y = matrix(0,t,n)  
for (i in 1:n)
	y[,i] = data$cases[((i-1)*t + 1):(i*t)]


d = 2  ## set this manually for the covariates you want
n.basis = 10 ## sets number of bases to be used
covnames = c("Stringency","Stringency 2") ## names of covariates in order

x = array(0,c(t,n,d))  
for (i in 1:n)
{
	x[,i,1] = data$stringency[((i-1)*t + 1):(i*t)]
	x[,i,2] = data$stringency2[((i-1)*t + 1):(i*t)]
}

FitBandsPlot(x,y,t,n.basis,covnames)

Hypothesis Test for Concurrent Multivariate Regression Models With Time-Varying Coefficients

Description

This function provides a hypothesis test which is used for concurrent multivariate regression models that have time varying coefficients. The hypothesis test can be used to determine if covariates were significant for any time "t" within a given range of time.

Usage

HypothesisTestFunctionalData(x,y, B = 500, n.basis, show_iter=FALSE)

Arguments

x

Array containing the data from the different covariates

y

Matrix containing the data from the response variable

B

Number of bootstraps used to determine the distribution for the test statistic

n.basis

Number of bases used for the bootstrapping process

show_iter

Let's the user choose whether or not they would like to see the progress of the bootstrap

Details

With the given parameters, this function will conduct the specified number of bootstraps and then use the results to estimate the beta functions and their associated confidence bands. With this information, the function will then use an integral to calculate the area where the upper confidence bands fall below 0 and where the lower confidence bands rise above 0. The total area calculated will be compared to the expected area based on the bootstraps and a p-value will then be determined for each covariate.

Value

HypothesisTestFunctionalData will return a one-dimensional array with the p-values for each covariate

Author(s)

Adriano Zambom

Examples

library(fda)
library(Bolstad2)

country = c(rep("Brazil",365), rep("US",365), rep("Canada",365), rep("UK",365))
cases = c(1:365, 2*(1:365), 9*(1:365), 7*(1:365))
stringency  = c(seq(10,20,length.out = 365), 10 + sin(1:365), 10 + cos(1:365), abs(tan(1:365)))
stringency2  = c(seq(10,20,length.out = 365)+rnorm(365), 
10 + sin(1:365)+abs(rnorm(365)), 10 + cos(1:365)+abs(rnorm(365)), abs(tan(1:365))+ abs(rnorm(365)))
data = data.frame(country, cases, stringency, stringency2)

n = dim(data)[2]
t = dim(data)[1]/dim(data)[2]

y = matrix(0,t,n)  
for (i in 1:n)
	y[,i] = data$cases[((i-1)*t + 1):(i*t)]


d = 2  ## set this manually for the covariates you want
n.basis = 8 ## sets number of bases to be used

x = array(0,c(t,n,d))  
for (i in 1:n)
{
	x[,i,1] = data$stringency[((i-1)*t + 1):(i*t)]
	x[,i,2] = data$stringency2[((i-1)*t + 1):(i*t)]
}

p.values = HypothesisTestFunctionalData(x,y, B = 5,n.basis)
p.values