Question: Fix The Fortran Code Below: program resampking implicit none integer, parameter :: ns = 1 0 0 0 0 real, dimension ( 4 ) ::

Fix The Fortran Code Below:
program resampking
implicit none
integer, parameter :: ns =10000
real, dimension(4) :: WC1=[0.8,1.2,1.6,5.2]
real, dimension(5) :: WCex =[3.1,4.9,6.8,8.2,15.9]
integer :: i, nge_random, nge_bootstrap
real :: median_group1, median_group2, test_statistic, p_value_random, p_value_bootstrap
real :: combined(9), temp_median1, temp_median2, pseudo_stat
real, dimension(ns) :: pseudo
real :: actualstat, pvalue, corr
integer :: nge, nsize
real, dimension(:), allocatable :: x, y, xactual
real, dimension(3) :: alpha =[0.01,0.05,0.10]
character(len=3) :: ans
combined =[WC1, WCex]! Correct concatenation with //
call calculate_statistics(WC1, WCex, median_group1, median_group2, test_statistic)
nge_random =0
nge_bootstrap =0
do i =1, ns
call random_permutation(combined)
call calculate_statistics(combined(1:4), combined(5:9), temp_median1, temp_median2, pseudo_stat)
if (abs(pseudo_stat)>= abs(test_statistic)) then
nge_random = nge_random +1
end if
temp_median1= bootstrap_resample(WC1)
temp_median2= bootstrap_resample(WCex)
pseudo_stat = temp_median2- temp_median1
if (abs(pseudo_stat)>= abs(test_statistic)) then
nge_bootstrap = nge_bootstrap +1
end if
end do
p_value_random = real(nge_random +1)/ real(ns +1)
p_value_bootstrap = real(nge_bootstrap +1)/ real(ns +1)
nsize = size(WC1)
call AllocateArrays(nsize)
x = xactual
actualstat =-corr(nsize, WC1, WC1)! Pass WC1 as both x and y
nge =0
do i =1, ns
call simpleshuffle(nsize, WC1)
pseudo(i)=-corr(nsize, WC1, WC1)! Pass WC1 as both x and y
if (pseudo(i)>= actualstat) nge = nge +1
end do
pvalue = real(nge +1)/ real(ns +1)
write (*,21) nge, pvalue
21 format (' Number of resampled test statistics >-r =', I10,/, &
' p-value =', F10.4)
write (*,22) 'Level of Significance', 'Null hypothesis rejected? (Yes or No)'
22 format (A30,4X, A30)
do i =1,3
if (pvalue < alpha(i)) then
ans = 'Yes'
else
ans ='No'
end if
write (*,23) alpha(i), ans
23 format (F4.2,4X, A3)
end do
! Deallocate arrays
call DeallocateArrays
contains
subroutine calculate_statistics(group1, group2, median1, median2, test_stat)
real, dimension(:), intent(in) :: group1, group2
real, intent(out) :: median1, median2, test_stat
median1= median(group1)
median2= median(group2)
test_stat = median2- median1
end subroutine calculate_statistics
subroutine random_permutation(arr)
real, dimension(:), intent(inout) :: arr
integer :: i, j, n
real :: temp
n = size(arr)
do i =1, n
call random_number(temp)
j = i + int(temp *(n - i +1))
temp = arr(i)
arr(i)= arr(j)
arr(j)= temp
end do
end subroutine random_permutation
subroutine simpleshuffle(m, y)
implicit none
integer, intent(in) :: m
real, intent(inout) :: y(m)
real :: temp, r
integer :: j, k
do j =1, m -1
call random_number(r)
k = j + int(r *(m - j +1))
temp = y(k)
y(k)= y(j)
y(j)= temp
end do
end subroutine simpleshuffle
real function bootstrap_resample(data)
real, dimension(:), intent(in) :: data
real, dimension(size(data)) :: sample
integer :: i
real :: temp
do i =1, size(data)
call random_number(temp)
sample(i)= data(int(temp * size(data))+1)
end do
bootstrap_resample = median(sample)
end function bootstrap_resample
real function median(arr)
real, dimension(:), intent(in) :: arr
real, dimension(size(arr)) :: sorted_arr
integer :: n
sorted_arr = arr
call quicksort(sorted_arr, size(arr))! Assuming quicksort is a sorting subroutine or function
n = size(arr)
if (mod(n,2)==0) then
median =0.5*(sorted_arr(n /2)+ sorted_arr(n /2+1))
else
median = sorted_arr((n +1)/2)
end if
end function median
subroutine AllocateArrays(n)
integer, intent(in) :: n
allocate(x(n), y(n), xactual(n))
end subroutine AllocateArrays
subroutine DeallocateArrays
deallocate(x, y, xactual)
end subroutine DeallocateArrays
end program resampking

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!