Skip to content

Commit

Permalink
removed old backtransform function
Browse files Browse the repository at this point in the history
  • Loading branch information
GregFa committed Apr 27, 2024
1 parent 222eaef commit 73290f1
Showing 1 changed file with 0 additions and 119 deletions.
119 changes: 0 additions & 119 deletions src/utilities/std_helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,125 +36,6 @@ function normalize!(A::AbstractArray{Float64,2}, hasIntercept::Bool)
return means, norms
end


"""
backtransform!(B::AbstractArray{Float64,2},
meansX::AbstractArray{Float64,2},
meansZ::AbstractArray{Float64,2},
normsX::AbstractArray{Float64,2},
normsZ::AbstractArray{Float64,2},
Y::AbstractArray{Float64,2},
Xold::AbstractArray{Float64,2},
Zold::AbstractArray{Float64,2})
Back-transform coefficient estimates B in place if X and Z were standardized
prior to the estimation-- when both X and Z include intercept columns.
# Arguments
- B = 2d array of coefficient estimates B
- meansX = 2d array of column means of X, obtained prior to standardizing X
- meansZ = 2d array of column means of Z, obtained prior to standardizing Z
- normsX = 2d array of column norms of X, obtained prior to standardizing X
- normsZ = 2d array of column norms of Z, obtained prior to standardizing Z
- Y = 2d array of response matrix Y
- Xold = 2d array row covariates X prior to standardization
- Zold = 2d array column covariates Z prior to standardization
# Value
None; back-transforms B in place
"""
function backtransform!(B::AbstractArray{Float64,2},
meansX::AbstractArray{Float64,2},
meansZ::AbstractArray{Float64,2},
normsX::AbstractArray{Float64,2},
normsZ::AbstractArray{Float64,2},
Y::AbstractArray{Float64,2},
Xold::AbstractArray{Float64,2},
Zold::AbstractArray{Float64,2})

# Back transform the X intercepts (row main effects)
prodX = (meansX[:,2:end]./normsX[:,2:end])*B[2:end, 2:end]
B[1,2:end] = (B[1,2:end]-vec(prodX))./vec(normsZ[:,2:end])/normsX[1,1]

# Back transform the Z intercepts (column main effects)
prodZ = B[2:end, 2:end]*transpose(meansZ[:,2:end]./normsZ[:,2:end])
B[2:end,1] = (B[2:end,1]-prodZ)./transpose(normsX[:,2:end])/normsZ[1,1]

# Back transform the interactions
B[2:end, 2:end] = B[2:end, 2:end]./transpose(normsX[:,2:end])./
normsZ[:,2:end]

# Re-estimate intercept
B[1,1] = 0
B[1,1] = mean(Y-Xold*B*transpose(Zold))
end


"""
backtransform!(B::AbstractArray{Float64,2},
addXIntercept::Bool, addZIntercept::Bool,
meansX::AbstractArray{Float64,2},
meansZ::AbstractArray{Float64,2},
normsX::AbstractArray{Float64,2},
normsZ::AbstractArray{Float64,2})
Back-transform coefficient estimates B in place if X and Z were standardized
prior to the estimation-- when not including intercept columns for either X
or Z.
# Arguments
- B = 2d array of coefficient estimates B
- addXIntercept = boolean flag indicating whether or not to X has an
intercept column
- addZIntercept = boolean flag indicating whether or not to Z has an
intercept column
- meansX = 2d array of column means of X, obtained prior to standardizing X
- meansZ = 2d array of column means of Z, obtained prior to standardizing Z
- normsX = 2d array of column norms of X, obtained prior to standardizing X
- normsZ = 2d array of column norms of Z, obtained prior to standardizing Z
# Value
None; back-transforms B in place
"""
function backtransform!(B::AbstractArray{Float64,2},
addXIntercept::Bool, addZIntercept::Bool,
meansX::AbstractArray{Float64,2},
meansZ::AbstractArray{Float64,2},
normsX::AbstractArray{Float64,2},
normsZ::AbstractArray{Float64,2})

# Back transform the X intercepts (row main effects), if necessary
if addXIntercept == true
prodX = (meansX[:,2:end]./normsX[:,2:end])*B[2:end, 2:end]
B[1,2:end] = (B[1,2:end]-vec(prodX))./vec(normsZ[:,2:end])/normsX[1,1]
end

# Back transform the Z intercepts (column main effects), if necessary
if addZIntercept == true
prodZ = B[2:end, 2:end]*transpose(meansZ[:,2:end]./normsZ[:,2:end])
B[2:end,1] = (B[2:end,1]-prodZ)./transpose(normsX[:,2:end])/
normsZ[1,1]
end

# Back transform the interactions, if necessary
if (addXIntercept == true) || (addZIntercept == true)
B[2:end, 2:end] = B[2:end, 2:end]./transpose(normsX[:,2:end])./
normsZ[:,2:end]
end

# Back transform the interactions if not including any main effects
if (addXIntercept == false) && (addZIntercept == false)
B = B./transpose(normsX)./normsZ
end
end


"""
backtransform!(B::AbstractArray{Float64,4},
addXIntercept::Bool, addZIntercept::Bool,
Expand Down

0 comments on commit 73290f1

Please sign in to comment.